Skip to content

gitflarePublicPartly agent-ready40

neon-drift

Real-time multiplayer arcade racer on Cloudflare Workers and Durable Objects.

Add the Apache-2.0 licence3efe3da
JavaScript55 lines2.1 KB
const N = 1024, RN = 24; /** Pure camera target math (no allocation: writes into out). */export function cameraTarget(me, arena, phase, scale, out) {  const la = 120;  out.x = me.x + Math.cos(me.heading) * la;  out.y = me.y + Math.sin(me.heading) * la;  let z = 1;  if (me.boost) z -= 0.12;  if (arena && arena.warn) z -= 0.05;  if (z < 0.85) z = 0.85;  let base = 1.1;  if (phase === 'countdown') base = 1.18;  out.zoom = scale * z * base;  return out;} export function createFx() {  const x = new Float32Array(N), y = new Float32Array(N), vx = new Float32Array(N), vy = new Float32Array(N);  const life = new Float32Array(N), max = new Float32Array(N), hue = new Float32Array(N), size = new Float32Array(N);  const rx = new Float32Array(RN), ry = new Float32Array(RN), rl = new Float32Array(RN), rm = new Float32Array(RN);  const rr = new Float32Array(RN), rh = new Float32Array(RN), rg = new Float32Array(RN);  let head = 0, rhead = 0, shake = 0;  const fx = {    x, y, vx, vy, life, max, hue, size, count: N,    rx, ry, rl, rm, rr, rh, rg, ringCount: RN,    burst(px, py, h, n, speed) {      for (let i = 0; i < n; i++) {        const k = head; head = (head + 1) % N;        const a = Math.random() * 6.2832, s = speed * (0.2 + Math.random());        x[k] = px; y[k] = py; vx[k] = Math.cos(a) * s; vy[k] = Math.sin(a) * s;        max[k] = life[k] = 0.4 + Math.random() * 0.8; hue[k] = h; size[k] = 1.5 + Math.random() * 3;      }    },    /** expanding ring; maxR in world units, grow = life seconds */    ring(px, py, h, maxR, dur) {      const k = rhead; rhead = (rhead + 1) % RN;      rx[k] = px; ry[k] = py; rh[k] = h; rr[k] = maxR; rm[k] = rl[k] = dur || 0.5;    },    addShake(v) { shake = Math.min(24, shake + v); },    update(dt) {      const d = Math.pow(0.05, dt);      for (let i = 0; i < N; i++) {        if (life[i] <= 0) continue;        life[i] -= dt; x[i] += vx[i] * dt; y[i] += vy[i] * dt; vx[i] *= d; vy[i] *= d;      }      for (let i = 0; i < RN; i++) if (rl[i] > 0) rl[i] -= dt;      shake *= Math.pow(0.002, dt);      if (shake < 0.05) shake = 0;    },    get shake() { return shake; },  };  return fx;}