Skip to content

Commit

Permalink
Electrician 12: Level 3 (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdrzazga authored Dec 24, 2024
1 parent f0a02ca commit 859ed2c
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 104 deletions.
Binary file modified 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 modified 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.
143 changes: 59 additions & 84 deletions other/electrician/files/creators.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,39 @@ class Creator {
static HIGH_FLOOR_LEVEL = 104;
static LOW_FLOOR_LEVEL = 438;

static createEnemies(ratsData, batsData, physics){
let enemies = [];
const rats = ratsData.map(data => Creator.createEnemy(Rat, data, physics));
const bats = batsData.map(data => Creator.createEnemy(Bat, data, physics));

enemies.push(...rats, ...bats);
return enemies;
}

static createEnemy(EnemyClass, data, physics, positionAdjustment = 0) {
const enemy = new EnemyClass(data.id);
enemy.active = data.active;
const y = EnemyClass === Rat ? data.y : 555 + 7 * data.id + positionAdjustment;
enemy.init(physics, y);

Object.assign(enemy, {
minX: data.minX || enemy.minX,
maxX: data.maxX || enemy.maxX,
angularSpeed: data.speed || enemy.angularSpeed,
currentAngle: data.currentAngle || enemy.currentAngle,
wireId: EnemyClass === Rat ? data.wireId : undefined
});

if (EnemyClass === Bat) {
enemy.centerX = Constants.SCREEN_WIDTH / 2 + 50 - 39 * data.id;
}

if (data.velocity) enemy.sprite.velocity = data.velocity;

return enemy;
}

//Level 1
static create3storeBuilding(physics) {
let building = new Building('House');
building.init(physics); // Initializes ladder and power lines
Expand Down Expand Up @@ -51,21 +84,13 @@ class Creator {
return building;
}

static createEnemies(ratsData, batsData, physics){
let enemies = [];
const rats = ratsData.map(data => Creator.createEnemy(Rat, data, physics));
const bats = batsData.map(data => Creator.createEnemy(Bat, data, physics));

enemies.push(...rats, ...bats);
return enemies;
}

//Level 2
static createOfficeGymGarage(physics){
let building = new Building('Office Gym Garage');
building.init(physics); // Initializes ladder and power lines
let building = new Building('Office Gym Garage');
building.init(physics); // Initializes ladder and power lines

const officeBuilder = new FloorBuilder();
building.floors.push(officeBuilder.withName('office').withBottomConnector(5).withBottomConnector(9)
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());

Expand All @@ -75,57 +100,62 @@ class Creator {

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

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

const connectionPointsCounts = [4, 8, 3];
const connectionPointsCounts = [4, 8, 4];
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();

//const MID_FLOOR_LEVEL = 328 - Floor.HEIGHT / 2;
const ratsData = [
{ id: 1, active: true, y: Building.GROUND_FLOOR_LEVEL },
{ id: 2, active: true, y: Creator.LOW_FLOOR_LEVEL, velocity: { x: 0.7 }, wireId: 2},
//{ id: 4, active: true, y: MID_FLOOR_LEVEL, velocity: { x: 0.85}, wireId: 1},
{ id: 3, active: true, y: Creator.HIGH_FLOOR_LEVEL, wireId: 0}
{ id: 1, active: true, y: Building.GROUND_FLOOR_LEVEL }
];

const batsData = [
{ id: 0, active: true, speed: -0.007 }
{ id: 0, active: true, speed: 0.007 },
{ id: 1, active: true, speed: 0.006 },
{ id: 3, active: true, speed: 0.005 },
{ id: 4, active: true, speed: 0.004 },
{ id: 5, active: true, speed: 0.008 },
{ id: 6, active: true, speed: 0.0053 },
{ id: 7, active: true, speed: 0.009 },
{ id: 8, active: true, speed: 0.0042 },
];

building.enemies = Creator.createEnemies(ratsData, batsData, physics);

return building;
}

//Level 3
static createBuilding(physics){
let building = new Building('Home 2');
building.init(physics); // Initializes ladder and power lines

const atticBuilder = new FloorBuilder();
building.floors.push(atticBuilder.withName('attic').withCeilingConnector(12).build());
building.floors.push(atticBuilder.withName('floor2').withCeilingConnector(7).withCeilingConnector(12)
.withCeilingConnector(23).withBottomConnector(23).withBottomConnector(24).withBottomConnector(25).build());

const gymBuilder = new FloorBuilder();
building.floors.push(gymBuilder.withName('gym').withCeilingConnector(7).withCeilingConnector(23)
.build());
building.floors.push(gymBuilder.withName('power-room').withCeilingConnector(7).withCeilingConnector(12)
.withCeilingConnector(19).withCeilingConnector(20).withCeilingConnector(21).withCeilingConnector(26)
.withCeilingConnector(27).withCeilingConnector(28).build());

const garageBuilder = new FloorBuilder();
building.floors.push(garageBuilder.withName('garage').withCeilingConnector(5).withCeilingConnector(20)
.withCeilingConnector(22)
.build());
building.floors.push(garageBuilder.withName('basement').withCeilingConnector(7).withCeilingConnector(12)
.withCeilingConnector(23).build());

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

const connectionPointsCounts = [4, 8, 3];
const connectionPointsCounts = [3, 11, 3];
building.wires = building.floors.map((floor, index) => {
const aboveFloor = building.floors[index] || null;
const belowFloor = building.floors[index - 1] || null;
Expand All @@ -150,59 +180,4 @@ class Creator {

return building;
}

static createEnemy(EnemyClass, data, physics, positionAdjustment = 0) {
const enemy = new EnemyClass(data.id);
enemy.active = data.active;
const y = EnemyClass === Rat ? data.y : 555 + 7 * data.id + positionAdjustment;
enemy.init(physics, y);

Object.assign(enemy, {
minX: data.minX || enemy.minX,
maxX: data.maxX || enemy.maxX,
angularSpeed: data.speed || enemy.angularSpeed,
currentAngle: data.currentAngle || enemy.currentAngle,
wireId: EnemyClass === Rat ? data.wireId : undefined
});

if (EnemyClass === Bat) {
enemy.centerX = Constants.SCREEN_WIDTH / 2 + 50 - 39 * data.id;
}

if (data.velocity) enemy.sprite.velocity = data.velocity;

return enemy;
}

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;
}
}
Binary file modified 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 modified 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.
40 changes: 20 additions & 20 deletions other/electrician/files/levels.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,28 @@ class LevelScene extends Phaser.Scene {
}
}

class Level1Scene extends LevelScene{
class Level1Scene extends LevelScene {

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

loadFloorImages(){
this.load.image('floor0', 'files/attic.png');
this.load.image('floor1', 'files/livingRoom.png');
this.load.image('floor2', 'files/kitchen.png');
this.load.image('floor0', 'files/attic2.png');
this.load.image('floor1', 'files/home1.png');
this.load.image('floor2', 'files/basement.png');
}

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

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

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

this.cursors = this.input.keyboard.createCursorKeys();
}
}

Expand Down Expand Up @@ -269,27 +280,16 @@ class Level2Scene extends LevelScene{
}
}

class Level3Scene extends LevelScene {
class Level3Scene extends LevelScene{

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

loadFloorImages(){
this.load.image('floor0', 'files/attic2.png');
this.load.image('floor1', 'files/home1.png');
this.load.image('floor2', 'files/basement.png');
}

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

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

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

this.cursors = this.input.keyboard.createCursorKeys();
this.load.image('floor0', 'files/attic.png');
this.load.image('floor1', 'files/livingRoom.png');
this.load.image('floor2', 'files/kitchen.png');
}
}

0 comments on commit 859ed2c

Please sign in to comment.