Skip to content

Commit

Permalink
updating space
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardTMiles committed Feb 14, 2024
1 parent 6ae2ae7 commit 546f7cb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
10 changes: 0 additions & 10 deletions src/Game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,16 +250,6 @@ canvas.addEventListener('click', function (event) {

if (existingTurret) {

if (existingTurret.level > existingTurret.upgrades.length) {

console.log('Turret is already at max level', existingTurret);

return;

}

console.log('Turret is already at max level', existingTurret);

existingTurret.upgrade();

}
Expand Down
24 changes: 24 additions & 0 deletions src/Turret.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Turret class
import Alert from "./Alert";
import tGridPosition from "./tGridPosition";
import Entity, {iEntityConstructorProps} from "./Entity";

Expand Down Expand Up @@ -104,7 +105,30 @@ export class Turret extends Entity implements iTurret {
}

upgrade() {


if (this.level > this.upgrades.length) {

console.log('Turret is already at max level', this);

return;

}

const upgrade = this.upgrades[this.level - 1];

if (this.gameState.energy < this.upgrades[this.level - 1].cost) {

// add new alert
this.gameState.alerts.push(new Alert({
message: "Not enough energy to upgrade turret",
seconds: 4
}))

return;

}

this.range = upgrade.range;
this.damage = upgrade.damage;
this.cooldown = upgrade.cooldown;
Expand Down

0 comments on commit 546f7cb

Please sign in to comment.