85 lines
1.9 KiB
JavaScript
85 lines
1.9 KiB
JavaScript
import {Proton, TextNode, TextNodeRenderer} from '@avocado/graphics';
|
|
|
|
class DamageTextNode extends TextNode {
|
|
|
|
constructor(damage) {
|
|
const {amount, damageSpec, isDamage} = damage;
|
|
super(amount);
|
|
// Big numbers are literally big.
|
|
if (amount > 999) {
|
|
this.span.style.fontSize = '1em';
|
|
}
|
|
else if (amount > 99) {
|
|
this.span.style.fontSize = '0.75em';
|
|
}
|
|
else if (amount > 9) {
|
|
this.span.style.fontSize = '0.6em';
|
|
}
|
|
else {
|
|
this.span.style.fontSize = '0.5em';
|
|
}
|
|
// Class by affinity and whether it's damage or healing.
|
|
this.span.className += ' ' + damageSpec.affinity;
|
|
if (isDamage) {
|
|
this.span.className += ' is-damage';
|
|
}
|
|
else {
|
|
this.span.className += ' is-healing';
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
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, damage) {
|
|
// BUGS
|
|
const pz = new Proton.PointZone();
|
|
pz.x = position[0];
|
|
pz.y = -position[1];
|
|
const initializers = [
|
|
new Proton.Body(new DamageTextNode(damage)),
|
|
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(-.008, .008);
|
|
const behaviors = [
|
|
new Proton.Alpha(1, .25),
|
|
new Proton.Scale(.8, 1.2),
|
|
new Proton.Force(0, -1, 0),
|
|
rot,
|
|
];
|
|
this.emitter.createParticle(initializers, behaviors);
|
|
}
|
|
|
|
hasParticles() {
|
|
return this.emitter.particles.length > 0;
|
|
}
|
|
|
|
tick(elapsed) {
|
|
this.proton.tick(elapsed);
|
|
}
|
|
|
|
}
|