From 7010c9ca72200eeeeb3e18f5a73193a02f30c06e Mon Sep 17 00:00:00 2001 From: Paolo Brasolin <paolo.brasolin@eurac.edu> Date: Mon, 11 Apr 2022 19:01:50 +0200 Subject: [PATCH] feat: #fe flash critter on hit --- frontend/src/js/critter.ts | 5 +++++ frontend/src/js/spear.ts | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/frontend/src/js/critter.ts b/frontend/src/js/critter.ts index 539baea..b380674 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 ce6ad72..ac86673 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(); } -- GitLab