Advertisement
jargon

Roe2Js :: "canvas3dRenderCommands.js"

Jul 1st, 2024 (edited)
737
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     // const frontCanvas = document.getElementById('frontCanvas');
  2.     // const frontContext = frontCanvas.getContext('2d');
  3.  
  4.     const TILE_WIDTH = 64;
  5.     const TILE_HEIGHT = 32;
  6.     const BOX_HEIGHT = 64;
  7.            
  8.     const textures = {
  9.         top: `/GFX/wall____.png`,
  10.         side: `/GFX/wall____.png`,
  11.         front: `/GFX/wall____.png`
  12.     };
  13.  
  14.     const textureImages = {};
  15.  
  16.     function loadTextures(callback) {
  17.         let loadedCount = 0;
  18.         const textureKeys = Object.keys(textures);
  19.         textureKeys.forEach(key => {
  20.             const img = new Image();
  21.             img.src = `${host}/test dictionary/GFX/${textures[key]}`;
  22.             img.onload = () => {
  23.                 textureImages[key] = img;
  24.                 loadedCount++;
  25.                 if (loadedCount === textureKeys.length) {
  26.                     callback();
  27.                 }
  28.             };
  29.         });
  30.     }
  31.  
  32.     function drawIsometricBox(x, y, z) {
  33.        
  34.         const screenX = (x - y) * TILE_WIDTH / 2;
  35.         const screenY = (x + y) * TILE_HEIGHT / 2 - z * BOX_HEIGHT;
  36.  
  37.         // Draw top
  38.         frontContext.drawImage(textureImages.top, screenX, screenY - BOX_HEIGHT);
  39.  
  40.         // Draw side
  41.         frontContext.drawImage(textureImages.side, screenX, screenY - TILE_HEIGHT / 2);
  42.  
  43.         // Draw front
  44.         frontContext.drawImage(textureImages.front, screenX - TILE_WIDTH / 2, screenY);
  45.     }
  46.  
  47.     function drawScene() {
  48.         frontContext.clearRect(0, 0, frontCanvas.width, frontCanvas.height);
  49.        
  50.         // Draw a grid of boxes for demonstration
  51.         for (let x = 0; x < 5; x++) {
  52.             for (let y = 0; y < 5; y++) {
  53.                 drawIsometricBox(x, y, 1);
  54.             }
  55.         }
  56.     }
  57.  
  58.     loadTextures(drawScene);
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement