72 lines
1.6 KiB
JavaScript
72 lines
1.6 KiB
JavaScript
import {Proton, TextNode, TextNodeRenderer} from '@avocado/graphics';
|
|
|
|
export class DamageEmitter {
|
|
|
|
constructor() {
|
|
const proton = new Proton();
|
|
const emitter = new Proton.Emitter();
|
|
proton.addEmitter(emitter);
|
|
this.emitter = emitter;
|
|
this.proton = proton;
|
|
}
|
|
|
|
addRenderer(renderer) {
|
|
this.renderer = renderer;
|
|
this.proton.addRender(this.renderer);
|
|
}
|
|
|
|
emit(position, amount) {
|
|
// BUGS
|
|
const pz = new Proton.PointZone();
|
|
pz.x = position[0];
|
|
pz.y = -position[1];
|
|
const initializers = [
|
|
new Proton.Body(new DamageTextNode(Math.abs(amount))),
|
|
new Proton.Position(pz),
|
|
new Proton.Mass(1),
|
|
new Proton.Life(2),
|
|
new Proton.Velocity(
|
|
new Proton.Span(80, 120),
|
|
new Proton.Vector3D(0, 5, 0),
|
|
27.5
|
|
),
|
|
];
|
|
// Heh, bugs.
|
|
const rot = new Proton.Rotate(0, 0, 0);
|
|
rot.a = new Proton.Span(-.003, .003);
|
|
const behaviors = [
|
|
new Proton.Alpha(1, .5),
|
|
new Proton.Color(amount < 0 ? 0x00ff00 : 0xff0000),
|
|
new Proton.Scale(.6, 1),
|
|
new Proton.Force(0, -1, 0),
|
|
rot,
|
|
];
|
|
this.emitter.createParticle(initializers, behaviors);
|
|
}
|
|
|
|
tick(elapsed) {
|
|
this.proton.tick(elapsed);
|
|
}
|
|
|
|
}
|
|
|
|
export class DamageTextNode extends TextNode {
|
|
|
|
constructor(damage) {
|
|
super(damage);
|
|
if (damage > 999) {
|
|
this.span.style.fontSize = '2em';
|
|
}
|
|
else if (damage > 99) {
|
|
this.span.style.fontSize = '1.5em';
|
|
}
|
|
else if (damage > 9) {
|
|
this.span.style.fontSize = '1.2em';
|
|
}
|
|
else {
|
|
this.span.style.fontSize = '1em';
|
|
}
|
|
}
|
|
|
|
}
|