Advertisement
jargon

Roe2Js :: "canvas3dRenderCommands.js"

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