Last active
November 28, 2016 16:16
-
-
Save raduGaspar/07330f997342c0bef931c238a0826983 to your computer and use it in GitHub Desktop.
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
import { Scene, Particle } from '../../engine'; | |
export default class Bullet extends Particle { | |
constructor(model) { | |
super(3, '#ff0'); | |
this.x = model.x; | |
this.y = model.y; | |
this.angle = model.angle + Math.PI*0.5; | |
this.speed = 5; | |
this.created = Date.now(); | |
this.lifeTime = 3000; | |
this.removeBullet = this.removeBullet.bind(this); | |
} | |
removeBullet() { | |
this.scene.remove(this); | |
} | |
update() { | |
if (Date.now() - this.created >= this.lifeTime) { | |
this.removeBullet(); | |
} | |
this.x += Math.sin(this.angle) * this.speed; | |
this.y -= Math.cos(this.angle) * this.speed; | |
Scene.wrap(this); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment