From 45538d94368372480cfb5f57f713d1e7b48c6ab1 Mon Sep 17 00:00:00 2001 From: eboatwright Date: Thu, 3 Mar 2022 13:57:01 -0600 Subject: [PATCH] 3/3/22 1:57 PM - DungeonGenerator is usable*! - updated example / testing code - updated TODO list --- TODO | 22 ++++++++++++++++++++-- src/extras.js | 10 +++++----- src/jscii/extras/worldGeneration.js | 10 +++++----- src/main.js | 4 +++- 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/TODO b/TODO index 7bafd93..5a57bc7 100644 --- a/TODO +++ b/TODO @@ -17,12 +17,30 @@ that I might not want to add. Bugs list: - - ui covers up some of the dungeon + - Main todo list: - - + - documentation / comments + - constants.js + - font.js + - input.js + - main.js + - utils.js + - vector2.js Extras todo list: + - documentation / comments + - action.js + - animations.js + - camera.js + - level.js + - map.js + - nameGeneration.js + - PECS.js + - rect.js + - ui.js + - worldGeneration.js + - update action system - kick - open diff --git a/src/extras.js b/src/extras.js index 8430e7b..bf29038 100644 --- a/src/extras.js +++ b/src/extras.js @@ -189,8 +189,6 @@ class Text extends Entity { } // extras/worldGeneration.js -// DISCLAIMER! This is not finished! *DONT* use in your own projects! - class WorldGenerator { constructor(width, height) { this.width = width; @@ -203,7 +201,7 @@ class WorldGenerator { } class DungeonGenerator extends WorldGenerator { - constructor(tilemap, minRoomSize = vector2(8, 8), maxRoomSize = vector2(16, 16), maxTries = 50, floorTiles = [1, 2], wallTile = 3, tunnelTile = 4) { + constructor(tilemap, minRoomSize = vector2(8, 8), maxRoomSize = vector2(16, 16), maxTries = 50, floorTiles = [1, 2], wallTile = 3, tunnelTile = 4, posOffset = vOne(), sizeOffset = vZero()) { super(tilemap.tiles[0].length, tilemap.tiles.length); this.tilemap = tilemap; this.minRoomSize = minRoomSize; @@ -212,6 +210,8 @@ class DungeonGenerator extends WorldGenerator { this.floorTiles = floorTiles; this.wallTile = wallTile; this.tunnelTile = tunnelTile; + this.posOffset = posOffset; + this.sizeOffset = sizeOffset; this.tries = 0; this.rooms = []; } @@ -219,8 +219,8 @@ class DungeonGenerator extends WorldGenerator { createRoom() { const rect = new Rect( vector2( - Math.floor(randomRange(1, this.width - this.maxRoomSize.x)), - Math.floor(randomRange(1, this.height - this.maxRoomSize.y)) + Math.floor(randomRange(this.posOffset.x, this.width - this.maxRoomSize.x - this.sizeOffset.x)), + Math.floor(randomRange(this.posOffset.y, this.height - this.maxRoomSize.y - this.sizeOffset.y)) ), vector2( Math.floor(randomRange(this.minRoomSize.x, this.maxRoomSize.x)), diff --git a/src/jscii/extras/worldGeneration.js b/src/jscii/extras/worldGeneration.js index 8c9269a..8315d42 100644 --- a/src/jscii/extras/worldGeneration.js +++ b/src/jscii/extras/worldGeneration.js @@ -1,5 +1,3 @@ -// DISCLAIMER! This is not finished! *DONT* use in your own projects! - class WorldGenerator { constructor(width, height) { this.width = width; @@ -12,7 +10,7 @@ class WorldGenerator { } class DungeonGenerator extends WorldGenerator { - constructor(tilemap, minRoomSize = vector2(8, 8), maxRoomSize = vector2(16, 16), maxTries = 50, floorTiles = [1, 2], wallTile = 3, tunnelTile = 4) { + constructor(tilemap, minRoomSize = vector2(8, 8), maxRoomSize = vector2(16, 16), maxTries = 50, floorTiles = [1, 2], wallTile = 3, tunnelTile = 4, posOffset = vOne(), sizeOffset = vZero()) { super(tilemap.tiles[0].length, tilemap.tiles.length); this.tilemap = tilemap; this.minRoomSize = minRoomSize; @@ -21,6 +19,8 @@ class DungeonGenerator extends WorldGenerator { this.floorTiles = floorTiles; this.wallTile = wallTile; this.tunnelTile = tunnelTile; + this.posOffset = posOffset; + this.sizeOffset = sizeOffset; this.tries = 0; this.rooms = []; } @@ -28,8 +28,8 @@ class DungeonGenerator extends WorldGenerator { createRoom() { const rect = new Rect( vector2( - Math.floor(randomRange(1, this.width - this.maxRoomSize.x)), - Math.floor(randomRange(1, this.height - this.maxRoomSize.y)) + Math.floor(randomRange(this.posOffset.x, this.width - this.maxRoomSize.x - this.sizeOffset.x)), + Math.floor(randomRange(this.posOffset.y, this.height - this.maxRoomSize.y - this.sizeOffset.y)) ), vector2( Math.floor(randomRange(this.minRoomSize.x, this.maxRoomSize.x)), diff --git a/src/main.js b/src/main.js index 35a66ce..7d84b2f 100644 --- a/src/main.js +++ b/src/main.js @@ -85,7 +85,7 @@ init = function() { init2DArray(WIDTH_TILE, HEIGHT_TILE) ); - dungeonGenerator = new DungeonGenerator(tilemap, vector2(6, 6), vector2(15, 15), 50, [1, 2], 3, 4); + dungeonGenerator = new DungeonGenerator(tilemap, vector2(6, 6), vector2(15, 15), 50, [1, 2], 3, 4, vector2(1, 4), vector2(0, 0)); const playerPosition = dungeonGenerator.generate(); @@ -107,6 +107,8 @@ init = function() { update = function() { level.update(); + if(keyJustDown("l")) + level.lightmap.tiles = init2DArray(WIDTH_TILE, HEIGHT_TILE, 0); } render = function() {