Skip to content

Commit c888654

Browse files
UI for enemies immune to storm
1 parent cc5b867 commit c888654

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

public/js/enemy.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -763,27 +763,35 @@ class Enemy {
763763
}
764764

765765
drawHexagon() {
766+
const immuneToStorm = this.inCamp || this.returningToCamp || (this.patrolling && !this.hasPlayerBeenDetected);
767+
766768
this.strengthenedSquare.clear();
767769
if (this.patrolling) {
768770
this.strengthenedSquare.fillStyle(0x228b6c, 1);
769771
} else {
770-
// forest green
771772
this.strengthenedSquare.fillStyle(0x000000, 1);
772773
}
773-
774-
// Draw a hexagon
774+
775+
if (immuneToStorm) {
776+
this.strengthenedSquare.lineStyle(3, 0xffffff, 1);
777+
}
778+
775779
const radius = 15;
776780
this.strengthenedSquare.beginPath();
777781
for (let i = 0; i < 6; i++) {
778-
// calculate vertex positions
779-
const x = radius * Math.cos(2 * Math.PI * i / 6 - Math.PI / 2);
780-
const y = radius * Math.sin(2 * Math.PI * i / 6 - Math.PI / 2);
782+
const x = radius * Math.cos(2 * Math.PI * i / 6);
783+
const y = radius * Math.sin(2 * Math.PI * i / 6);
781784
if (i === 0) this.strengthenedSquare.moveTo(x, y);
782785
else this.strengthenedSquare.lineTo(x, y);
783786
}
784787
this.strengthenedSquare.closePath();
785788
this.strengthenedSquare.fill();
789+
790+
if (immuneToStorm) {
791+
this.strengthenedSquare.strokePath();
792+
}
786793
}
794+
787795

788796
updateHealthBar() {
789797
if (this.isDead) return;
@@ -996,9 +1004,17 @@ class Enemy {
9961004

9971005
update(time, delta) {
9981006
if (this.isDead) return;
1007+
9991008
this.updateHealthBar();
10001009
this.updatePatrol(time, delta);
1010+
1011+
const wasImmuneToStorm = this.immuneToStorm;
1012+
this.immuneToStorm = this.inCamp || (this.patrolling && !this.hasPlayerBeenDetected) || this.returningToCamp;
10011013

1014+
if (this.immuneToStorm !== wasImmuneToStorm) {
1015+
this.drawHexagon();
1016+
}
1017+
10021018
if (this.originalCamp) {
10031019
const distanceFromCamp = Phaser.Math.Distance.Between(
10041020
this.sprite.x, this.sprite.y,

0 commit comments

Comments
 (0)