Skip to content
Snippets Groups Projects
Commit 7010c9ca authored by Paolo.Brasolin's avatar Paolo.Brasolin
Browse files

feat: #fe flash critter on hit

parent 229d58ca
No related branches found
No related tags found
No related merge requests found
...@@ -82,6 +82,11 @@ class Critter extends Phaser.Physics.Arcade.Sprite { ...@@ -82,6 +82,11 @@ class Critter extends Phaser.Physics.Arcade.Sprite {
this.play({ key: this.species + "_run", repeat: -1 }); this.play({ key: this.species + "_run", repeat: -1 });
this.body.setVelocity(3 * this.baseVelocity, 0); this.body.setVelocity(3 * this.baseVelocity, 0);
} }
hitFlash() {
this.setTintFill(0xcc0000);
this.scene.time.delayedCall(100, () => this.clearTint());
}
} }
export default Critter; export default Critter;
import "phaser"; import "phaser";
import FightScene from "./fight_scene"; import FightScene from "./fight_scene";
import Critter from "./critter";
import { GRAVITY_Y } from "./game"; import { GRAVITY_Y } from "./game";
import newtonRaphson from "newton-raphson-method"; // TODO: TS signatures import newtonRaphson from "newton-raphson-method"; // TODO: TS signatures
...@@ -8,13 +9,13 @@ const SPEED = 550; ...@@ -8,13 +9,13 @@ const SPEED = 550;
class Spear extends Phaser.Physics.Arcade.Sprite { class Spear extends Phaser.Physics.Arcade.Sprite {
source: Phaser.GameObjects.Sprite; source: Phaser.GameObjects.Sprite;
target: Phaser.GameObjects.Sprite | undefined; target: Critter | undefined;
body: Phaser.Physics.Arcade.Body; body: Phaser.Physics.Arcade.Body;
constructor( constructor(
scene: FightScene, scene: FightScene,
source: Phaser.GameObjects.Sprite, source: Phaser.GameObjects.Sprite,
target: Phaser.GameObjects.Sprite | undefined, target: Critter | undefined,
) { ) {
super(scene, scene.player.x, scene.player.y, "spear"); super(scene, scene.player.x, scene.player.y, "spear");
this.play({ key: "spearAni", repeat: -1 }); this.play({ key: "spearAni", repeat: -1 });
...@@ -60,6 +61,8 @@ class Spear extends Phaser.Physics.Arcade.Sprite { ...@@ -60,6 +61,8 @@ class Spear extends Phaser.Physics.Arcade.Sprite {
this.scene.sound.play("sfx_hit_critter"); this.scene.sound.play("sfx_hit_critter");
// TODO: bounce? // TODO: bounce?
this.destroy(); this.destroy();
if (!this.target) return;
this.target.hitFlash();
this.target.flee(); this.target.flee();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment