Guest User

Untitled

a guest
Jul 22nd, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. export default class DungeonScene extends Phaser.Scene {
  2. create() {
  3. // ... dungeon and map generation code omitted
  4.  
  5. this.dungeon.rooms.forEach(room => {
  6. // These room properties are all in grid units (not pixels units)
  7. const { x, y, width, height, left, right, top, bottom } = room;
  8.  
  9. // ... room tile mapping code omitted
  10.  
  11. // Dungeons have rooms that are connected with doors. Each door has an x & y relative to the
  12. // room's location. Each direction has a different door to tile mapping.
  13. var doors = room.getDoorLocations(); // → Returns an array objects like this {x, y}
  14. for (var i = 0; i < doors.length; i++) {
  15. if (doors[i].y === 0) {
  16. this.groundLayer.putTilesAt(TILES.DOOR.TOP, x + doors[i].x - 1, y + doors[i].y);
  17. } else if (doors[i].y === room.height - 1) {
  18. this.groundLayer.putTilesAt(TILES.DOOR.BOTTOM, x + doors[i].x - 1, y + doors[i].y);
  19. } else if (doors[i].x === 0) {
  20. this.groundLayer.putTilesAt(TILES.DOOR.LEFT, x + doors[i].x, y + doors[i].y - 1);
  21. } else if (doors[i].x === room.width - 1) {
  22. this.groundLayer.putTilesAt(TILES.DOOR.RIGHT, x + doors[i].x, y + doors[i].y - 1);
  23. }
  24. }
  25. });
  26. }
  27. }
Add Comment
Please, Sign In to add comment