Skip to content

Commit

Permalink
Added comments
Browse files Browse the repository at this point in the history
  • Loading branch information
IsThatRay committed Oct 28, 2023
1 parent f54ab24 commit ef7fbd1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
14 changes: 10 additions & 4 deletions src/animations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,16 @@ export class Animations {

death(creature: Creature, opts: AnimationOptions) {
const game = this.game;

const length = 100;
const numSegments = 10;

// Animation Properties
const length = 100; // Distance travelled in x
const numSegments = 10; // "Resolution" of the curve
const speed = !opts.overrideSpeed ? 500 : opts.overrideSpeed;

// Curve should pass (0, 0)
const curve = opts.flipped ? new QuadraticCurve(0.1, 5, 0) : new QuadraticCurve(0.1, -5, 0);

// Tween properties
const segmentLength = (opts.flipped ? -1 : 1) * Math.round(length / numSegments);
const segmentTime = Math.round(speed / numSegments);

Expand All @@ -335,15 +338,18 @@ export class Animations {
return;
}

// Calculate the point in the curve
let next = {
x: startPos.x + segmentLength * currSegment,
y: startPos.y + curve.calc_y(segmentLength * currSegment)
};

// Tween to point
creature.creatureSprite.setPx(next, segmentTime).then(() => {
// Next tween
anim();
});

currSegment++;
}

Expand Down
8 changes: 5 additions & 3 deletions src/creature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1539,22 +1539,24 @@ export class Creature {
this.player.deactivate(); // Here because of score calculation
}

// Kill animation
//this.creatureSprite.setAlpha(0, 500).then(() => this.destroy());

// Kill animation
const opts = {
callback: () => {this.destroy();},
flipped: false
};

// Check whether or not to flip the animation
if (killerCreature instanceof Creature) {
if (this.pos.x - killerCreature.pos.x < 0) {
opts.flipped = true;
}
}

// Fade and rotate the sprite
this.creatureSprite.setAngle(opts.flipped ? -90 : 90, 500);
this.creatureSprite.setAlpha(0, 500);

// Trigger the "launching off board"
game.animations.death(this, opts);
this.cleanHex();

Expand Down

0 comments on commit ef7fbd1

Please sign in to comment.