Files
shooting-word/js/particle.js
T
Ku6epXBOCTuK ec01e1ce56
Deploy to GitHub Pages / deploy (push) Failing after 1m2s
fix: add frame factor calculations
2026-06-26 22:23:47 +05:00

29 lines
879 B
JavaScript

class Particle {
constructor(x, y, color) {
this.x = x;
this.y = y;
this.vx = (Math.random() - 0.5) * S.particleVel;
this.vy = (Math.random() - 0.5) * S.particleVel;
this.life = 1;
this.decay = S.particleDecayBase + Math.random() * S.particleDecayRange;
this.color = color;
this.size = S.particleSizeMin + Math.random() * (S.particleSizeMax - S.particleSizeMin);
}
update() {
this.x += this.vx * frameFactor;
this.y += this.vy * frameFactor;
this.life -= this.decay * frameFactor;
this.vx *= S.particleDamping;
this.vy *= S.particleDamping;
}
draw() {
ctx.save();
ctx.globalAlpha = this.life;
ctx.fillStyle = this.color;
ctx.shadowColor = this.color;
ctx.shadowBlur = S.particleGlow;
ctx.fillRect(this.x - this.size / 2, this.y - this.size / 2, this.size, this.size);
ctx.restore();
}
}