Skip to content

Instantly share code, notes, and snippets.

@raduGaspar
Last active November 28, 2016 16:16
Show Gist options
  • Save raduGaspar/07330f997342c0bef931c238a0826983 to your computer and use it in GitHub Desktop.
Save raduGaspar/07330f997342c0bef931c238a0826983 to your computer and use it in GitHub Desktop.
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