feat: implemented checkpoint

This commit is contained in:
Renge 2022-04-22 15:56:12 -04:00
parent c38273f1a3
commit 832e42affa
3 changed files with 25 additions and 1 deletions

View File

@ -51,7 +51,8 @@
"y": 10,
"possibility": 1
}
]
],
"checkPoint": [5, 19, 5, 5]
},
"exit": {
"width": 30,

View File

@ -173,6 +173,8 @@ export default class GameLevel extends Scene {
this.startpos = this.rmg.getPlayer().scale(32);
//call super after extending story with scene
@ -191,6 +193,9 @@ export default class GameLevel extends Scene {
this.subscribeToEvents();
this.addUI();
const checkPoint = this.rmg.getCheckPoint();
this.addLevelEnd(new Vec2(checkPoint[0], checkPoint[1]), new Vec2(checkPoint[2], checkPoint[3]));
// Create an enemies array
// Send the player and enemies to the battle manager
this.battleManager.setPlayers([<PlayerController>this.player._ai]);
@ -900,6 +905,13 @@ export default class GameLevel extends Scene {
}
protected addLevelEnd(startingTile: Vec2, size: Vec2): void {
this.levelEndArea = <Rect>this.add.graphic(GraphicType.RECT, "primary", {position: startingTile.scale(32), size: size.scale(32)});
this.levelEndArea.addPhysics(undefined, undefined, false, true);
// this.levelEndArea.setTrigger("player", somelevelendevent, null);
this.levelEndArea.color = new Color(0, 0, 0, 0);
}
/**
* damages the player if they collide with an enemy

View File

@ -25,6 +25,7 @@ export default class RandomMapGenerator {
private exitFacing: Facing;
private enemies: Array<Enemy>;
private player: Vec2;
private checkPoint: [number, number, number, number];
constructor(JSONFilePath: string, seed: any) {
let xhr = new XMLHttpRequest();
@ -44,6 +45,7 @@ export default class RandomMapGenerator {
this.rooms = new Array();
this.enemies = new Array();
this.player = new Vec2();
this.checkPoint = [0,0,0,0];
let gen = require('random-seed');
this.gen = new gen(seed);
this.hasExit = false;
@ -115,6 +117,10 @@ export default class RandomMapGenerator {
return new Vec2(this.player.x - this.minX, this.player.y - this.minY);
}
getCheckPoint(): [number, number, number, number] {
return [this.checkPoint[0] - this.minX, this.checkPoint[1] - this.minY, this.checkPoint[2], this.checkPoint[3]];
}
getEnemies(): Array<Enemy> {
return this.enemies;
}
@ -372,6 +378,11 @@ export default class RandomMapGenerator {
}
}
}
if (old.checkPoint) {
this.checkPoint = [...old.checkPoint];
this.checkPoint[0] += posX;
this.checkPoint[1] += posY;
}
if (posX < this.minX)
this.minX = posX;
if (posY < this.minY)