Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export default class DungeonScene extends Phaser.Scene {
- // ... preload omitted for brevity
- create() {
- // Generate a random world with a few extra options:
- // - Rooms should only have odd dimensions so that they have a center tile.
- // - Doors should be at least 2 tiles away from corners, to leave enough room for the tiles
- // that we're going to put on either side of the door opening.
- this.dungeon = new Dungeon({
- width: 50,
- height: 50,
- doorPadding: 2,
- rooms: {
- width: { min: 7, max: 15, onlyOdd: true },
- height: { min: 7, max: 15, onlyOdd: true }
- }
- });
- // Creating a blank tilemap with dimensions matching the dungeon
- const map = this.make.tilemap({
- tileWidth: 48,
- tileHeight: 48,
- width: this.dungeon.width,
- height: this.dungeon.height
- });
- const tileset = map.addTilesetImage("tiles", null, 48, 48, 1, 2); // 1px margin, 2px spacing
- this.groundLayer = map.createBlankDynamicLayer("Ground", tileset); // Wall & floor
- this.stuffLayer = map.createBlankDynamicLayer("Stuff", tileset); // Chest, stairs, etc.
- }
- }
Add Comment
Please, Sign In to add comment