MCPcopy Index your code
hub / github.com/monkeytypegame/monkeytype / updateParticle

Function updateParticle

frontend/src/ts/elements/monkey-power.ts:93–123  ·  view source on GitHub ↗

* @param {Particle} particle

(particle: Particle)

Source from the content-addressed store, hash-verified

91 * @param {Particle} particle
92 */
93function updateParticle(particle: Particle): void {
94 if (!ctx.canvas || !isSafeNumber(ctx.deltaTime)) return;
95
96 particle.prev.x = particle.x;
97 particle.prev.y = particle.y;
98 // Update pos
99 particle.x += particle.vel.x * ctx.deltaTime;
100 particle.y += particle.vel.y * ctx.deltaTime;
101
102 if (particle.x > ctx.canvas.width) {
103 particle.vel.x *= -particleBounceMod;
104 particle.x =
105 ctx.canvas.width - (particle.x - ctx.canvas.width) * particleBounceMod;
106 } else if (particle.x < 0) {
107 particle.vel.x *= -particleBounceMod;
108 particle.x *= -particleBounceMod;
109 }
110 if (particle.y > ctx.canvas.height) {
111 particle.vel.y *= -particleBounceMod;
112 particle.y =
113 ctx.canvas.height - (particle.y - ctx.canvas.height) * particleBounceMod;
114 } else if (particle.y < 0) {
115 particle.vel.y *= -1;
116 particle.y *= -1;
117 }
118
119 particle.vel.y += gravity * ctx.deltaTime;
120 particle.vel.x *= 1 - drag * ctx.deltaTime;
121
122 particle.alpha *= 1 - particleFade * ctx.deltaTime;
123}
124
125export function init(): void {
126 ctx.caret = qsr("#caret");

Callers 1

renderFunction · 0.85

Calls 1

isSafeNumberFunction · 0.90

Tested by

no test coverage detected