-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Philipp Sehmisch
committed
Sep 20, 2020
1 parent
40e6331
commit 49060d4
Showing
10 changed files
with
155 additions
and
96 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,49 @@ | ||
class Particle extends Entity { | ||
|
||
|
||
constructor(pos: Point, sprite: Sprite, lifetime: number) { | ||
constructor(pos: Point, sprite: Sprite, lifetime: number, fade: boolean, velocity:number) { | ||
super(pos) | ||
this.sprite = sprite | ||
this.sprite.drawOrder = CONST.LAYER_FX | ||
|
||
this.behaviors.push(new SelfDestructBehavior(lifetime)) | ||
this.behaviors.push(new SelfDestructBehavior(lifetime, fade)) | ||
if ("setProgress" in this.sprite) { | ||
this.behaviors.push(new AnimatedBehavior(lifetime, false)) | ||
} | ||
|
||
if (velocity > 0) { | ||
let angle = Math.random() * Math.PI * 2 | ||
this.behaviors.push(new FlyForwardBehavior(this, { x: Math.sin(angle), y:Math.cos(angle)}, velocity, { x:0, y:0})) | ||
} | ||
} | ||
|
||
} | ||
|
||
class ParticleEmitterBehavior extends Behavior { | ||
|
||
private time: number = 0 | ||
private particleLifetime: number | ||
private particleSpread: number | ||
private particleSprite: ImageResource | ||
public frequency: number | ||
|
||
constructor(particleLifetime: number, particleSprite: ImageResource, frequency: number, spread:number) { | ||
super() | ||
this.particleLifetime = particleLifetime | ||
this.particleSprite = particleSprite | ||
this.particleSpread = spread | ||
this.frequency = frequency | ||
} | ||
|
||
update(entity:Entity, deltaTime: number, state: State) : void { | ||
|
||
this.time += deltaTime | ||
while (this.time > this.frequency) { | ||
state.addEntity(new Particle( | ||
entity.pos, | ||
new SimpleSprite(this.particleSprite), | ||
this.particleLifetime, | ||
true, | ||
Math.random() * Math.random() * this.particleSpread) | ||
) | ||
this.time -= this.frequency | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
class Rocket extends Entity { | ||
|
||
static PARTICLE_SPRITE: Sprite | ||
|
||
constructor(pos: Point, direction: Point, initialVelocity: Point) { | ||
super(pos) | ||
|
||
this.sprite = new SimpleSprite(ImageResource.ROCKET) | ||
this.sprite.renderPivot = {x: 19, y: 9} | ||
this.sprite.drawOrder = CONST.LAYER_MOBS | ||
this.behaviors.push(new FlyForwardBehavior(this, pos, direction, initialVelocity)) | ||
this.behaviors.push(new FlyForwardBehavior(this, direction, CONST.ROCKET_VELOCITY, initialVelocity)) | ||
this.behaviors.push(new ExplodeOnImpactBehavior) | ||
this.behaviors.push(new ParticleEmitterBehavior(0.25, ImageResource.SPARK, 0.01, 3)) | ||
this.behaviors.push(SelfDestructIfOffscreen) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters