Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export default class DungeonScene extends Phaser.Scene {
- create() {
- // ... dungeon and map generation code omitted
- this.dungeon.rooms.forEach(room => {
- // These room properties are all in grid units (not pixels units)
- const { x, y, width, height, left, right, top, bottom } = room;
- // ... room tile mapping code omitted
- // Dungeons have rooms that are connected with doors. Each door has an x & y relative to the
- // room's location. Each direction has a different door to tile mapping.
- var doors = room.getDoorLocations(); // → Returns an array objects like this {x, y}
- for (var i = 0; i < doors.length; i++) {
- if (doors[i].y === 0) {
- this.groundLayer.putTilesAt(TILES.DOOR.TOP, x + doors[i].x - 1, y + doors[i].y);
- } else if (doors[i].y === room.height - 1) {
- this.groundLayer.putTilesAt(TILES.DOOR.BOTTOM, x + doors[i].x - 1, y + doors[i].y);
- } else if (doors[i].x === 0) {
- this.groundLayer.putTilesAt(TILES.DOOR.LEFT, x + doors[i].x, y + doors[i].y - 1);
- } else if (doors[i].x === room.width - 1) {
- this.groundLayer.putTilesAt(TILES.DOOR.RIGHT, x + doors[i].x, y + doors[i].y - 1);
- }
- }
- });
- }
- }
Add Comment
Please, Sign In to add comment