This commit is contained in:
OfficialCHenry 2022-04-13 16:28:10 -04:00
commit e433e41406
2 changed files with 21 additions and 7 deletions

12
.gitignore vendored
View File

@ -4,6 +4,18 @@ node_modules
# Exclude the compiled project # Exclude the compiled project
dist/* dist/*
# Firebase cache
.firebase/
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
firebase-debug.log*
firebase-debug.*.log*
# Include the demo_assets folder # Include the demo_assets folder
!dist/demo_assets/ !dist/demo_assets/

View File

@ -110,7 +110,7 @@ export default class RandomMapGenerator {
} }
getPlayer(): Vec2 { getPlayer(): Vec2 {
return this.player; return new Vec2(this.player.x - this.minX, this.player.y - this.minY);
} }
getEnemies(): Array<Enemy> { getEnemies(): Array<Enemy> {
@ -250,6 +250,10 @@ export default class RandomMapGenerator {
for (let room of this.rooms) { for (let room of this.rooms) {
let roomWidth = room.bottomRight.x - room.topLeft.x + 1; let roomWidth = room.bottomRight.x - room.topLeft.x + 1;
let roomHeight = room.bottomRight.y - room.topLeft.y + 1; let roomHeight = room.bottomRight.y - room.topLeft.y + 1;
room.topLeft.x -= this.minX;
room.topLeft.y -= this.minY;
room.bottomRight.x -= this.minX;
room.bottomRight.y -= this.minY;
for (let i = 0; i < roomHeight; i++) for (let i = 0; i < roomHeight; i++)
for (let j = 0; j < roomWidth; j++) { for (let j = 0; j < roomWidth; j++) {
this.map.layers[0].data[(room.topLeft.y + i) * width + room.topLeft.x + j] = room.bottomLayer[i * roomWidth + j]; this.map.layers[0].data[(room.topLeft.y + i) * width + room.topLeft.x + j] = room.bottomLayer[i * roomWidth + j];
@ -257,13 +261,11 @@ export default class RandomMapGenerator {
} }
if (room.enemies) if (room.enemies)
for (let enemy of this.enemies) { for (let enemy of this.enemies) {
enemy.position.x -= this.minX; enemy.position.x += room.topLeft.x;
enemy.position.y -= this.minY; enemy.position.y += room.topLeft.y;
this.enemies.push(enemy); this.enemies.push(enemy);
} }
} }
this.player.x -= this.minX;
this.player.y -= this.minY;
} }
private isValidRoom(topLeft: Vec2, bottomRight: Vec2): boolean { private isValidRoom(topLeft: Vec2, bottomRight: Vec2): boolean {
@ -353,8 +355,8 @@ export default class RandomMapGenerator {
if (old.sprites) { if (old.sprites) {
for (let sprite of old.sprites) { for (let sprite of old.sprites) {
if (sprite.type === 'player') { if (sprite.type === 'player') {
this.player.x = sprite.x; this.player.x = sprite.x + posX;
this.player.y = sprite.y; this.player.y = sprite.y + posY;
} }
else { else {
if (this.gen.random() <= sprite.possibility) { if (this.gen.random() <= sprite.possibility) {