Skip to content

Commit

Permalink
Fixed explosion animation cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Sehmisch committed Sep 20, 2020
1 parent 3c8e008 commit 40e6331
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
8 changes: 6 additions & 2 deletions entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,15 @@ class AnimatedBehavior extends Behavior {
private time: number
private duration: number

constructor(cycleDuration: number) {
constructor(cycleDuration: number, randomize:boolean) {
super()

this.time = Math.random() * cycleDuration
this.duration = cycleDuration
if (randomize) {
this.time = Math.random() * cycleDuration
} else {
this.time = 0
}
}

public update(entity: Entity, deltaTime: number, state:State) : void {
Expand Down
4 changes: 2 additions & 2 deletions mob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Bird extends Entity {
this.collisionRadiusSqare = CONST.MOB_BIRD_RADIUS * CONST.MOB_BIRD_RADIUS

this.behaviors.push(new SineMovementBehavior(this, CONST.MOB_BIRD_MOVE_RANGE, CONST.MOB_BIRD_MOVE_TIME, "x"))
this.behaviors.push(new AnimatedBehavior(CONST.MOB_BIRD_ANIMATION_LENGHT))
this.behaviors.push(new AnimatedBehavior(CONST.MOB_BIRD_ANIMATION_LENGHT, true))
}
}

Expand All @@ -38,7 +38,7 @@ class Ufo extends Entity {
this.sprite.drawOrder = CONST.LAYER_MOBS
this.collisionRadiusSqare = CONST.MOB_UFO_RADIUS * CONST.MOB_UFO_RADIUS

this.behaviors.push(new AnimatedBehavior(CONST.MOB_UFO_ANIMATION_LENGHT))
this.behaviors.push(new AnimatedBehavior(CONST.MOB_UFO_ANIMATION_LENGHT, true))
this.behaviors.push(new SineMovementBehavior(this, 600, 10, "x"))
this.behaviors.push(new SineMovementBehavior(this, 200, 4, "y"))
}
Expand Down
2 changes: 1 addition & 1 deletion particle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Particle extends Entity {

this.behaviors.push(new SelfDestructBehavior(lifetime))
if ("setProgress" in this.sprite) {
this.behaviors.push(new AnimatedBehavior(lifetime))
this.behaviors.push(new AnimatedBehavior(lifetime, false))
}

}
Expand Down

0 comments on commit 40e6331

Please sign in to comment.