fix: some bugs in rmg

This commit is contained in:
Renge 2022-04-20 19:57:26 -04:00
parent 86e5a5b7b4
commit da1e053033
2 changed files with 15 additions and 4 deletions

View File

@ -24,7 +24,15 @@
"width": 3,
"alt_tile": [11, 11]
}
],
"sprites": [
{
"type": "player",
"x": 5,
"y": 10
}
]
},
"exit": {
"width": 30,

View File

@ -94,10 +94,12 @@ export default class RandomMapGenerator {
getMap(): TiledTilemapData {
let room = this.copyRoom(this.template.entrance, 0, 0);
this.rooms.push(room);
let facing = this.getEntranceFacing(this.template.entrance.entrances[0], this.template.entrance.width);
let position = new Vec2(this.template.entrance.entrances[0].x, this.template.entrance.entrances[0].y);
// this.removeEntrance(room, this.template.entrance.entrances[0], facing);
this.rooms.push(room);
this.putNextRoom(position, this.getOppositeFacing(facing));
@ -134,7 +136,7 @@ export default class RandomMapGenerator {
default:
break;
}
if (this.roomPlaced >= this.minRoom && facing == this.exitFacing) {
if (this.roomPlaced >= this.minRoom && facing == this.exitFacing && !this.hasExit) {
this.putExitRoom(position);
return true;
}
@ -155,9 +157,10 @@ export default class RandomMapGenerator {
return false;
}
let room = this.copyRoom(nextRoom, nextPosition.x, nextPosition.y);
this.removeEntrance(room, thisEntrance, facing);
this.rooms.push(room);
this.roomPlaced += 1;
if (this.hasExit && this.gen.range() <= 0.5) {
if (this.hasExit && this.gen.random() <= 0.3) {
return false;
}
for (let entrance of nextRoom.entrances) {