diff --git a/frontend/src/js/critter.ts b/frontend/src/js/critter.ts index 539baea9829d497b65fd5746ffbd032917d7aaf0..b38067428d4bbf3e40ef1f761a28e4f60ff06c61 100644 --- a/frontend/src/js/critter.ts +++ b/frontend/src/js/critter.ts @@ -82,6 +82,11 @@ class Critter extends Phaser.Physics.Arcade.Sprite { this.play({ key: this.species + "_run", repeat: -1 }); this.body.setVelocity(3 * this.baseVelocity, 0); } + + hitFlash() { + this.setTintFill(0xcc0000); + this.scene.time.delayedCall(100, () => this.clearTint()); + } } export default Critter; diff --git a/frontend/src/js/spear.ts b/frontend/src/js/spear.ts index ce6ad72d0bb80493fbf6d9e743f0820194350277..ac86673a66acd46f8be513ebcf0d0b671f5323e3 100644 --- a/frontend/src/js/spear.ts +++ b/frontend/src/js/spear.ts @@ -1,5 +1,6 @@ import "phaser"; import FightScene from "./fight_scene"; +import Critter from "./critter"; import { GRAVITY_Y } from "./game"; import newtonRaphson from "newton-raphson-method"; // TODO: TS signatures @@ -8,13 +9,13 @@ const SPEED = 550; class Spear extends Phaser.Physics.Arcade.Sprite { source: Phaser.GameObjects.Sprite; - target: Phaser.GameObjects.Sprite | undefined; + target: Critter | undefined; body: Phaser.Physics.Arcade.Body; constructor( scene: FightScene, source: Phaser.GameObjects.Sprite, - target: Phaser.GameObjects.Sprite | undefined, + target: Critter | undefined, ) { super(scene, scene.player.x, scene.player.y, "spear"); this.play({ key: "spearAni", repeat: -1 }); @@ -60,6 +61,8 @@ class Spear extends Phaser.Physics.Arcade.Sprite { this.scene.sound.play("sfx_hit_critter"); // TODO: bounce? this.destroy(); + if (!this.target) return; + this.target.hitFlash(); this.target.flee(); }