Skip to content

Commit

Permalink
Basic "launch" death animation
Browse files Browse the repository at this point in the history
  • Loading branch information
IsThatRay committed Oct 28, 2023
1 parent eb50a7b commit 5e649ca
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
40 changes: 40 additions & 0 deletions src/animations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Game from './game';
import { Creature } from './creature';
import { Hex } from './utility/hex';
import { Ability } from './ability';
import { QuadraticCurve } from './utility/curve';

// to fix @ts-expect-error 2554: properly type the arguments for the trigger functions in `game.ts`

Expand All @@ -12,6 +13,7 @@ type AnimationOptions = {
ignoreMovementPoint?: boolean;
ignoreTraps?: boolean;
ignoreFacing?: boolean;
callback?: () => void;
callbackStepIn?: (hex?: Hex) => void;
pushed?: boolean;
turnAroundOnComplete?: boolean;
Expand Down Expand Up @@ -307,4 +309,42 @@ export class Animations {

return [tween, sprite, dist];
}

death(creature: Creature, opts: AnimationOptions) {
const game = this.game;
const length = 100;
const numSegments = 10;
const speed = !opts.overrideSpeed ? 500 : opts.overrideSpeed;

const curve = new QuadraticCurve(0.1, -5, 0);

const segmentLength = Math.round(length / numSegments);
const segmentTime = Math.round(speed / numSegments);

const startPos = creature.creatureSprite.getPos();

creature.healthHide();

let currSegment = 1;

const anim = () => {
if (currSegment > numSegments) {
opts.callback();
return;
}

let next = {
x: startPos.x + segmentLength * currSegment,
y: startPos.y + curve.calc_y(segmentLength * currSegment)
}

creature.creatureSprite.setPx(next, segmentTime).then(() => {
anim();
});

currSegment++;
}

anim();
}
}
12 changes: 11 additions & 1 deletion src/creature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1540,7 +1540,13 @@ export class Creature {
}

// Kill animation
this.creatureSprite.setAlpha(0, 500).then(() => this.destroy());
//this.creatureSprite.setAlpha(0, 500).then(() => this.destroy());
const opts = {
callback: () => {this.destroy();}
}

this.creatureSprite.setAlpha(0, 500)
game.animations.death(this, opts);
this.cleanHex();

game.updateQueueDisplay();
Expand Down Expand Up @@ -1921,6 +1927,10 @@ class CreatureSprite {
}
}

getPos() {
return this._group.position;
}

hint(text: string, hintType: CreatureHintType) {
const tooltipSpeed = 250;
const tooltipDisplaySpeed = 500;
Expand Down

0 comments on commit 5e649ca

Please sign in to comment.