Skip to content

Commit

Permalink
Electrician 10 (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdrzazga authored Dec 23, 2024
1 parent 2b89a8a commit 7dd702f
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 4 deletions.
Binary file added other/electrician/files/attic2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added other/electrician/files/basement.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions other/electrician/files/creators.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,36 @@ class Creator {

return building;
}

static createOfficeGymGarage(physics){
let building = new Building();
building.init(physics); // Initializes ladder and power lines

const officeBuilder = new FloorBuilder();
building.floors.push(officeBuilder.withName('office').withBottomConnector(5).withBottomConnector(9)
.withBottomConnector(13).withBottomConnector(16).withBottomConnector(19).withBottomConnector(26)
.withCeilingConnector(5).withCeilingConnector(12).withCeilingConnector(20).withCeilingConnector(26).build());

const gymBuilder = new FloorBuilder();
building.floors.push(gymBuilder.withName('gym').withCeilingConnector(7).withCeilingConnector(23)
.build());

const garageBuilder = new FloorBuilder();
building.floors.push(garageBuilder.withName('garage').withCeilingConnector(5).withCeilingConnector(22)
.build());

building.floors.forEach(floor => floor.init(physics));
building.floors.forEach(floor => floor.calculateFloorLevel());

const connectionPointsCounts = [4, 8, 2];
building.wires = building.floors.map((floor, index) => {
const aboveFloor = building.floors[index] || null;
const belowFloor = building.floors[index - 1] || null;
return new Wire(index, physics, belowFloor, aboveFloor, connectionPointsCounts[index]);
});

building.includeWiresInInfoFrame();

return building;
}
}
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: Level1Scene
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;
*/
Binary file added other/electrician/files/garage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added other/electrician/files/gym.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added other/electrician/files/home1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 @@ -231,3 +243,28 @@ class Level1Scene extends LevelScene{
this.load.image('floor2', 'files/kitchen.png');
}
}

class Level2Scene extends LevelScene{

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

loadFloorImages(){
this.load.image('floor0', 'files/office.png');
this.load.image('floor1', 'files/gym.png');
this.load.image('floor2', 'files/garage.png');
}

create() {
this.physics.world.setBounds(0, 0, 800, 600);

this.building = Creator.createOfficeGymGarage(this.physics);

this.player = this.physics.add.sprite(100, 400, 'sprite');
this.player.setCollideWorldBounds(true);

this.cursors = this.input.keyboard.createCursorKeys();
}
}
Binary file added other/electrician/files/office.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion other/electrician/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/phaser/3.55.2/phaser.min.js"></script>
<script src="files/classdef.js"></script>
<script src="files/creators.js"></script>
<script src="files/level1.js"></script>
<script src="files/levels.js"></script>
<script src="files/electrician.js"></script>
</html>

0 comments on commit 7dd702f

Please sign in to comment.