Skip to content

Commit

Permalink
fix2
Browse files Browse the repository at this point in the history
  • Loading branch information
kdrzazga committed Dec 7, 2024
1 parent c3f104f commit 7f12520
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
26 changes: 19 additions & 7 deletions other/electrician/files/classdef.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,19 @@ class Building {
f.calculateFloorLevel();
});

for (let w = 0; w < floorCount - 1; w++){
const wire = new Wire(physics, this.floors[w], this.floors[w+1]);
for (let w = 0; w <= floorCount; w++) {
const aboveFloor = this.floors[w] || null;
const belowFloor = this.floors[w - 1] || null;
const wire = new Wire(physics, belowFloor, aboveFloor);
this.wires.push(wire);
}

if (this.wires.length > 0) {
const lastFloorY = this.floors[floorCount - 1].floorLevel;
const secondTolastFloorY = this.floors[floorCount - 2].floorLevel;
this.wires[this.wires.length - 1].y = lastFloorY + Math.abs(lastFloorY - secondTolastFloorY)/2;
}

this.leftPowerLine = new PowerLine();
this.leftPowerLine.init(physics, 'left');
this.rightPowerLine = new PowerLine();
Expand All @@ -99,7 +107,8 @@ class Building {
}

drawWire(player){
this.wires[0].place(player.x, player.y);
const currentFloor = this.getCurrentFloor(player);
this.wires[0].place(currentFloor, player);
}
}

Expand All @@ -116,8 +125,9 @@ class Wire {//connects PowerLine to Floor
constructor(physics, floor1, floor2){
this.physics = physics;
const y2 = floor2 == null ? 0 : floor2.sprite.y;
this.x = floor1.sprite.x;
this.y = (floor1.sprite.y + y2) / 2;
const y1 = floor1 == null ? 0 : floor1.sprite.y;
this.x = floor1 ? floor1.sprite.x : 0;
this.y = (y1 + y2) / 2;

this.fields = [];
this.sprites = [];
Expand All @@ -126,8 +136,10 @@ class Wire {//connects PowerLine to Floor
}
}

place(spriteX, spriteY){
this.physics.add.sprite(spriteX, this.y, 'wire-section');
place(floor, sprite){
const extraInfoDiv = document.getElementById('extra-info');
extraInfoDiv.innerText = floor.id + " " + floor.floorLevel ;
this.physics.add.sprite(sprite.x, floor.floorLevel, 'wire-section');
}
}

Expand Down
8 changes: 6 additions & 2 deletions other/electrician/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<html>
<html lang="en">
<head>
<style>
body {
Expand Down Expand Up @@ -35,12 +35,16 @@
src: url('files/atari.ttf');
}
</style>
<title>Electrician</title>
</head>
<body>

<div id="header" class="big header">ELECTRICIAN</div>
<div class="small header" style="font-size: 0.5em'">Controls: arrow keys, fire: space/shift</div>
<div id="infoFrame" class="panel">Floor:<div id="floor-number"></div></div>
<div id="infoFrame" class="panel">Floor:
<div id="floor-number"></div>
<div id="extra-info"></div>
</div>
<div id = "board"></div>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/phaser/3.55.2/phaser.min.js"></script>
Expand Down

0 comments on commit 7f12520

Please sign in to comment.