Skip to content

Commit

Permalink
Make wings easier to use
Browse files Browse the repository at this point in the history
  • Loading branch information
lorgan3 committed Oct 17, 2024
1 parent 331f121 commit a2f846d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/data/entity/character.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ export class Character extends Container implements HurtableEntity, Syncable {
}

if (this.wings) {
this.wings.flap();
this.wings.flap(this.time);
this.animator.animate(AnimationState.Float);

if (this.wings.power <= 0) {
Expand Down
9 changes: 8 additions & 1 deletion src/data/entity/wings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ export class Wings extends Container {
private static minScale = 1;
private static flapThreshHold = 0.2;
private static lift = 2.6;
private static flapInterval = 15;

private sprite: AnimatedSprite;
private particles: SimpleParticleEmitter;

private _power = Wings.fullPower;
private lastFlap = 0;

constructor(private character: Character) {
super();
Expand Down Expand Up @@ -68,7 +70,11 @@ export class Wings extends Container {
ControllableSound.fromEntity(this.character, Sound.Wing);
}

flap() {
flap(time: number) {
if (time - this.lastFlap < Wings.flapInterval) {
return;
}

if (
this.character.body.grounded ||
this.character.body.yVelocity > Wings.flapThreshHold
Expand All @@ -82,6 +88,7 @@ export class Wings extends Container {
this.sprite.scale.set(map(Wings.minScale, Wings.maxScale, this.power));
this.particles.burst(10);
ControllableSound.fromEntity(this.character, Sound.Jump);
this.lastFlap = time;
}
}

Expand Down

0 comments on commit a2f846d

Please sign in to comment.