Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export default class DungeonScene extends Phaser.Scene {
- create() {
- // ... previous dungeon and map generation code omitted for brevity
- // Set all tiles in the ground layer with blank tiles (purple-black tile)
- this.groundLayer.fill(20);
- // Use the array of rooms generated to place tiles in the map
- // Note: using an arrow function here so that "this" still refers to our scene
- 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;
- // Fill the room (minus the walls) with mostly clean floor tiles (90% of the time), but
- // occasionally place a dirty tile (10% of the time).
- this.groundLayer.weightedRandomize(x + 1, y + 1, width - 2, height - 2, [
- { index: 6, weight: 9 }, // 9/10 times, use index 6
- { index: [7, 8, 26], weight: 1 } // 1/10 times, randomly pick 7, 8 or 26
- ]);
- // Place the room corners tiles
- this.groundLayer.putTileAt(3, left, top);
- this.groundLayer.putTileAt(4, right, top);
- this.groundLayer.putTileAt(23, right, bottom);
- this.groundLayer.putTileAt(22, left, bottom);
- // Place the non-corner wall tiles using fill with x, y, width, height parameters
- this.groundLayer.fill(39, left + 1, top, width - 2, 1); // Top
- this.groundLayer.fill(1, left + 1, bottom, width - 2, 1); // Bottom
- this.groundLayer.fill(21, left, top + 1, 1, height - 2); // Left
- this.groundLayer.fill(19, right, top + 1, 1, height - 2); // Right
- });
- }
- }
Add Comment
Please, Sign In to add comment