Skip to content

Commit

Permalink
Advancing to next level
Browse files Browse the repository at this point in the history
  • Loading branch information
kdrzazga committed Dec 23, 2024
1 parent 34384f9 commit 4110738
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
1 change: 0 additions & 1 deletion other/electrician/files/creators.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ class Creator {
return new Wire(index, physics, belowFloor, aboveFloor, connectionPointsCounts[index]);
});


building.includeWiresInInfoFrame();

return building;
Expand Down
15 changes: 12 additions & 3 deletions other/electrician/files/electrician.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
const levelsJson = {'lvl1' : Level1Scene, 'lvl2': Level2Scene}

let level = sessionStorage.getItem("level");
let levelObject = Level1Scene;
if (level == null) levelObject = Level1Scene;
else {
levelObject = levelsJson[level];
}

const config = {
type: Phaser.AUTO,
width: Constants.SCREEN_WIDTH,
Expand All @@ -9,13 +18,13 @@ const config = {
debug: false
}
},
scene: Level2Scene
scene: [levelObject]
};

const game = new Phaser.Game(config);
let game = new Phaser.Game(config);
/*
Hacking:
game.scene.scenes[0].building.enemies[7].active = false;
game.scene.scenes[0].building.enemies[8].active = false;
game.scene.scenes[0].player.y=0;
*/
13 changes: 13 additions & 0 deletions other/electrician/files/levels.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class LevelScene extends Phaser.Scene {
super({ key: levelName });
this.playerCanJump = true;
this.playerFalling = false;
this.nextLevel = '';
}

preload() {
Expand Down Expand Up @@ -50,6 +51,7 @@ class LevelScene extends Phaser.Scene {
this.handleEnemyMovement();
this.checkCollisions();
this.conditionalFallDown();
this.checkVictory();
}

jump(direction) {
Expand Down Expand Up @@ -217,12 +219,22 @@ class LevelScene extends Phaser.Scene {
let prettyCurrentFloorText = realCurrentFloor < 0 ? ' ' : prettyCurrentFloor;
floorInfo.innerText = `${prettyCurrentFloorText} (${realCurrentFloor})`;
}

checkVictory(){
const allConnected = this.building.wires.every(wire => wire.isConnected());
if (allConnected){
console.log(`All floors are connected. Advancing to the next level ${this.nextLevel}`);
sessionStorage.setItem('level', this.nextLevel);
location.reload();
}
}
}

class Level1Scene extends LevelScene{

constructor() {
super('Level1');
this.nextLevel = 'lvl2';
}

loadFloorImages(){
Expand All @@ -236,6 +248,7 @@ class Level2Scene extends LevelScene{

constructor() {
super('Level2');
this.nextLevel = 'lvl1'; //TODO: looped game
}

loadFloorImages(){
Expand Down

0 comments on commit 4110738

Please sign in to comment.