Skip to content

Commit

Permalink
3/3/22 1:57 PM
Browse files Browse the repository at this point in the history
 - DungeonGenerator is usable*!
 - updated example / testing code
 - updated TODO list
  • Loading branch information
eboatwright committed Mar 3, 2022
1 parent 06385eb commit 45538d9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
22 changes: 20 additions & 2 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/extras.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -212,15 +210,17 @@ class DungeonGenerator extends WorldGenerator {
this.floorTiles = floorTiles;
this.wallTile = wallTile;
this.tunnelTile = tunnelTile;
this.posOffset = posOffset;
this.sizeOffset = sizeOffset;
this.tries = 0;
this.rooms = [];
}

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)),
Expand Down
10 changes: 5 additions & 5 deletions src/jscii/extras/worldGeneration.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// DISCLAIMER! This is not finished! *DONT* use in your own projects!

class WorldGenerator {
constructor(width, height) {
this.width = width;
Expand All @@ -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;
Expand All @@ -21,15 +19,17 @@ class DungeonGenerator extends WorldGenerator {
this.floorTiles = floorTiles;
this.wallTile = wallTile;
this.tunnelTile = tunnelTile;
this.posOffset = posOffset;
this.sizeOffset = sizeOffset;
this.tries = 0;
this.rooms = [];
}

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)),
Expand Down
4 changes: 3 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -107,6 +107,8 @@ init = function() {

update = function() {
level.update();
if(keyJustDown("l"))
level.lightmap.tiles = init2DArray(WIDTH_TILE, HEIGHT_TILE, 0);
}

render = function() {
Expand Down

0 comments on commit 45538d9

Please sign in to comment.