add stupid explosion effect

This commit is contained in:
Asraelite 2016-03-25 17:42:03 +00:00
parent 8a8a9c8ae3
commit 6f85d63839
5 changed files with 128 additions and 8 deletions

View file

@ -0,0 +1,39 @@
class Particle {
constructor(effect, x, y, xvel, yvel, color, size, behaviour, lifetime) {
this.effect = effect;
this.x = x;
this.y = y;
this.xvel = xvel || 0;
this.yvel = yvel || 0;
this.color = color || '#f00';
this.size = size || 1;
this.behaviour = behaviour;
this.lifetime = lifetime * (1 + (Math.random() - 0.5) * 0.5) || 100;
}
tick() {
this.x += this.xvel;
this.y += this.yvel;
if (this.behaviour == 'sizzle') {
this.xvel *= 0.98;
this.yvel *= 0.98;
this.x += (Math.random() - 0.5) * 2;
this.y += (Math.random() - 0.5) * 2;
}
if (this.lifetime-- <= 0) {
this.destroy();
}
}
render() {
let x = this.x;
let y = this.y;
this.effect.pallet.square(this.color, x, y, this.size);
}
destroy() {
this.effect.particles.delete(this);
}
}