Advertisement
myarkqub

isometric

Apr 23rd, 2024 (edited)
536
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.  
  4. <head>
  5.     <meta charset="UTF-8">
  6.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.     <title>Document</title>
  8.     <script src="/phaserjs"></script>
  9. </head>
  10.  
  11. <body>
  12.     <script>
  13.  
  14.         let testbox
  15.         let map = [
  16.             [0, 0, 0, 0, 0, 0, 1, 1, 1, 1],
  17.             [0, 0, 0, 0, 0, 0, 1, 1, 1, 1],
  18.             [0, 0, 1, 1, 1, 1, 1, 1, 1, 1],
  19.             [0, 0, 1, 1, 1, 1, 1, 1, 1, 1],
  20.             [0, 1, 1, 1, 1, 1, 1, 1, 1, 1],
  21.             [0, 0, 1, 1, 1, 1, 1, 1, 1, 1],
  22.             [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
  23.             [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
  24.             [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
  25.             [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
  26.         ]
  27.  
  28.         let map_tile
  29.  
  30.         class Scene1 extends Phaser.Scene {
  31.             preload() {
  32.  
  33.             }
  34.  
  35.             create() {
  36.                 let offset = { x: 0, y: 0 }
  37.                 let tile_size = 64
  38.                 let tile_height = 8
  39.                 for (let y = 0; y < map.length; y++) {
  40.                     for (let x = 0; x < map[y].length; x++) {
  41.                         if (map[y][x] > 0) {
  42.                             map_tile = this.add.isobox(x * (tile_size / 2) - (y * (tile_size / 2)) + offset.x, y * (tile_size / 4) + (x * (tile_size / 4)) + offset.y, tile_size, tile_height).setInteractive()
  43.                             map_tile.on('pointerdown', function (pointer) {
  44.                                 this.setFillStyle(0xff0000);
  45.                                 console.log(x, y)
  46.                             });
  47.  
  48.                             map_tile.on('pointerover', function (pointer) {
  49.  
  50.                                 this.setFillStyle(0x00ff00, 0xffff00, 0xff0000);
  51.  
  52.                             });
  53.  
  54.                             map_tile.on('pointerout', function (pointer) {
  55.  
  56.                                 this.setFillStyle(0xeeeeee, 0x999999, 0xcccccc);
  57.  
  58.                             });
  59.  
  60.                             map_tile.on('pointerup', function (pointer) {
  61.  
  62.                                 this.setFillStyle(0xeeeeee, 0x999999, 0xcccccc);
  63.  
  64.                             });
  65.                         }
  66.                     }
  67.                 }
  68.  
  69.                 const cursors = this.input.keyboard.createCursorKeys();
  70.                 this.cameras.main.centerOn(0, 150);
  71.                 const controlConfig = {
  72.                     camera: this.cameras.main,
  73.                     left: cursors.left,
  74.                     right: cursors.right,
  75.                     up: cursors.up,
  76.                     down: cursors.down,
  77.                     zoomIn: this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.Q),
  78.                     zoomOut: this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.E),
  79.                     acceleration: 0.02,
  80.                     drag: 0.0005,
  81.                     maxSpeed: 0.7
  82.                 };
  83.  
  84.                 this.controls = new Phaser.Cameras.Controls.SmoothedKeyControl(controlConfig);
  85.             }
  86.  
  87.             update(time, delta) {
  88.                 this.controls.update(delta);
  89.             }
  90.         }
  91.  
  92.         const config = {
  93.             type: Phaser.AUTO,
  94.             width: 800,
  95.             height: 600,
  96.             scene: Scene1
  97.         };
  98.  
  99.         const game = new Phaser.Game(config);
  100.     </script>
  101. </body>
  102.  
  103. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement