Guest User

Untitled

a guest
Jul 22nd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. export default class DungeonScene extends Phaser.Scene {
  2. create() {
  3. // ... previous dungeon and map generation code omitted for brevity
  4.  
  5. // Set all tiles in the ground layer with blank tiles (purple-black tile)
  6. this.groundLayer.fill(20);
  7.  
  8. // Use the array of rooms generated to place tiles in the map
  9. // Note: using an arrow function here so that "this" still refers to our scene
  10. this.dungeon.rooms.forEach(room => {
  11. // These room properties are all in grid units (not pixels units)
  12. const { x, y, width, height, left, right, top, bottom } = room;
  13.  
  14. // Fill the room (minus the walls) with mostly clean floor tiles (90% of the time), but
  15. // occasionally place a dirty tile (10% of the time).
  16. this.groundLayer.weightedRandomize(x + 1, y + 1, width - 2, height - 2, [
  17. { index: 6, weight: 9 }, // 9/10 times, use index 6
  18. { index: [7, 8, 26], weight: 1 } // 1/10 times, randomly pick 7, 8 or 26
  19. ]);
  20.  
  21. // Place the room corners tiles
  22. this.groundLayer.putTileAt(3, left, top);
  23. this.groundLayer.putTileAt(4, right, top);
  24. this.groundLayer.putTileAt(23, right, bottom);
  25. this.groundLayer.putTileAt(22, left, bottom);
  26.  
  27. // Place the non-corner wall tiles using fill with x, y, width, height parameters
  28. this.groundLayer.fill(39, left + 1, top, width - 2, 1); // Top
  29. this.groundLayer.fill(1, left + 1, bottom, width - 2, 1); // Bottom
  30. this.groundLayer.fill(21, left, top + 1, 1, height - 2); // Left
  31. this.groundLayer.fill(19, right, top + 1, 1, height - 2); // Right
  32. });
  33. }
  34. }
Add Comment
Please, Sign In to add comment