Death242 commited on
Commit
7586f4b
·
verified ·
1 Parent(s): df0f4e7

Static site

Browse files
Files changed (9) hide show
  1. index.html +2 -2
  2. static/city.js +19 -2
  3. static/extras.js +55 -9
  4. static/game.js +40 -12
  5. static/legion.js +303 -186
  6. static/main.js +35 -5
  7. static/police.js +60 -1
  8. static/sound.js +5 -0
  9. static/world.js +34 -17
index.html CHANGED
@@ -8,7 +8,7 @@
8
  <meta name="theme-color" content="#10131b">
9
  <link rel="preconnect" href="https://fonts.googleapis.com"><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
10
  <link href="https://fonts.googleapis.com/css2?family=Unbounded:wght@500;800;900&family=Inter:wght@400;500;600;700&family=Noto+Kufi+Arabic:wght@700&display=swap" rel="stylesheet">
11
- <link rel="stylesheet" href="/static/style.css?v=1795180010">
12
  <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 64 64%27%3E%3Crect width=%2764%27 height=%2764%27 rx=%2714%27 fill=%27%23050506%27/%3E%3Ccircle cx=%2732%27 cy=%2732%27 r=%2716%27 fill=%27none%27 stroke=%27%23fff%27 stroke-width=%275%27/%3E%3C/svg%3E">
13
  <script type="importmap">
14
  { "imports": {
@@ -242,6 +242,6 @@
242
  <div id="toast" role="status"></div>
243
  <noscript><p style="position:fixed;inset:auto 0 0;padding:16px;background:#111;color:#fff;text-align:center">VOID needs JavaScript for the 3D car.</p></noscript>
244
  <script src="/static/hub.js" data-app="void" data-credit="none" data-splash="none" defer></script>
245
- <script type="module" src="/static/main.js?v=1795180010"></script>
246
  </body>
247
  </html>
 
8
  <meta name="theme-color" content="#10131b">
9
  <link rel="preconnect" href="https://fonts.googleapis.com"><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
10
  <link href="https://fonts.googleapis.com/css2?family=Unbounded:wght@500;800;900&family=Inter:wght@400;500;600;700&family=Noto+Kufi+Arabic:wght@700&display=swap" rel="stylesheet">
11
+ <link rel="stylesheet" href="/static/style.css?v=1795181084">
12
  <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 64 64%27%3E%3Crect width=%2764%27 height=%2764%27 rx=%2714%27 fill=%27%23050506%27/%3E%3Ccircle cx=%2732%27 cy=%2732%27 r=%2716%27 fill=%27none%27 stroke=%27%23fff%27 stroke-width=%275%27/%3E%3C/svg%3E">
13
  <script type="importmap">
14
  { "imports": {
 
242
  <div id="toast" role="status"></div>
243
  <noscript><p style="position:fixed;inset:auto 0 0;padding:16px;background:#111;color:#fff;text-align:center">VOID needs JavaScript for the 3D car.</p></noscript>
244
  <script src="/static/hub.js" data-app="void" data-credit="none" data-splash="none" defer></script>
245
+ <script type="module" src="/static/main.js?v=1795181084"></script>
246
  </body>
247
  </html>
static/city.js CHANGED
@@ -32,6 +32,10 @@ const NEON = ["#ff3b5c", "#3dfcff", "#ffd23d", "#7dff6a", "#ff8a3d", "#c07dff",
32
  const ADS = [["HYDRA LTE242", "THE DREAM CAR", "#ff2a3a", "#0b0b10"], ["VOID", "DRIVE · FLY · LAND", "#ffffff", "#101828"], ["NY PIZZA", "A SLICE FOR $1", "#ffd23d", "#8a1010"],
33
  ["SMASH BURGERS", "OPEN ALL NIGHT", "#ff8a3d", "#1a0d05"], ["MADE BY AWSAA", "BUILT IN CODE", "#3dfcff", "#081a24"], ["SKYLINE", "WEATHER APP", "#7cc4ff", "#0c1424"], ["COLA", "ICE COLD", "#ffffff", "#c8102e"], ["BROADWAY", "TONIGHT", "#ffd23d", "#2a0838"]];
34
 
 
 
 
 
35
  export async function buildCity(scene, canvasTex, COARSE) {
36
  let seed = 7; const rnd = () => (seed = (seed * 16807) % 2147483647) / 2147483647;
37
  const pick = a => a[Math.floor(rnd() * a.length)], range = (a, b) => a + rnd() * (b - a);
@@ -217,9 +221,19 @@ export async function buildCity(scene, canvasTex, COARSE) {
217
  // (the ground layers get depth nudges so they never flicker through each other far away: grass back, pavement, parks and markings forward)
218
  const grassMat = mat({ map: grassTex, roughness: .95, color: 0xb8d0a0, polygonOffset: true, polygonOffsetFactor: 4, polygonOffsetUnits: 4 });
219
  grassTex.repeat.set(1, 1);
 
 
220
  for (const [a, b] of [[-20000, HW0], [W1, W2], [EW1, 20000]]) {
221
- const g = new THREE.PlaneGeometry(b - a, 40000).rotateX(-Math.PI / 2), uv = g.attributes.uv; for (let k = 0; k < uv.count; k++) uv.setXY(k, uv.getX(k) * (b - a) / 10, uv.getY(k) * 4000);
222
- const m = new THREE.Mesh(g, grassMat); m.position.set((a + b) / 2, -.12, 0); scene.add(m);
 
 
 
 
 
 
 
 
223
  }
224
  const asphaltN = normalTex(256, 256, (g, w, h) => { g.fillStyle = "#808080"; g.fillRect(0, 0, w, h); for (let i = 0; i < 9000; i++) { const v = 90 + rnd() * 120 | 0; g.fillStyle = `rgb(${v},${v},${v})`; g.fillRect(rnd() * w | 0, rnd() * h | 0, 1 + (rnd() < .2), 1 + (rnd() < .2)); } }, 1.6);
225
  asphaltN.repeat.copy(asphaltTex.repeat);
@@ -676,6 +690,7 @@ export async function buildCity(scene, canvasTex, COARSE) {
676
  // small props go in 200 m tiles and are only drawn near the camera (trees a little further)
677
  const propTiles = [];
678
  const smashReg = new Map(); // list -> { kind, items: [ [mesh, index, matrix], ... ] per item } for the props a car can knock over
 
679
  const instT = (geo, material, list, place, colorOf, far = 330, kind) => {
680
  const groups = new Map(), PT = 400;
681
  list.forEach((it, i) => { place(it, i); const e = m4.elements, k = Math.floor(e[12] / PT) * 1000 + Math.floor(e[14] / PT); let gr = groups.get(k); if (!gr) groups.set(k, gr = []); gr.push([m4.clone(), colorOf ? colorOf(it, i) : null, i]); });
@@ -758,6 +773,8 @@ export async function buildCity(scene, canvasTex, COARSE) {
758
  tufts.frustumCulled = false; tufts.count = 0; tufts.setColorAt(0, new THREE.Color(1, 1, 1)); scene.add(tufts);
759
  let tuftAt = null; const tuftC = new THREE.Color();
760
  const grassy = (x, z) => {
 
 
761
  if (inPark(x, z)) return Math.hypot((x - lake.x) / (lake.rx + 6), (z - lake.z) / (lake.rz + 6)) > 1 ? .08 : -1;
762
  if (x > MT.x0 && x < MT.x1 && z > MT.z0 && z < MT.z1 && terrain) { const h = terrain.height(x, z); return h > .3 && h < 165 ? h : -1; }
763
  if (x < HW0 - 30 && !(x > -2660 && x < -1860 && Math.abs(z) < 34)) return 0; // New Jersey, off the runway
 
32
  const ADS = [["HYDRA LTE242", "THE DREAM CAR", "#ff2a3a", "#0b0b10"], ["VOID", "DRIVE · FLY · LAND", "#ffffff", "#101828"], ["NY PIZZA", "A SLICE FOR $1", "#ffd23d", "#8a1010"],
33
  ["SMASH BURGERS", "OPEN ALL NIGHT", "#ff8a3d", "#1a0d05"], ["MADE BY AWSAA", "BUILT IN CODE", "#3dfcff", "#081a24"], ["SKYLINE", "WEATHER APP", "#7cc4ff", "#0c1424"], ["COLA", "ICE COLD", "#ffffff", "#c8102e"], ["BROADWAY", "TONIGHT", "#ffd23d", "#2a0838"]];
34
 
35
+ // the Sky Park (open grass north of the grid: the mega ramp, the half-pipe, the second loop) and the secret tunnel south of
36
+ // downtown: a trench down at a0..a1, a tube under the Hudson, a trench up at b0..b1 on the far bank (floor -12, roof -2)
37
+ export const SKYPARK = { x0: -920, x1: 760, z0: -1320, z1: -760 };
38
+ export const TUNNEL = { z: 2200, half: 7, a0: -372, a1: -492, b0: -1768, b1: -1888, floor: -12, ceil: -2 };
39
  export async function buildCity(scene, canvasTex, COARSE) {
40
  let seed = 7; const rnd = () => (seed = (seed * 16807) % 2147483647) / 2147483647;
41
  const pick = a => a[Math.floor(rnd() * a.length)], range = (a, b) => a + rnd() * (b - a);
 
221
  // (the ground layers get depth nudges so they never flicker through each other far away: grass back, pavement, parks and markings forward)
222
  const grassMat = mat({ map: grassTex, roughness: .95, color: 0xb8d0a0, polygonOffset: true, polygonOffsetFactor: 4, polygonOffsetUnits: 4 });
223
  grassTex.repeat.set(1, 1);
224
+ const V2 = (x, y) => new THREE.Vector2(x, y);
225
+ const trenches = [[TUNNEL.a1 - 12, TUNNEL.a0], [TUNNEL.b1, TUNNEL.b0 + 12]].map(([x0, x1]) => [x0, x1, TUNNEL.z - TUNNEL.half - .5, TUNNEL.z + TUNNEL.half + .5]);
226
  for (const [a, b] of [[-20000, HW0], [W1, W2], [EW1, 20000]]) {
227
+ const holes = trenches.filter(([x0, x1]) => x0 > a && x1 < b);
228
+ let g;
229
+ if (!holes.length) { g = new THREE.PlaneGeometry(b - a, 40000).rotateX(-Math.PI / 2).translate((a + b) / 2, 0, 0); }
230
+ else { // (shape y is -z: the shape is laid flat with rotateX)
231
+ const sh = new THREE.Shape([V2(a, 20000), V2(b, 20000), V2(b, -20000), V2(a, -20000)].reverse());
232
+ for (const [x0, x1, z0, z1] of holes) sh.holes.push(new THREE.Path([V2(x0, -z0), V2(x1, -z0), V2(x1, -z1), V2(x0, -z1)]));
233
+ g = new THREE.ShapeGeometry(sh).rotateX(-Math.PI / 2);
234
+ }
235
+ const ps = g.attributes.position, uv = g.attributes.uv; for (let k = 0; k < ps.count; k++) uv.setXY(k, ps.getX(k) / 10, ps.getZ(k) / 10);
236
+ const m = new THREE.Mesh(g, grassMat); m.position.y = -.12; scene.add(m);
237
  }
238
  const asphaltN = normalTex(256, 256, (g, w, h) => { g.fillStyle = "#808080"; g.fillRect(0, 0, w, h); for (let i = 0; i < 9000; i++) { const v = 90 + rnd() * 120 | 0; g.fillStyle = `rgb(${v},${v},${v})`; g.fillRect(rnd() * w | 0, rnd() * h | 0, 1 + (rnd() < .2), 1 + (rnd() < .2)); } }, 1.6);
239
  asphaltN.repeat.copy(asphaltTex.repeat);
 
690
  // small props go in 200 m tiles and are only drawn near the camera (trees a little further)
691
  const propTiles = [];
692
  const smashReg = new Map(); // list -> { kind, items: [ [mesh, index, matrix], ... ] per item } for the props a car can knock over
693
+ P.trees = P.trees.filter(([x, z]) => !(x > SKYPARK.x0 && x < SKYPARK.x1 && z > SKYPARK.z0 && z < SKYPARK.z1) && !trenches.some(([x0, x1, z0, z1]) => x > x0 - 6 && x < x1 + 6 && z > z0 - 6 && z < z1 + 6));
694
  const instT = (geo, material, list, place, colorOf, far = 330, kind) => {
695
  const groups = new Map(), PT = 400;
696
  list.forEach((it, i) => { place(it, i); const e = m4.elements, k = Math.floor(e[12] / PT) * 1000 + Math.floor(e[14] / PT); let gr = groups.get(k); if (!gr) groups.set(k, gr = []); gr.push([m4.clone(), colorOf ? colorOf(it, i) : null, i]); });
 
773
  tufts.frustumCulled = false; tufts.count = 0; tufts.setColorAt(0, new THREE.Color(1, 1, 1)); scene.add(tufts);
774
  let tuftAt = null; const tuftC = new THREE.Color();
775
  const grassy = (x, z) => {
776
+ if (Math.abs(z - TUNNEL.z) < TUNNEL.half + 3 && x < TUNNEL.a0 + 3 && x > TUNNEL.b1 - 3) return -1; // not in the tunnel trenches
777
+ if (x > SKYPARK.x0 && x < SKYPARK.x1 && z > SKYPARK.z0 && z < SKYPARK.z1 && (Math.abs(z + 1000) < 16 || Math.abs(z + 905) < 14 || Math.abs(z + 1180) < 12 || Math.abs(z + 880) < 7)) return -1; // nor on the Sky Park runs
778
  if (inPark(x, z)) return Math.hypot((x - lake.x) / (lake.rx + 6), (z - lake.z) / (lake.rz + 6)) > 1 ? .08 : -1;
779
  if (x > MT.x0 && x < MT.x1 && z > MT.z0 && z < MT.z1 && terrain) { const h = terrain.height(x, z); return h > .3 && h < 165 ? h : -1; }
780
  if (x < HW0 - 30 && !(x > -2660 && x < -1860 && Math.abs(z) < 34)) return 0; // New Jersey, off the runway
static/extras.js CHANGED
@@ -1,6 +1,7 @@
1
  // Taxi jobs and hidden coins.
2
  // Taxi: press J (or Menu → Taxi job). Passengers wave from the kerb near you; stop next to one and they hop in,
3
  // the GPS shows where they're going, and the fare drops the longer you take. Back-to-back fares build a streak.
 
4
  // Coins: 80 spinning VOID coins: rooftops, piers, the bridge towers, the park, and since the city doubled the south
5
  // supertalls, the Ferris wheel, the El, the stunt park, Brooklyn, the highway and up the mountain trail; found ones stay found.
6
  import * as THREE from "three";
@@ -17,7 +18,9 @@ export function createExtras(W, api, nav, sound) {
17
  // ---- passengers: a little figure with a yellow beacon ----
18
  const personMat = new THREE.MeshStandardMaterial({ color: 0x3060c0, roughness: .7 }), skin = new THREE.MeshStandardMaterial({ color: 0xd9a07a, roughness: .7 });
19
  const beaconMat = new THREE.MeshBasicMaterial({ color: new THREE.Color(0xffd23d).multiplyScalar(1.8), transparent: true, opacity: .35, depthWrite: false, toneMapped: false, side: THREE.DoubleSide });
20
- const fig = () => { const g = new THREE.Group(); const b = new THREE.Mesh(new THREE.CylinderGeometry(.25, .3, 1.2, 10).translate(0, .9, 0), personMat); const h = new THREE.Mesh(new THREE.SphereGeometry(.17, 12, 8).translate(0, 1.7, 0), skin); const arm = new THREE.Mesh(new THREE.BoxGeometry(.1, .6, .1).translate(0, .3, 0), personMat); arm.position.set(0, 1.35, .3); arm.rotation.x = -2.6; g.add(b, h, arm); const beam = new THREE.Mesh(new THREE.CylinderGeometry(1.4, 1.4, 30, 16, 1, true).translate(0, 15, 0), beaconMat); g.add(beam); g.userData.arm = arm; scene.add(g); return g; };
 
 
21
  const waiting = [fig(), fig(), fig()], dropMark = new THREE.Mesh(new THREE.CylinderGeometry(5, 5, 40, 24, 1, true).translate(0, 20, 0), new THREE.MeshBasicMaterial({ color: new THREE.Color(0x3dff8a).multiplyScalar(1.6), transparent: true, opacity: .22, depthWrite: false, toneMapped: false, side: THREE.DoubleSide }));
22
  scene.add(dropMark); dropMark.visible = false; waiting.forEach(w => w.visible = false);
23
  const kerb = (x0, z0, rMin, rMax) => { // a sidewalk spot rMin..rMax metres away
@@ -32,7 +35,10 @@ export function createExtras(W, api, nav, sound) {
32
  return null;
33
  };
34
  const J = { on: false, fare: null, streak: 0, t: 0, earned: 0 };
35
- function placeWaiting(p) { for (const w of waiting) { const s = kerb(p.x, p.z, 60, 260); if (s) { w.position.set(s[0], 0, s[1]); w.visible = true; } } }
 
 
 
36
  function toggle(on = !J.on) {
37
  const p = api.state; if (!p) return;
38
  J.on = on; J.fare = null; dropMark.visible = false;
@@ -97,13 +103,28 @@ export function createExtras(W, api, nav, sound) {
97
  const spots = [[GRID.ax(9), GRID.sz(3), "Midtown"], [GRID.ax(3), GRID.sz(15), "Park Ave"], [GRID.ax(11), GRID.sz(17), "Downtown"], [600, 0, "Broadway"], [GRID.ax(1), GRID.sz(6), "West Side"], [1400, 18, "Bridge"],
98
  [1880, 0, "Highway West"], [2380, 0, "Highway East"], [GRID.ax(5), GRID.sz(27), "South Ave"], [GRID.ax(10), GRID.sz(32), "Harbor"], [GRID.ax(2), GRID.sz(37), "Bay Ridge"], [GRID.ax(7), GRID.sz(22), "Midtown South"], [480, GRID.sz(20), "Under the El"]];
99
  if (W.city.mountains) { const [x, , z] = W.city.mountains.trail[1]; spots.push([x, z, "Hill Climb"]); }
100
- spots.forEach(([x, z, name]) => {
101
- const g = new THREE.Group(); g.position.set(x + 11, 0, z + 9); scene.add(g);
 
102
  g.add(new THREE.Mesh(new THREE.CylinderGeometry(.12, .15, 5, 8).translate(0, 2.5, 0), pole)); const b = new THREE.Mesh(new THREE.BoxGeometry(.8, .5, .5), boxM); b.position.y = 5; g.add(b);
103
  const f = new THREE.Mesh(new THREE.SphereGeometry(.18, 8, 6), flashM.clone()); f.position.set(-.45, 5, 0); g.add(f);
104
  TRAPS.push({ x, z, name, f, cool: 0 });
105
  });
106
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
  // ---- sky traffic: an airliner crossing high up, a slow blimp with a glowing VOID sign ----
108
  const plane = new THREE.Group(), blimp = new THREE.Group();
109
  {
@@ -124,6 +145,9 @@ export function createExtras(W, api, nav, sound) {
124
  return {
125
  toggle, pads: PADS, get job() { return J; }, coins: () => ({ got: got.size, total: COINS.length }),
126
  fastCams: () => TRAPS.filter(t => (best[t.name] || 0) >= 250).length,
 
 
 
127
  sky(dt, time) {
128
  skyT += dt;
129
  const a = (skyT * .012) % (Math.PI * 2); plane.position.set(Math.cos(a) * 2600, 620, Math.sin(a) * 1600); plane.rotation.y = -Math.atan2(Math.cos(a) * 1600, -Math.sin(a) * 2600);
@@ -162,13 +186,35 @@ export function createExtras(W, api, nav, sound) {
162
  cm.compose(cv, cq, cs); coinMesh.setMatrixAt(c.id, cm); glowMesh.setMatrixAt(c.id, cm);
163
  }
164
  coinMesh.instanceMatrix.needsUpdate = glowMesh.instanceMatrix.needsUpdate = true;
165
- $("gCoins").textContent = `🪙 ${got.size}/${COINS.length}` + (near < 150 ? ` · one ${Math.round(near)} m away` : "");
 
 
 
 
 
 
 
 
 
 
 
166
  if (!J.on) return;
167
  const sp = Math.hypot(p.vel.x, p.vel.z);
168
  // waving passengers; the nearest one gets in when you stop beside it
169
  for (const w of waiting) {
170
  if (!w.visible) continue;
171
  w.userData.arm.rotation.z = Math.sin(time * 6) * .4;
 
 
 
 
 
 
 
 
 
 
 
172
  if (!J.fare && Math.hypot(p.x - w.position.x, p.z - w.position.z) < 9 && sp < 4 && p.mode === "drive") {
173
  const d = kerb(w.position.x, w.position.z, 350, 1100); if (!d) continue;
174
  const dist = Math.hypot(d[0] - w.position.x, d[1] - w.position.z);
@@ -182,13 +228,13 @@ export function createExtras(W, api, nav, sound) {
182
  if (J.fare) {
183
  const f = J.fare; f.t -= dt;
184
  const pay = Math.max(50, Math.round(f.max * Math.min(1, .35 + f.t / 40)));
185
- $("gJob").textContent = `🚕 To ${f.street} · ${fmt(Math.max(0, f.t))} · $${pay}${J.streak > 1 ? ` · streak ×${J.streak}` : ""}`;
186
- if (Math.hypot(p.x - f.x, p.z - f.z) < 12 && sp < 4) {
187
  J.streak = f.t > 0 ? J.streak + 1 : 0; const total = pay + (J.streak > 1 ? J.streak * 100 : 0); J.earned += total;
188
- api.addScore(total, `🚕 Fare $${total}${J.streak > 1 ? ` (streak ×${J.streak})` : ""}`); J.fare = null; dropMark.visible = false; if (nav.dest && nav.dest.taxi) nav.setDest(null); placeWaiting(p);
189
  } else if (f.t < -20) { api.say("🚕 The passenger gave up and got out", 3); J.fare = null; J.streak = 0; dropMark.visible = false; if (nav.dest && nav.dest.taxi) nav.setDest(null); placeWaiting(p); }
190
  } else {
191
- $("gJob").textContent = `🚕 Find a passenger (yellow beams)${J.earned ? ` · $${J.earned} so far` : ""}`;
192
  if (waiting.every(w => !w.visible || Math.hypot(p.x - w.position.x, p.z - w.position.z) > 600)) placeWaiting(p);
193
  }
194
  },
 
1
  // Taxi jobs and hidden coins.
2
  // Taxi: press J (or Menu → Taxi job). Passengers wave from the kerb near you; stop next to one and they hop in,
3
  // the GPS shows where they're going, and the fare drops the longer you take. Back-to-back fares build a streak.
4
+ // VIPs (gold, only when your car can fly) want a skyscraper's rooftop helipad against the clock, and pay big.
5
  // Coins: 80 spinning VOID coins: rooftops, piers, the bridge towers, the park, and since the city doubled the south
6
  // supertalls, the Ferris wheel, the El, the stunt park, Brooklyn, the highway and up the mountain trail; found ones stay found.
7
  import * as THREE from "three";
 
18
  // ---- passengers: a little figure with a yellow beacon ----
19
  const personMat = new THREE.MeshStandardMaterial({ color: 0x3060c0, roughness: .7 }), skin = new THREE.MeshStandardMaterial({ color: 0xd9a07a, roughness: .7 });
20
  const beaconMat = new THREE.MeshBasicMaterial({ color: new THREE.Color(0xffd23d).multiplyScalar(1.8), transparent: true, opacity: .35, depthWrite: false, toneMapped: false, side: THREE.DoubleSide });
21
+ const fig = () => { const g = new THREE.Group(); const b = new THREE.Mesh(new THREE.CylinderGeometry(.25, .3, 1.2, 10).translate(0, .9, 0), personMat); const h = new THREE.Mesh(new THREE.SphereGeometry(.17, 12, 8).translate(0, 1.7, 0), skin); const arm = new THREE.Mesh(new THREE.BoxGeometry(.1, .6, .1).translate(0, .3, 0), personMat); arm.position.set(0, 1.35, .3); arm.rotation.x = -2.6; g.add(b, h, arm); const beam = new THREE.Mesh(new THREE.CylinderGeometry(1.4, 1.4, 30, 16, 1, true).translate(0, 15, 0), beaconMat); g.add(beam); g.userData.arm = arm; g.userData.beam = beam; g.userData.body = b; scene.add(g); return g; };
22
+ const vipBeam = new THREE.MeshBasicMaterial({ color: new THREE.Color(1.6, .5, 2.2), transparent: true, opacity: .4, depthWrite: false, toneMapped: false, side: THREE.DoubleSide }), vipSuit = new THREE.MeshStandardMaterial({ color: 0xd4a83a, metalness: .6, roughness: .3 });
23
+ const canFly = () => { const p = api.state; return !!p && (!p.ride || !!(p.ride.model && p.ride.model.kind && p.ride.model.kind.fly)); };
24
  const waiting = [fig(), fig(), fig()], dropMark = new THREE.Mesh(new THREE.CylinderGeometry(5, 5, 40, 24, 1, true).translate(0, 20, 0), new THREE.MeshBasicMaterial({ color: new THREE.Color(0x3dff8a).multiplyScalar(1.6), transparent: true, opacity: .22, depthWrite: false, toneMapped: false, side: THREE.DoubleSide }));
25
  scene.add(dropMark); dropMark.visible = false; waiting.forEach(w => w.visible = false);
26
  const kerb = (x0, z0, rMin, rMax) => { // a sidewalk spot rMin..rMax metres away
 
35
  return null;
36
  };
37
  const J = { on: false, fare: null, streak: 0, t: 0, earned: 0 };
38
+ function placeWaiting(p) {
39
+ waiting.forEach((w, k) => { const s = kerb(p.x, p.z, 60, 260); if (!s) return; w.position.set(s[0], 0, s[1]); w.visible = true;
40
+ const vip = k === 2 && canFly() && rnd() < .6; w.userData.vip = vip; w.userData.beam.material = vip ? vipBeam : beaconMat; w.userData.body.material = vip ? vipSuit : personMat; });
41
+ }
42
  function toggle(on = !J.on) {
43
  const p = api.state; if (!p) return;
44
  J.on = on; J.fare = null; dropMark.visible = false;
 
103
  const spots = [[GRID.ax(9), GRID.sz(3), "Midtown"], [GRID.ax(3), GRID.sz(15), "Park Ave"], [GRID.ax(11), GRID.sz(17), "Downtown"], [600, 0, "Broadway"], [GRID.ax(1), GRID.sz(6), "West Side"], [1400, 18, "Bridge"],
104
  [1880, 0, "Highway West"], [2380, 0, "Highway East"], [GRID.ax(5), GRID.sz(27), "South Ave"], [GRID.ax(10), GRID.sz(32), "Harbor"], [GRID.ax(2), GRID.sz(37), "Bay Ridge"], [GRID.ax(7), GRID.sz(22), "Midtown South"], [480, GRID.sz(20), "Under the El"]];
105
  if (W.city.mountains) { const [x, , z] = W.city.mountains.trail[1]; spots.push([x, z, "Hill Climb"]); }
106
+ spots.push([GRID.ax(12), GRID.sz(10), "East Side"], [GRID.ax(0), GRID.sz(28), "Riverside"], [GRID.ax(6), GRID.sz(40), "Battery"], [GRID.ax(9), GRID.sz(36), "Downtown South"], [-860, -1000, "Sky Park"], [-1100, 2200, "Tunnel", -12]);
107
+ spots.forEach(([x, z, name, y]) => {
108
+ const g = new THREE.Group(); if (y != null) g.position.set(x + 4, y, z + 5.2); else g.position.set(x + 11, 0, z + 9); scene.add(g);
109
  g.add(new THREE.Mesh(new THREE.CylinderGeometry(.12, .15, 5, 8).translate(0, 2.5, 0), pole)); const b = new THREE.Mesh(new THREE.BoxGeometry(.8, .5, .5), boxM); b.position.y = 5; g.add(b);
110
  const f = new THREE.Mesh(new THREE.SphereGeometry(.18, 8, 6), flashM.clone()); f.position.set(-.45, 5, 0); g.add(f);
111
  TRAPS.push({ x, z, name, f, cool: 0 });
112
  });
113
  }
114
+ // ---- radar gates: big frames in the sky that clock your speed and height as you fly through ----
115
+ const GATES = [], gateBest = store.get("void.gates") || {};
116
+ {
117
+ const frameMat = new THREE.MeshBasicMaterial({ color: new THREE.Color(.3, 1.6, 2.2), toneMapped: false });
118
+ const C = W.city, M = C.mountains;
119
+ [[-1320, 200, 400, 0, "Hudson Gate"], [C.lawn.x, 170, C.lawn.z, Math.PI / 2, "Park Gate"], [1350, 150, 0, 0, "Bridge Gate"], [-80, 360, 1250, Math.PI / 2, "Supertall Gate"], [M ? M.peak[0] - 200 : 3700, M ? M.peak[1] + 80 : 380, M ? M.peak[2] : -380, 0, "Summit Gate"], [-300, 140, -1000, 0, "Sky Park Gate"]].forEach(([x, y, z, yaw, name]) => {
120
+ const g = new THREE.Group(); g.position.set(x, y, z); g.rotation.y = -yaw;
121
+ for (const [w, h, py, pz] of [[1.4, 1.4, 15, 0], [1.4, 1.4, -15, 0]]) { const bar = new THREE.Mesh(new THREE.BoxGeometry(w, h, 31.4), frameMat); bar.position.set(0, py, pz); g.add(bar); }
122
+ for (const pz of [15, -15]) { const bar = new THREE.Mesh(new THREE.BoxGeometry(1.4, 30, 1.4), frameMat); bar.position.set(0, 0, pz); g.add(bar); }
123
+ scene.add(g); GATES.push({ x, y, z, nx: Math.cos(yaw), nz: Math.sin(yaw), name, g, side: 0, t: 0 });
124
+ });
125
+ }
126
+ let nearestCoinD = 1e9;
127
+
128
  // ---- sky traffic: an airliner crossing high up, a slow blimp with a glowing VOID sign ----
129
  const plane = new THREE.Group(), blimp = new THREE.Group();
130
  {
 
145
  return {
146
  toggle, pads: PADS, get job() { return J; }, coins: () => ({ got: got.size, total: COINS.length }),
147
  fastCams: () => TRAPS.filter(t => (best[t.name] || 0) >= 250).length,
148
+ nearestCoin: () => nearestCoinD, gates: GATES, traps: TRAPS,
149
+ coinsNear: (x, z, rr) => COINS.filter(c => c.on && Math.hypot(c.x - x, c.z - z) < rr).map(c => [c.x, c.z]),
150
+ taxi: () => ({ on: J.on, fare: J.fare, waiting: waiting.filter(w => w.visible).map(w => [w.position.x, w.position.z, !!w.userData.vip]) }),
151
  sky(dt, time) {
152
  skyT += dt;
153
  const a = (skyT * .012) % (Math.PI * 2); plane.position.set(Math.cos(a) * 2600, 620, Math.sin(a) * 1600); plane.rotation.y = -Math.atan2(Math.cos(a) * 1600, -Math.sin(a) * 2600);
 
186
  cm.compose(cv, cq, cs); coinMesh.setMatrixAt(c.id, cm); glowMesh.setMatrixAt(c.id, cm);
187
  }
188
  coinMesh.instanceMatrix.needsUpdate = glowMesh.instanceMatrix.needsUpdate = true;
189
+ $("gCoins").textContent = `🪙 ${got.size}/${COINS.length}` + (near < 150 ? ` · one ${Math.round(near)} m away` : ""); nearestCoinD = near;
190
+ // radar gates: fly through one and it clocks you
191
+ for (const G of GATES) {
192
+ if (G.t > 0) { G.t -= dt; if (G.t <= 0) G.g.children.forEach(m => m.material.color.setRGB(.3, 1.6, 2.2)); }
193
+ const dx = p.x - G.x, dy = p.y - G.y, dz = p.z - G.z, plane = dx * G.nx + dz * G.nz, side = Math.sign(plane);
194
+ if (G.side && side !== G.side && Math.abs(plane) < 8 && Math.abs(dy) < 15 && Math.abs(-dx * G.nz + dz * G.nx) < 15 && G.t <= 0) {
195
+ G.t = 3; const kmh = Math.round(Math.hypot(p.vel.x, p.vel.y, p.vel.z) * 3.6), alt = Math.round(p.y), b = gateBest[G.name] || 0;
196
+ if (!G.own) { G.own = true; G.g.children.forEach(m => m.material = m.material.clone()); } G.g.children.forEach(m => m.material.color.setRGB(2.6, 2.6, 2.6));
197
+ if (kmh > b) { gateBest[G.name] = kmh; store.set("void.gates", gateBest); api.addScore(Math.round(kmh * 3), `📡 ${G.name}: ${kmh} km/h at ${alt} m (new best)`); } else api.say(`📡 ${G.name}: ${kmh} km/h at ${alt} m (best ${b})`, 2.5);
198
+ }
199
+ G.side = side;
200
+ }
201
  if (!J.on) return;
202
  const sp = Math.hypot(p.vel.x, p.vel.z);
203
  // waving passengers; the nearest one gets in when you stop beside it
204
  for (const w of waiting) {
205
  if (!w.visible) continue;
206
  w.userData.arm.rotation.z = Math.sin(time * 6) * .4;
207
+ if (!J.fare && Math.hypot(p.x - w.position.x, p.z - w.position.z) < 9 && sp < 4 && p.mode === "drive" && w.userData.vip) {
208
+ // a VIP: fly them to a rooftop helipad 400-1200 m away before the clock runs out
209
+ const pads = W.city.helipads.filter(h => { const d = Math.hypot(h.x - w.position.x, h.z - w.position.z); return d > 400 && d < 1200 && h.y > 40; });
210
+ if (pads.length) {
211
+ const h = pads[Math.floor(rnd() * pads.length)], dist = Math.hypot(h.x - w.position.x, h.z - w.position.z);
212
+ J.fare = { x: h.x, z: h.z, y: h.y, vip: true, t: dist / 38 + 35, max: 1500 + Math.round(dist * 1.4), street: `the rooftop ${Math.round(h.y)} m up` };
213
+ waiting.forEach(o => o.visible = false); dropMark.position.set(h.x, h.y, h.z); dropMark.visible = true;
214
+ nav.setDest({ name: `👔 VIP rooftop`, x: h.x, z: h.z, y: h.y, air: true, taxi: true });
215
+ api.say(`👔 VIP: "Fly me to that rooftop, ${Math.round(h.y)} m up. You have ${Math.round(J.fare.t)} seconds."`, 4); sound.pop(); continue;
216
+ }
217
+ }
218
  if (!J.fare && Math.hypot(p.x - w.position.x, p.z - w.position.z) < 9 && sp < 4 && p.mode === "drive") {
219
  const d = kerb(w.position.x, w.position.z, 350, 1100); if (!d) continue;
220
  const dist = Math.hypot(d[0] - w.position.x, d[1] - w.position.z);
 
228
  if (J.fare) {
229
  const f = J.fare; f.t -= dt;
230
  const pay = Math.max(50, Math.round(f.max * Math.min(1, .35 + f.t / 40)));
231
+ $("gJob").textContent = `${f.vip ? "👔 VIP" : "🚕"} To ${f.street} · ${fmt(Math.max(0, f.t))} · $${pay}${J.streak > 1 ? ` · streak ×${J.streak}` : ""}`;
232
+ if (Math.hypot(p.x - f.x, p.z - f.z) < (f.vip ? 10 : 12) && sp < 4 && (!f.vip || Math.abs(p.y - f.y) < 3)) {
233
  J.streak = f.t > 0 ? J.streak + 1 : 0; const total = pay + (J.streak > 1 ? J.streak * 100 : 0); J.earned += total;
234
+ api.addScore(total, `${f.vip ? "👔 VIP fare" : "🚕 Fare"} $${total}${J.streak > 1 ? ` (streak ×${J.streak})` : ""}`); J.fare = null; dropMark.visible = false; if (nav.dest && nav.dest.taxi) nav.setDest(null); placeWaiting(p);
235
  } else if (f.t < -20) { api.say("🚕 The passenger gave up and got out", 3); J.fare = null; J.streak = 0; dropMark.visible = false; if (nav.dest && nav.dest.taxi) nav.setDest(null); placeWaiting(p); }
236
  } else {
237
+ $("gJob").textContent = `🚕 Find a passenger (yellow beams${waiting.some(w => w.visible && w.userData.vip) ? ", the purple one is a VIP" : ""})${J.earned ? ` · $${J.earned} so far` : ""}`;
238
  if (waiting.every(w => !w.visible || Math.hypot(p.x - w.position.x, p.z - w.position.z) > 600)) placeWaiting(p);
239
  }
240
  },
static/game.js CHANGED
@@ -88,14 +88,21 @@ export function createGame(W, car, sound, life, opts = {}) {
88
  { x: city.lawn.x - 40, z: city.lawn.z, yaw: 0, len: 18, h: 5.5 }, { x: 1000, z: -300, yaw: -Math.PI / 2, len: 18, h: 6 }, { x: -1000, z: -500, yaw: Math.PI / 2, len: 18, h: 6 },
89
  // the stunt park (south-west square)
90
  { x: -900, z: 1345, yaw: 0, len: 10, h: 2.2 }, { x: -860, z: 1365, yaw: 0, len: 8, h: 1.6 }, { x: -760, z: 1350, yaw: Math.PI, len: 10, h: 2.4 }, { x: -880, z: 1420, yaw: 0, len: 22, h: 7.5, w: 5 },
91
- { x: -680, z: 1440, yaw: Math.PI, len: 22, h: 7.5, w: 5 }, { x: -620, z: 1350, yaw: Math.PI / 2, len: 12, h: 3 }, { x: -560, z: 1460, yaw: -Math.PI / 2, len: 12, h: 3 }, { x: -800, z: 1395, yaw: Math.PI / 4, len: 9, h: 1.8 }]) RAMPS.push({ w: 4, ...r });
 
 
 
 
92
  {
93
  const rampMat = new THREE.MeshStandardMaterial({ color: 0x1b1c22, metalness: .6, roughness: .35 }), stripe = new THREE.MeshBasicMaterial({ color: new THREE.Color(0xffd23d).multiplyScalar(1.6), toneMapped: false });
94
  for (const r of RAMPS) {
95
  if (r.main) continue;
96
- const shape = new THREE.Shape(); const n = 16; shape.moveTo(0, 0); for (let i = 0; i <= n; i++) { const u = i / n; shape.lineTo(u * r.len, r.h * u * u); } shape.lineTo(r.len, 0); shape.closePath();
97
- const geo = new THREE.ExtrudeGeometry(shape, { depth: r.w * 2, bevelEnabled: false }).translate(0, 0, -r.w);
 
 
98
  const m = new THREE.Mesh(geo, rampMat); m.position.set(r.x, 0, r.z); m.rotation.y = -r.yaw; m.castShadow = m.receiveShadow = true; W.scene.add(m);
 
99
  for (const s of [-1, 1]) { const e = new THREE.Mesh(new THREE.BoxGeometry(.3, .08, r.w * 2), stripe); e.position.set(r.len - .2, r.h + .02, 0); m.add(e); const side = new THREE.Mesh(new THREE.BoxGeometry(r.len, .1, .1), stripe); side.position.set(r.len / 2, r.h / 2 + .1, s * r.w); side.rotation.z = Math.atan(r.h / r.len); m.add(side); }
100
  }
101
  }
@@ -123,10 +130,12 @@ export function createGame(W, car, sound, life, opts = {}) {
123
  const rampAt = (x, z) => {
124
  for (const r of RAMPS) {
125
  const dx = x - r.x, dz = z - r.z, c = Math.cos(r.yaw), s = Math.sin(r.yaw), a = dx * c + dz * s, b = -dx * s + dz * c;
 
126
  if (a >= 0 && a <= r.len && Math.abs(b) < r.w + .3) return { r, h: r.h * (a / r.len) ** 2, a, slope: 2 * r.h * a / (r.len * r.len) };
127
  }
128
  return null;
129
  };
 
130
  const RINGS = [];
131
  {
132
  let sd = 9; const rr = () => (sd = (sd * 16807) % 2147483647) / 2147483647;
@@ -338,6 +347,7 @@ export function createGame(W, car, sound, life, opts = {}) {
338
 
339
  // the ground under a point: ramps, rooftops (only if you are up there), else the street; water is -1
340
  function groundAt(x, z, y) {
 
341
  const rp = rampAt(x, z); if (rp) return { h: rp.h, ramp: rp };
342
  const roof = city.roofAt(x, z); if (roof > 0 && y >= roof - 1.2) return { h: roof, roof: true };
343
  if (y < 1.5 && city.isWater(x, z)) return { h: -1, water: true };
@@ -454,6 +464,7 @@ export function createGame(W, car, sound, life, opts = {}) {
454
  // fuel: about 10 minutes of driving, 5 of flying; empty and the engine (and thrusters) stop
455
  const flying = g.mode === "air";
456
  if (gas || flying || Math.hypot(g.vel.x, g.vel.z) > 1 || (g.thr > .05 && g.veh !== "car")) g.fuel = Math.max(0, g.fuel - dt / (flying ? 300 : 600));
 
457
  if (g.fuel <= 0) { gas = 0; if (!g.fuelMsg) { g.fuelMsg = 1; say("Out of fuel! Coast to a ⛽ station (GPS has the nearest)", 5); } }
458
  else if (g.fuel < .15 && g.fuelMsg !== 2 && g.fuel > 0) { g.fuelMsg = 2; say("Low fuel: find a ⛽ station", 4); }
459
  if (g.fuel > .2) g.fuelMsg = 0;
@@ -532,7 +543,7 @@ export function createGame(W, car, sound, life, opts = {}) {
532
  const gr = groundAt(g.x, g.z, g.y), prevY = g.y;
533
  if (gr.water) { splash(); return; }
534
  if (gr.ramp) {
535
- g.y = gr.h; g.pitch = Math.atan(gr.ramp.slope) * Math.cos(g.yaw - gr.ramp.r.yaw);
536
  // off the lip fast and you fly
537
  if (gr.ramp.a > gr.ramp.r.len - .8 && u > 8 && Math.cos(g.yaw - gr.ramp.r.yaw) > .6) {
538
  const th = Math.atan(gr.ramp.slope); g.mode = "air"; g.hover = false; g.vel.y = Math.sin(th) * u; g.vel.x *= Math.cos(th); g.vel.z *= Math.cos(th); g.airT = 0; g.jump = true; return;
@@ -543,8 +554,12 @@ export function createGame(W, car, sound, life, opts = {}) {
543
  g.pitch = lerp(g.pitch, Math.atan(sa) + g.sp, clamp(dt * 12)); if (Math.abs(u) > 6 && Math.random() < .08) g.spV += (Math.random() - .5) * Math.abs(u) * .02 / Math.max(.6, OR); // bumps
544
  if (Math.abs(u) > 4) g.shake = Math.max(g.shake || 0, Math.min(.22, Math.abs(u) * .004 / Math.max(.6, OR))); // rough ground rattles you, less in a truck
545
  }
 
546
  else { g.y = gr.h; g.pitch = g.sp; }
547
- g.onTerrain = !!gr.terrain; if (!gr.terrain) { g.slope = 0; g.tRoll = 0; }
 
 
 
548
  // drive into the loop and the track takes you round
549
  if (g.x > LOOP_X - 1.5 && g.x < LOOP_X + .5 && Math.abs(g.z) < HW && Math.cos(g.yaw) > .8 && u > 3 && g.y < .2) { g.mode = "rail"; g.d = T.D[T.loopIn]; g.v = u; return; }
550
  traffic(dt);
@@ -556,6 +571,14 @@ export function createGame(W, car, sound, life, opts = {}) {
556
  return;
557
  }
558
 
 
 
 
 
 
 
 
 
559
  if (g.mode === "rail") {
560
  T.sample(g.d, fr);
561
  g.v = clamp(g.v + ((gas ? 10 * (1 - g.v / 92) : 0) + g.nitroOn * 10 - (brake ? 16 : 0) - .4 - G * fr.f.y) * dt, 0, 112);
@@ -675,12 +698,14 @@ export function createGame(W, car, sound, life, opts = {}) {
675
  if (gr.water) { splash(); return; }
676
  g.y = gr.h;
677
  landTricks();
678
- const down2 = -g.vel.y, vh2 = Math.hypot(g.vel.x, g.vel.z), angle = Math.atan2(down2, Math.max(.1, vh2));
 
679
  if (down2 > 12) impact(g.x, g.y, g.z, down2 * 1.2);
680
  if (down2 > 26 || (down2 > 15 && angle > 1.1)) { hurt(down2 * 3, `Hit the ground hard (${down2.toFixed(1)} m/s down)`); if (g.wreck > 0) return; }
681
  else if (down2 > 10) hurt((down2 - 10) * 1.5, "Hard landing");
682
  else if (g.airT > 2 && !g.jump) { if (down2 < 2) addScore(300, "Butter landing!"); else if (down2 < 4.5) addScore(150, "Smooth landing"); else say(`Firm landing (${down2.toFixed(1)} m/s)`, 2); }
683
  const zone = ZONES.find(z => Math.hypot(g.x - z.x, g.z - z.z) < (z.r || PAD_R) && Math.abs(g.y - (z.y || 0)) < 3);
 
684
  if (zone && !g.done.has(zone.id)) { g.done.add(zone.id); if (zone.safe) addScore(1000 + Math.round(Math.max(0, 7 - down2) * 60) + (zone.y ? 500 : 0), `Landed at ${zone.id}`); else say(`${zone.id} is unsafe: ${zone.note}`); }
685
  if (g.jump && g.airT > 1.2) addScore(Math.round(g.airT * 120), `Airtime ${g.airT.toFixed(1)} s`);
686
  // keep the kinetic energy: the drop's speed carries into the roll along the ground
@@ -743,7 +768,7 @@ export function createGame(W, car, sound, life, opts = {}) {
743
  busted(msg) { say(msg, 4); g.hp = 100; g.vel.set(0, 0, 0); $("gScore").textContent = "$" + g.score.toLocaleString(); sound.crash(); },
744
  // the VOID car: locked until bought (or the secret code); then you're put straight into it
745
  useHero() { if (!g || !g.started) return; if (g.veh === "foot") Object.assign(g, { veh: "car", mode: "drive" }); if (g.ride) { if (g.ride.c) life.park(g.ride.c, g.x, g.z, g.yaw); g.ride = null; } g.heroPark = null; g.vel.set(0, 0, 0); rig.yaw = null; say("Your VOID car: 330 km/h and it flies (F)", 3); },
746
- freeze(t) { g.frozen = t; }, teleport(x, z, yaw) { Object.assign(g, { x, z, y: 0, yaw, mode: "drive", pitch: 0, roll: 0, wings: 0 }); g.vel.set(0, 0, 0); camPos.set(x - Math.cos(yaw) * 8, 3, z - Math.sin(yaw) * 8); rig.yaw = yaw; orbit.yaw = orbit.pitch = 0; },
747
  hitBox, isWater: (x, z) => city.isWater(x, z), impact: (x, z, p) => impact(x, .6, z, p),
748
  groundAt: (x, z, y) => groundAt(x, z, y), wreck: why => wreck(why), setVehicle: t => setVehicle(t), setStick: (x, y) => { stick.x = x; stick.y = y; }, nearCars: (x, z, r) => life ? life.nearCars(x, z, r) : [], fly: () => { if (g.mode === "drive") toggleFly(); },
749
  policeClear: () => opts.policeClear && opts.policeClear(), terrainH: (x, z) => city.terrainH ? city.terrainH(x, z) : 0, board: () => boardToggle(),
@@ -757,7 +782,7 @@ export function createGame(W, car, sound, life, opts = {}) {
757
  },
758
  };
759
  return {
760
- api, RINGS, RAILS, RAMPS,
761
  get state() { return g; }, get photo() { return photo; },
762
  enter() { active = true; start(); },
763
  exit() { active = false; keys.clear(); touch.clear(); sound.setGame("off"); if (photo) togglePhoto(); },
@@ -766,8 +791,9 @@ export function createGame(W, car, sound, life, opts = {}) {
766
  if (!g) start();
767
  pollPad();
768
  if (g.started && !paused && !photo) { acc += dt; const H = 1 / 60; let n = 0; while (acc >= H && n < 6) { step(H); acc -= H; n++; } }
769
- const air = g.mode === "air", speed = g.mode === "rail" ? g.v * 3.6 : g.vel.length() * 3.6;
770
  if (g.mode === "rail") { basis.makeBasis(fr.f, fr.u, fr.s); q.setFromRotationMatrix(basis); }
 
771
  else {
772
  const f = new THREE.Vector3(Math.cos(g.yaw) * Math.cos(g.pitch), Math.sin(g.pitch), Math.sin(g.yaw) * Math.cos(g.pitch));
773
  const s0 = new THREE.Vector3().crossVectors(f, UP).normalize(), u0 = new THREE.Vector3().crossVectors(s0, f);
@@ -779,7 +805,7 @@ export function createGame(W, car, sound, life, opts = {}) {
779
  car.group.position.copy(fr.p); car.group.quaternion.copy(q); car.group.updateMatrixWorld(true);
780
  let cam;
781
  if (orbit.t > 0) orbit.t -= dt;
782
- const sp0 = g.mode === "rail" ? g.v : g.vel.length();
783
  // like GTA: once you stop moving the mouse (or finger) for a moment and the car is moving, the view eases back behind it
784
  if (orbit.t <= 1.5 && !photo && sp0 > 3 && !orbit.drag && g.veh !== "foot") { const k = clamp(dt * 1.6); orbit.yaw = lerp(orbit.yaw, 0, k); orbit.pitch = lerp(orbit.pitch, 0, k); }
785
  const nitroFov = g.nitroOn * 9;
@@ -791,6 +817,7 @@ export function createGame(W, car, sound, life, opts = {}) {
791
  else {
792
  let up = UP.clone();
793
  if (g.mode === "rail") { T.sample(Math.max(T.D[T.loopIn] - 6, g.d - 7.5), back); camPos.copy(loc(back, 0, 2.4, 0)); camLook.copy(loc(fr, 5, .8, 0)); up = back.u.clone(); }
 
794
  else {
795
  // an orbit rig round the car: only the angles are smoothed, so the camera never lags behind at speed, never
796
  // cuts through the car when you look round, and never swings in front when you reverse
@@ -806,12 +833,13 @@ export function createGame(W, car, sound, life, opts = {}) {
806
  const want = g.veh === "foot" ? 3.4 + (orbit.dist || 0) * .6 : g.veh === "board" ? 4.4 + speed * .015 + (orbit.dist || 0) * .6 : lerp(6.6 + speed * .012, 12 + speed * .01, A) + (orbit.dist || 0) + (g.veh === "plane" || g.veh === "heli" ? 6 : g.veh === "boat" ? 2 : 0);
807
  const pivot = fr.p.clone().add(new THREE.Vector3(0, g.veh === "foot" ? 1.55 : g.veh === "board" ? 1.9 : 1.3 + .1 * A, 0)), dir = new THREE.Vector3(-Math.cos(yawC) * Math.cos(pitC), Math.sin(pitC), -Math.sin(yawC) * Math.cos(pitC));
808
  // walls: pull in at once, ease back out
809
- let room = want; for (let t = .8; t <= want; t += .5) { const q2 = pivot.clone().addScaledVector(dir, t); if (q2.y < .3 || hitBox(q2.x, q2.z, q2.y, .35)) { room = Math.max(1.6, t - .6); break; } }
 
810
  rig.dist = room < rig.dist ? room : lerp(rig.dist, room, clamp(dt * 2.5));
811
  camPos.copy(pivot).addScaledVector(dir, rig.dist);
812
  camLook.copy(pivot).add(new THREE.Vector3(fx, 0, fz).multiplyScalar(1.5 + 1.5 * A));
813
  if (A > .01) up.lerp(fr.u, .15 * A).normalize();
814
- if (camPos.y < .4) camPos.y = .4;
815
  }
816
  cam = { pos: camPos.clone(), look: camLook.clone(), up, fov: lerp(56, 68, clamp(speed / 330)) + nitroFov };
817
  }
 
88
  { x: city.lawn.x - 40, z: city.lawn.z, yaw: 0, len: 18, h: 5.5 }, { x: 1000, z: -300, yaw: -Math.PI / 2, len: 18, h: 6 }, { x: -1000, z: -500, yaw: Math.PI / 2, len: 18, h: 6 },
89
  // the stunt park (south-west square)
90
  { x: -900, z: 1345, yaw: 0, len: 10, h: 2.2 }, { x: -860, z: 1365, yaw: 0, len: 8, h: 1.6 }, { x: -760, z: 1350, yaw: Math.PI, len: 10, h: 2.4 }, { x: -880, z: 1420, yaw: 0, len: 22, h: 7.5, w: 5 },
91
+ { x: -680, z: 1440, yaw: Math.PI, len: 22, h: 7.5, w: 5 }, { x: -620, z: 1350, yaw: Math.PI / 2, len: 12, h: 3 }, { x: -560, z: 1460, yaw: -Math.PI / 2, len: 12, h: 3 }, { x: -800, z: 1395, yaw: Math.PI / 4, len: 9, h: 1.8 },
92
+ // Sky Park, the grass north of the city: a 500 m mega ramp up to 60 m, a long soft landing slope, kickers and a half-pipe
93
+ { x: -780, z: -1000, yaw: 0, len: 500, h: 60, w: 9, mega: true }, { x: 520, z: -1000, yaw: Math.PI, len: 420, h: 34, w: 14, land: true },
94
+ { x: -560, z: -880, yaw: 0, len: 26, h: 9, w: 5 }, { x: -380, z: -880, yaw: 0, len: 18, h: 5, w: 5 }, { x: 60, z: -880, yaw: Math.PI, len: 26, h: 9, w: 5 },
95
+ { x: -700, z: -1180, yaw: 0, len: 150, h: 5.5, w: 10, pipe: true, flat: 4.5 }]) RAMPS.push({ w: 4, ...r });
96
  {
97
  const rampMat = new THREE.MeshStandardMaterial({ color: 0x1b1c22, metalness: .6, roughness: .35 }), stripe = new THREE.MeshBasicMaterial({ color: new THREE.Color(0xffd23d).multiplyScalar(1.6), toneMapped: false });
98
  for (const r of RAMPS) {
99
  if (r.main) continue;
100
+ const shape = new THREE.Shape(); const n = r.mega || r.land ? 40 : 16;
101
+ if (r.pipe) { shape.moveTo(-r.w, r.h + .4); shape.lineTo(-r.w, 0); shape.lineTo(r.w, 0); shape.lineTo(r.w, r.h + .4); for (let i = 0; i <= n; i++) { const b = r.w - i / n * 2 * r.w, e = Math.max(0, Math.abs(b) - r.flat) / (r.w - r.flat); shape.lineTo(b, r.h * e * e); } shape.closePath(); }
102
+ else { shape.moveTo(0, 0); for (let i = 0; i <= n; i++) { const u = i / n; shape.lineTo(u * r.len, r.h * u * u); } shape.lineTo(r.len, 0); shape.closePath(); }
103
+ const geo = r.pipe ? new THREE.ExtrudeGeometry(shape, { depth: r.len, bevelEnabled: false }).rotateY(Math.PI / 2) : new THREE.ExtrudeGeometry(shape, { depth: r.w * 2, bevelEnabled: false }).translate(0, 0, -r.w);
104
  const m = new THREE.Mesh(geo, rampMat); m.position.set(r.x, 0, r.z); m.rotation.y = -r.yaw; m.castShadow = m.receiveShadow = true; W.scene.add(m);
105
+ if (r.pipe) { for (const s of [-1, 1]) { const e = new THREE.Mesh(new THREE.BoxGeometry(r.len, .12, .12), stripe); e.position.set(r.len / 2, r.h + .45, s * r.w); m.add(e); } continue; }
106
  for (const s of [-1, 1]) { const e = new THREE.Mesh(new THREE.BoxGeometry(.3, .08, r.w * 2), stripe); e.position.set(r.len - .2, r.h + .02, 0); m.add(e); const side = new THREE.Mesh(new THREE.BoxGeometry(r.len, .1, .1), stripe); side.position.set(r.len / 2, r.h / 2 + .1, s * r.w); side.rotation.z = Math.atan(r.h / r.len); m.add(side); }
107
  }
108
  }
 
130
  const rampAt = (x, z) => {
131
  for (const r of RAMPS) {
132
  const dx = x - r.x, dz = z - r.z, c = Math.cos(r.yaw), s = Math.sin(r.yaw), a = dx * c + dz * s, b = -dx * s + dz * c;
133
+ if (r.pipe) { if (a >= 0 && a <= r.len && Math.abs(b) < r.w) { const e = Math.max(0, Math.abs(b) - r.flat) / (r.w - r.flat); return { r, h: r.h * e * e, a, slope: 0, side: Math.sign(b) * 2 * r.h * e / (r.w - r.flat) }; } continue; }
134
  if (a >= 0 && a <= r.len && Math.abs(b) < r.w + .3) return { r, h: r.h * (a / r.len) ** 2, a, slope: 2 * r.h * a / (r.len * r.len) };
135
  }
136
  return null;
137
  };
138
+ const LOOP2 = { x: 220, z: -905, R: 15, shift: 7 }; // the Sky Park loop: radius, and how far it moves you sideways
139
  const RINGS = [];
140
  {
141
  let sd = 9; const rr = () => (sd = (sd * 16807) % 2147483647) / 2147483647;
 
347
 
348
  // the ground under a point: ramps, rooftops (only if you are up there), else the street; water is -1
349
  function groundAt(x, z, y) {
350
+ const tn = opts.tunnel && opts.tunnel(x, z, y); if (tn) return tn;
351
  const rp = rampAt(x, z); if (rp) return { h: rp.h, ramp: rp };
352
  const roof = city.roofAt(x, z); if (roof > 0 && y >= roof - 1.2) return { h: roof, roof: true };
353
  if (y < 1.5 && city.isWater(x, z)) return { h: -1, water: true };
 
464
  // fuel: about 10 minutes of driving, 5 of flying; empty and the engine (and thrusters) stop
465
  const flying = g.mode === "air";
466
  if (gas || flying || Math.hypot(g.vel.x, g.vel.z) > 1 || (g.thr > .05 && g.veh !== "car")) g.fuel = Math.max(0, g.fuel - dt / (flying ? 300 : 600));
467
+ if (g.emp > 0) { g.emp -= dt; gas = 0; g.nitro = Math.min(g.nitro, .05); if (g.mode === "air") { g.hover = false; g.jump = true; } }
468
  if (g.fuel <= 0) { gas = 0; if (!g.fuelMsg) { g.fuelMsg = 1; say("Out of fuel! Coast to a ⛽ station (GPS has the nearest)", 5); } }
469
  else if (g.fuel < .15 && g.fuelMsg !== 2 && g.fuel > 0) { g.fuelMsg = 2; say("Low fuel: find a ⛽ station", 4); }
470
  if (g.fuel > .2) g.fuelMsg = 0;
 
543
  const gr = groundAt(g.x, g.z, g.y), prevY = g.y;
544
  if (gr.water) { splash(); return; }
545
  if (gr.ramp) {
546
+ g.y = gr.h; g.pitch = Math.atan(gr.ramp.slope) * Math.cos(g.yaw - gr.ramp.r.yaw); g.tRoll = gr.ramp.side ? -Math.atan(gr.ramp.side) * Math.cos(g.yaw - gr.ramp.r.yaw) : 0;
547
  // off the lip fast and you fly
548
  if (gr.ramp.a > gr.ramp.r.len - .8 && u > 8 && Math.cos(g.yaw - gr.ramp.r.yaw) > .6) {
549
  const th = Math.atan(gr.ramp.slope); g.mode = "air"; g.hover = false; g.vel.y = Math.sin(th) * u; g.vel.x *= Math.cos(th); g.vel.z *= Math.cos(th); g.airT = 0; g.jump = true; return;
 
554
  g.pitch = lerp(g.pitch, Math.atan(sa) + g.sp, clamp(dt * 12)); if (Math.abs(u) > 6 && Math.random() < .08) g.spV += (Math.random() - .5) * Math.abs(u) * .02 / Math.max(.6, OR); // bumps
555
  if (Math.abs(u) > 4) g.shake = Math.max(g.shake || 0, Math.min(.22, Math.abs(u) * .004 / Math.max(.6, OR))); // rough ground rattles you, less in a truck
556
  }
557
+ else if (gr.tunnel) { g.y = gr.h; g.pitch = lerp(g.pitch, Math.atan((gr.slopeX || 0) * Math.cos(g.yaw)) + g.sp, clamp(dt * 12)); g.tRoll = -Math.atan(gr.side || 0) * Math.cos(g.yaw); }
558
  else { g.y = gr.h; g.pitch = g.sp; }
559
+ if (gr.tunnel) { const b = g.z - gr.tunnel.z, lim = gr.tunnel.half - 1.2; if (Math.abs(b) > lim) { g.z = gr.tunnel.z + Math.sign(b) * lim; if (g.vel.z * Math.sign(b) > 0) { if (Math.abs(g.vel.z) > 6) { g.sparks = 1; sound.thud && sound.thud(Math.abs(g.vel.z) / 14); } g.vel.z *= -.2; } } }
560
+ g.onTerrain = !!gr.terrain; if (!gr.terrain) { g.slope = 0; if (!(gr.ramp && gr.ramp.side) && !gr.tunnel) g.tRoll = 0; }
561
+ // the Sky Park loop
562
+ if (Math.abs(g.x - LOOP2.x) < 1.2 && Math.abs(g.z - LOOP2.z) < 3 && Math.cos(g.yaw) > .85 && u > 12 && g.y < .3) { g.mode = "loop2"; g.lp = 0; g.v = u; return; }
563
  // drive into the loop and the track takes you round
564
  if (g.x > LOOP_X - 1.5 && g.x < LOOP_X + .5 && Math.abs(g.z) < HW && Math.cos(g.yaw) > .8 && u > 3 && g.y < .2) { g.mode = "rail"; g.d = T.D[T.loopIn]; g.v = u; return; }
565
  traffic(dt);
 
571
  return;
572
  }
573
 
574
+ if (g.mode === "loop2") {
575
+ const L2 = LOOP2, th = g.lp; g.v = clamp(g.v + ((gas ? 10 * (1 - g.v / 92) : 0) + g.nitroOn * 10 - (brake ? 16 : 0) - .4 - G * Math.sin(th)) * dt, 0, 112);
576
+ g.lp += g.v / L2.R * dt; const n = g.v * g.v / L2.R + G * Math.cos(th); g.gForce = n / G;
577
+ g.x = L2.x + L2.R * Math.sin(g.lp); g.y = L2.R * (1 - Math.cos(g.lp)); g.z = L2.z + L2.shift * g.lp / (2 * Math.PI);
578
+ if (n < 0 || g.v < .5) { g.mode = "air"; g.hover = false; g.jump = true; g.airT = 0; g.vel.set(Math.cos(g.lp) * g.v, Math.sin(g.lp) * g.v, 0); g.yaw = 0; g.pitch = 0; say("Too slow for the loop!", 2); return; }
579
+ if (g.lp >= 2 * Math.PI) { g.mode = "drive"; g.y = 0; g.yaw = 0; g.pitch = 0; g.roll = 0; g.x = L2.x; g.z = L2.z + L2.shift; g.vel.set(g.v, 0, 0); addScore(800, "Full loop (Sky Park)"); }
580
+ return;
581
+ }
582
  if (g.mode === "rail") {
583
  T.sample(g.d, fr);
584
  g.v = clamp(g.v + ((gas ? 10 * (1 - g.v / 92) : 0) + g.nitroOn * 10 - (brake ? 16 : 0) - .4 - G * fr.f.y) * dt, 0, 112);
 
698
  if (gr.water) { splash(); return; }
699
  g.y = gr.h;
700
  landTricks();
701
+ let down2 = -g.vel.y; const vh2 = Math.hypot(g.vel.x, g.vel.z), angle = Math.atan2(down2, Math.max(.1, vh2));
702
+ if (gr.ramp && gr.ramp.r.land) down2 = Math.min(down2, 4); // the landing slope takes the drop
703
  if (down2 > 12) impact(g.x, g.y, g.z, down2 * 1.2);
704
  if (down2 > 26 || (down2 > 15 && angle > 1.1)) { hurt(down2 * 3, `Hit the ground hard (${down2.toFixed(1)} m/s down)`); if (g.wreck > 0) return; }
705
  else if (down2 > 10) hurt((down2 - 10) * 1.5, "Hard landing");
706
  else if (g.airT > 2 && !g.jump) { if (down2 < 2) addScore(300, "Butter landing!"); else if (down2 < 4.5) addScore(150, "Smooth landing"); else say(`Firm landing (${down2.toFixed(1)} m/s)`, 2); }
707
  const zone = ZONES.find(z => Math.hypot(g.x - z.x, g.z - z.z) < (z.r || PAD_R) && Math.abs(g.y - (z.y || 0)) < 3);
708
+ if (opts.onLand) opts.onLand(g, down2);
709
  if (zone && !g.done.has(zone.id)) { g.done.add(zone.id); if (zone.safe) addScore(1000 + Math.round(Math.max(0, 7 - down2) * 60) + (zone.y ? 500 : 0), `Landed at ${zone.id}`); else say(`${zone.id} is unsafe: ${zone.note}`); }
710
  if (g.jump && g.airT > 1.2) addScore(Math.round(g.airT * 120), `Airtime ${g.airT.toFixed(1)} s`);
711
  // keep the kinetic energy: the drop's speed carries into the roll along the ground
 
768
  busted(msg) { say(msg, 4); g.hp = 100; g.vel.set(0, 0, 0); $("gScore").textContent = "$" + g.score.toLocaleString(); sound.crash(); },
769
  // the VOID car: locked until bought (or the secret code); then you're put straight into it
770
  useHero() { if (!g || !g.started) return; if (g.veh === "foot") Object.assign(g, { veh: "car", mode: "drive" }); if (g.ride) { if (g.ride.c) life.park(g.ride.c, g.x, g.z, g.yaw); g.ride = null; } g.heroPark = null; g.vel.set(0, 0, 0); rig.yaw = null; say("Your VOID car: 330 km/h and it flies (F)", 3); },
771
+ freeze(t) { g.frozen = t; }, emp(t) { if (!g) return; g.emp = Math.max(g.emp || 0, t); g.shake = 1; say("⚡ EMP! Engine down", 1.6); sound.crash(); }, teleport(x, z, yaw) { Object.assign(g, { x, z, y: 0, yaw, mode: "drive", pitch: 0, roll: 0, wings: 0 }); g.vel.set(0, 0, 0); camPos.set(x - Math.cos(yaw) * 8, 3, z - Math.sin(yaw) * 8); rig.yaw = yaw; orbit.yaw = orbit.pitch = 0; },
772
  hitBox, isWater: (x, z) => city.isWater(x, z), impact: (x, z, p) => impact(x, .6, z, p),
773
  groundAt: (x, z, y) => groundAt(x, z, y), wreck: why => wreck(why), setVehicle: t => setVehicle(t), setStick: (x, y) => { stick.x = x; stick.y = y; }, nearCars: (x, z, r) => life ? life.nearCars(x, z, r) : [], fly: () => { if (g.mode === "drive") toggleFly(); },
774
  policeClear: () => opts.policeClear && opts.policeClear(), terrainH: (x, z) => city.terrainH ? city.terrainH(x, z) : 0, board: () => boardToggle(),
 
782
  },
783
  };
784
  return {
785
+ api, RINGS, RAILS, RAMPS, LOOP2,
786
  get state() { return g; }, get photo() { return photo; },
787
  enter() { active = true; start(); },
788
  exit() { active = false; keys.clear(); touch.clear(); sound.setGame("off"); if (photo) togglePhoto(); },
 
791
  if (!g) start();
792
  pollPad();
793
  if (g.started && !paused && !photo) { acc += dt; const H = 1 / 60; let n = 0; while (acc >= H && n < 6) { step(H); acc -= H; n++; } }
794
+ const air = g.mode === "air", speed = g.mode === "rail" || g.mode === "loop2" ? g.v * 3.6 : g.vel.length() * 3.6;
795
  if (g.mode === "rail") { basis.makeBasis(fr.f, fr.u, fr.s); q.setFromRotationMatrix(basis); }
796
+ else if (g.mode === "loop2") { const th = g.lp; fr.f.set(Math.cos(th), Math.sin(th), LOOP2.shift / (2 * Math.PI * LOOP2.R)).normalize(); fr.u.set(-Math.sin(th), Math.cos(th), 0); fr.s.crossVectors(fr.f, fr.u).normalize(); fr.u.crossVectors(fr.s, fr.f); basis.makeBasis(fr.f, fr.u, fr.s); q.setFromRotationMatrix(basis); }
797
  else {
798
  const f = new THREE.Vector3(Math.cos(g.yaw) * Math.cos(g.pitch), Math.sin(g.pitch), Math.sin(g.yaw) * Math.cos(g.pitch));
799
  const s0 = new THREE.Vector3().crossVectors(f, UP).normalize(), u0 = new THREE.Vector3().crossVectors(s0, f);
 
805
  car.group.position.copy(fr.p); car.group.quaternion.copy(q); car.group.updateMatrixWorld(true);
806
  let cam;
807
  if (orbit.t > 0) orbit.t -= dt;
808
+ const sp0 = g.mode === "rail" || g.mode === "loop2" ? g.v : g.vel.length();
809
  // like GTA: once you stop moving the mouse (or finger) for a moment and the car is moving, the view eases back behind it
810
  if (orbit.t <= 1.5 && !photo && sp0 > 3 && !orbit.drag && g.veh !== "foot") { const k = clamp(dt * 1.6); orbit.yaw = lerp(orbit.yaw, 0, k); orbit.pitch = lerp(orbit.pitch, 0, k); }
811
  const nitroFov = g.nitroOn * 9;
 
817
  else {
818
  let up = UP.clone();
819
  if (g.mode === "rail") { T.sample(Math.max(T.D[T.loopIn] - 6, g.d - 7.5), back); camPos.copy(loc(back, 0, 2.4, 0)); camLook.copy(loc(fr, 5, .8, 0)); up = back.u.clone(); }
820
+ else if (g.mode === "loop2") { camPos.copy(fr.p).addScaledVector(fr.f, -8).addScaledVector(fr.u, 3); camLook.copy(fr.p).addScaledVector(fr.f, 5); up = fr.u.clone(); }
821
  else {
822
  // an orbit rig round the car: only the angles are smoothed, so the camera never lags behind at speed, never
823
  // cuts through the car when you look round, and never swings in front when you reverse
 
833
  const want = g.veh === "foot" ? 3.4 + (orbit.dist || 0) * .6 : g.veh === "board" ? 4.4 + speed * .015 + (orbit.dist || 0) * .6 : lerp(6.6 + speed * .012, 12 + speed * .01, A) + (orbit.dist || 0) + (g.veh === "plane" || g.veh === "heli" ? 6 : g.veh === "boat" ? 2 : 0);
834
  const pivot = fr.p.clone().add(new THREE.Vector3(0, g.veh === "foot" ? 1.55 : g.veh === "board" ? 1.9 : 1.3 + .1 * A, 0)), dir = new THREE.Vector3(-Math.cos(yawC) * Math.cos(pitC), Math.sin(pitC), -Math.sin(yawC) * Math.cos(pitC));
835
  // walls: pull in at once, ease back out
836
+ const tun = g.y < -1.5 && opts.tunnel ? opts.tunnel(g.x, g.z, g.y) : null, floorY = tun ? g.y : 0, ceilY = tun && tun.ceil != null ? tun.ceil : 1e9;
837
+ let room = want; for (let t = .8; t <= want; t += .5) { const q2 = pivot.clone().addScaledVector(dir, t); if (q2.y < floorY + .3 || q2.y > ceilY - .7 || hitBox(q2.x, q2.z, q2.y, .35) || (tun && Math.abs(q2.z - tun.tunnel.z) > tun.tunnel.half - .6)) { room = Math.max(1.6, t - .6); break; } }
838
  rig.dist = room < rig.dist ? room : lerp(rig.dist, room, clamp(dt * 2.5));
839
  camPos.copy(pivot).addScaledVector(dir, rig.dist);
840
  camLook.copy(pivot).add(new THREE.Vector3(fx, 0, fz).multiplyScalar(1.5 + 1.5 * A));
841
  if (A > .01) up.lerp(fr.u, .15 * A).normalize();
842
+ if (camPos.y < floorY + .4) camPos.y = floorY + .4;
843
  }
844
  cam = { pos: camPos.clone(), look: camLook.clone(), up, fov: lerp(56, 68, clamp(speed / 330)) + nitroFov };
845
  }
static/legion.js CHANGED
@@ -1,186 +1,303 @@
1
- // New Legion: the layer on top of the game that makes the first minute click and keeps every minute after it
2
- // worth playing. Three keys to start and the neon launch ramp, key hints that turn up when you need them, the GPS
3
- // beam and arrow, drift trails, the sonic boom and the cloud deck, smashable street props, smoke and fireballs when
4
- // traffic falls out of the sky, score pops, and the city's light columns only where they help.
5
- import * as THREE from "three";
6
- import { RAMP_X, LZ } from "./world.js";
7
-
8
- export function createLegion(o) {
9
- const { W, game, sound, store, life, COARSE } = o, scene = W.scene, city = W.city, fx = W.fx, $ = id => document.getElementById(id);
10
- const add = m => { scene.add(m); return m; };
11
- const puff = (x, y, z, vx, vy, vz, col, size, life = 1) => { const pf = fx.puffs[fx.puffI++ % fx.puffs.length]; pf.s.position.set(x, y, z); pf.life = life; pf.s.visible = true; pf.s.scale.setScalar(size); pf.grow = size; pf.s.material.color.set(col); pf.v.set(vx, vy, vz); };
12
- const rnd = () => Math.random() - .5;
13
-
14
- // ---- score pops: the big moments get a word in the middle of the screen ----
15
- const popEl = $("gPop"); let popAt = 0;
16
- function pop(text, cls = "") { if (!popEl || performance.now() - popAt < 220) return; popAt = performance.now(); popEl.className = "g-pop"; popEl.textContent = text; void popEl.offsetWidth; popEl.className = "g-pop on " + cls; }
17
- function onScore(why, pts) {
18
- if (/^NEAR MISS/.test(why)) pop(`${why} +$${pts}`);
19
- else if (/SONIC BOOM/.test(why)) pop(`💥 SONIC BOOM +$${pts}`, "hot");
20
- else if (/SKY CHAIN/.test(why)) pop(`⚡ SKY CHAIN +$${pts.toLocaleString()}`, "gold");
21
- else if (/^⚡ Sky boost/.test(why)) pop(why);
22
- else if (/^Drift ×/.test(why)) pop(`${why.toUpperCase()} +$${pts.toLocaleString()}`, "hot");
23
- else if (/^Full loop|^Landed at|^Butter landing|Above the clouds/.test(why)) pop(why.toUpperCase(), "gold");
24
- }
25
-
26
- // ---- light columns (race starts, VOID Motors, helipad beacons): only near enough to matter, never right on top of you,
27
- // and the tall helipad beacons only while you fly. A render layer is switched, so the modules' own show/hide still works ----
28
- const columns = [];
29
- scene.traverse(m => { const P = m.isMesh && m.geometry.type === "CylinderGeometry" && m.geometry.parameters; if (!P || !P.openEnded || ![260, 80, 60, 34].includes(P.height)) return; m.updateMatrixWorld(); columns.push({ m, sky: P.height === 260, far: P.height === 80 ? 700 : 350, p: new THREE.Vector3().setFromMatrixPosition(m.matrixWorld) }); });
30
- let colT = 0;
31
- function columnsUpdate(dt, cam, air) {
32
- if ((colT -= dt) > 0) return; colT = .25;
33
- for (const c of columns) { if (c.m.parent !== scene) c.p.setFromMatrixPosition(c.m.matrixWorld); const d = c.p.distanceTo(cam); c.m.layers.set((c.sky ? air && d < 2500 : d > 28 && d < c.far) ? 0 : 30); }
34
- }
35
-
36
- // ---- traffic in the sky: a smoke trail on the way down, a fireball where it lands (or where two collide) ----
37
- life.onSmoke = (x, y, z) => puff(x, y, z, rnd(), 1 + Math.random(), rnd(), 0x2b2b2b, 1.3, 1.3);
38
- life.onBoom = (x, z, power, y = 0) => {
39
- for (let k = 0; k < 36; k++) puff(x + rnd() * 3, y + 1 + Math.random() * 2, z + rnd() * 3, rnd() * 16, 3 + Math.random() * 12, rnd() * 16, k % 3 ? 0xff7a1a : k % 2 ? 0xffd23d : 0x222222, 1.6 + Math.random(), 1.4);
40
- const s = game.state; if (!s) return; const d = Math.hypot(x - s.x, z - s.z);
41
- if (d < 420) { sound.crash(); if (d < 140) s.shake = Math.min(1, (s.shake || 0) + .5 * (1 - d / 140)); }
42
- };
43
-
44
- // ---- the GPS: a light column on the destination and a floating arrow just ahead of the car pointing the way ----
45
- const beamMat = new THREE.MeshBasicMaterial({ color: new THREE.Color(0x3dfcff).multiplyScalar(1.5), transparent: true, opacity: .2, blending: THREE.AdditiveBlending, depthWrite: false, toneMapped: false, side: THREE.DoubleSide });
46
- const beam = add(new THREE.Mesh(new THREE.CylinderGeometry(1.8, 1.8, 420, 18, 1, true).translate(0, 210, 0), beamMat)), pad = add(new THREE.Mesh(new THREE.RingGeometry(5, 6.4, 40).rotateX(-Math.PI / 2), beamMat));
47
- const chevGeo = new THREE.ShapeGeometry(new THREE.Shape([[0, 1.1], [1, -.45], [.5, -.45], [0, .25], [-.5, -.45], [-1, -.45]].map(([x, y]) => new THREE.Vector2(x, y)))).rotateX(-Math.PI / 2).rotateY(-Math.PI / 2);
48
- const chev = add(new THREE.Mesh(chevGeo, new THREE.MeshBasicMaterial({ color: new THREE.Color(0x3dfcff).multiplyScalar(1.8), transparent: true, opacity: .9, toneMapped: false, side: THREE.DoubleSide, depthWrite: false })));
49
- beam.visible = pad.visible = chev.visible = false;
50
- function gpsUpdate(time, s) {
51
- const R = o.races && o.races(), race = R && R.race && R.race.next, nav = o.nav && o.nav(), dest = nav && nav.dest, pts = nav ? nav.pts : [];
52
- let tx = null, tz = null;
53
- if (race) { tx = race[0]; tz = race[2]; }
54
- else if (dest) {
55
- tx = dest.x; tz = dest.z;
56
- if (pts.length > 1) { let best = 0, bd = 1e9; pts.forEach(([x, z], i) => { const d = Math.hypot(x - s.x, z - s.z); if (d < bd) { bd = d; best = i; } }); for (let i = best; i < pts.length; i++) { const [x, z] = pts[i]; if (Math.hypot(x - s.x, z - s.z) > 25) { tx = x; tz = z; break; } } }
57
- }
58
- beam.visible = pad.visible = !!dest && Math.hypot(dest.x - s.x, dest.z - s.z) > 12;
59
- if (beam.visible) { const gy = Math.max(0, dest.y || 0); beam.position.set(dest.x, gy, dest.z); pad.position.set(dest.x, gy + .15, dest.z); pad.scale.setScalar(1 + .12 * Math.sin(time * 4)); beamMat.opacity = .13 + .07 * Math.sin(time * 3); }
60
- chev.visible = tx != null && s.veh !== "foot" && Math.hypot(tx - s.x, tz - s.z) > 14;
61
- if (chev.visible) { const f = s.veh === "board" ? 4 : 7; chev.position.set(s.x + Math.cos(s.yaw) * f, s.y + 2.3 + Math.sin(time * 5) * .12, s.z + Math.sin(s.yaw) * f); chev.rotation.y = -Math.atan2(tz - s.z, tx - s.x); }
62
- }
63
-
64
- // ---- drift trails: two neon ribbons from the rear tyres while the car slides, fading over four seconds ----
65
- const TQ = 320, tPos = new Float32Array(TQ * 18), tCol = new Float32Array(TQ * 18), tAge = new Float32Array(TQ).fill(99), tBase = new Float32Array(TQ * 3);
66
- const tGeo = new THREE.BufferGeometry(); tGeo.setAttribute("position", new THREE.BufferAttribute(tPos, 3).setUsage(THREE.DynamicDrawUsage)); tGeo.setAttribute("color", new THREE.BufferAttribute(tCol, 3).setUsage(THREE.DynamicDrawUsage));
67
- const trail = add(new THREE.Mesh(tGeo, new THREE.MeshBasicMaterial({ vertexColors: true, transparent: true, blending: THREE.AdditiveBlending, depthWrite: false, toneMapped: false, side: THREE.DoubleSide, polygonOffset: true, polygonOffsetFactor: -4, polygonOffsetUnits: -4 })));
68
- trail.frustumCulled = false; let tq = 0, tLive = 0; const lastW = [null, null];
69
- function trailsUpdate(dt, s, S) {
70
- const on = S.slip > .35 && s.mode === "drive" && s.veh === "car" && s.y < .5, fx0 = Math.cos(s.yaw), fz0 = Math.sin(s.yaw), col = o.trailColor ? o.trailColor() : [1, .2, .85];
71
- for (let w = 0; w < 2; w++) {
72
- const sd = w ? .8 : -.8, x = s.x - fx0 * 1.35 - fz0 * sd, z = s.z - fz0 * 1.35 + fx0 * sd;
73
- if (!on) { lastW[w] = null; continue; }
74
- if (Math.random() < .35) puff(x, .3, z, rnd(), .8, rnd(), 0xd8d8dc, .5, .9);
75
- const L = lastW[w]; if (L && Math.hypot(x - L[0], z - L[1]) < .45) continue;
76
- if (L && Math.hypot(x - L[0], z - L[1]) < 6) {
77
- const dx = x - L[0], dz = z - L[1], len = Math.hypot(dx, dz), nx = -dz / len * .16, nz = dx / len * .16, q = tq++ % TQ;
78
- tPos.set([L[0] + nx, .05, L[1] + nz, L[0] - nx, .05, L[1] - nz, x - nx, .05, z - nz, L[0] + nx, .05, L[1] + nz, x - nx, .05, z - nz, x + nx, .05, z + nz], q * 18);
79
- tAge[q] = 0; tBase.set(col, q * 3); tLive = 4.2;
80
- }
81
- lastW[w] = [x, z];
82
- }
83
- if (tLive <= 0) return; tLive -= dt;
84
- for (let q = 0; q < TQ; q++) {
85
- if (tAge[q] > 4) { if (tAge[q] < 90) { tAge[q] = 99; tCol.fill(0, q * 18, q * 18 + 18); } continue; }
86
- tAge[q] += dt; const k = Math.max(0, 1 - tAge[q] / 4) * .9;
87
- for (let i = 0; i < 6; i++) { const b = q * 18 + i * 3; tCol[b] = tBase[q * 3] * k; tCol[b + 1] = tBase[q * 3 + 1] * k; tCol[b + 2] = tBase[q * 3 + 2] * k; }
88
- }
89
- tGeo.attributes.position.needsUpdate = tGeo.attributes.color.needsUpdate = true;
90
- }
91
-
92
- // ---- the sonic boom (a shockwave ring round the car) and the cloud deck high over the city ----
93
- const shockMat = new THREE.MeshBasicMaterial({ color: 0xffffff, transparent: true, opacity: 0, blending: THREE.AdditiveBlending, depthWrite: false, toneMapped: false, side: THREE.DoubleSide });
94
- const shock = add(new THREE.Mesh(new THREE.RingGeometry(.86, 1, 56), shockMat)); shock.visible = false; let shockT = 0;
95
- const cloudTex = (() => { const c = document.createElement("canvas"); c.width = c.height = 64; const g = c.getContext("2d"), r = g.createRadialGradient(32, 32, 2, 32, 32, 32); r.addColorStop(0, "rgba(255,255,255,.9)"); r.addColorStop(.5, "rgba(255,255,255,.35)"); r.addColorStop(1, "rgba(255,255,255,0)"); g.fillStyle = r; g.fillRect(0, 0, 64, 64); return new THREE.CanvasTexture(c); })();
96
- const NCL = COARSE ? 260 : 620, cp = new Float32Array(NCL * 3);
97
- for (let i = 0; i < NCL; i++) cp.set([-1600 + Math.random() * 4400, 405 + Math.random() * 55, -1300 + Math.random() * 3800], i * 3);
98
- const cGeo = new THREE.BufferGeometry(); cGeo.setAttribute("position", new THREE.BufferAttribute(cp, 3));
99
- const cloudMat = new THREE.PointsMaterial({ map: cloudTex, size: 150, sizeAttenuation: true, transparent: true, opacity: 0, depthWrite: false, color: 0xe4eaf4, fog: false });
100
- const clouds = add(new THREE.Points(cGeo, cloudMat)); clouds.frustumCulled = false; let aboveDone = false;
101
-
102
- // ---- smashable street props: lamps, hydrants, bins, benches, cones and barriers fly off the car (no speed lost) ----
103
- const DEB = { lamp: [new THREE.CylinderGeometry(.1, .14, 8, 6), 0x22252b, 4], hydrant: [new THREE.CylinderGeometry(.22, .26, .8, 8), 0xc8202a, .4], bin: [new THREE.CylinderGeometry(.35, .3, 1, 8), 0x2d4a2d, .5],
104
- bench: [new THREE.BoxGeometry(1.8, .5, .6), 0x4a3a2a, .3], cone: [new THREE.ConeGeometry(.24, .72, 10), 0xff5a12, .36], barrier: [new THREE.BoxGeometry(.12, .5, 2.4), 0xe8e8e8, .5] };
105
- const debMat = {}; for (const k in DEB) debMat[k] = new THREE.MeshStandardMaterial({ color: DEB[k][1], roughness: .6 });
106
- const debris = [], downs = []; let smashN = 0, smashCash = 0, smashT = 0;
107
- function props(x, z, y, vel) {
108
- const sp = Math.hypot(vel.x, vel.z); if (y > 4 || sp < 4 || !city.props) return;
109
- for (const q of city.props.near(x, z, 1.7)) {
110
- city.props.hide(q); downs.push({ q, t: 50 });
111
- const [geo, , hh] = DEB[q.kind] || DEB.bin;
112
- let d = debris.find(e => !e.m.visible && e.kind === q.kind);
113
- if (!d && debris.length >= 36) d = debris.find(e => e.kind === q.kind);
114
- if (!d) { d = { m: add(new THREE.Mesh(geo, debMat[q.kind] || debMat.bin)), kind: q.kind, v: new THREE.Vector3(), w: new THREE.Vector3() }; d.m.castShadow = true; debris.push(d); }
115
- d.m.visible = true; d.m.scale.setScalar(1); d.t = 7; d.hh = hh; d.m.position.set(q.x, hh, q.z); d.m.rotation.set(0, Math.random() * 6, 0);
116
- d.v.set(vel.x * .9 + rnd() * 4, 3 + sp * .18 + Math.random() * 3, vel.z * .9 + rnd() * 4); d.w.set(rnd() * 10, rnd() * 6, rnd() * 10);
117
- for (let k = 0; k < 5; k++) puff(q.x, .6, q.z, rnd() * 6, 1 + Math.random() * 3, rnd() * 6, q.kind === "lamp" ? 0xffd27a : 0xb0b0b0, .25, .5);
118
- smashN++; smashCash += q.kind === "lamp" ? 40 : q.kind === "barrier" ? 25 : 15; smashT = .7; sound.thud && sound.thud(.45);
119
- }
120
- }
121
- function debrisUpdate(dt, cam) {
122
- for (const d of debris) if (d.m.visible) {
123
- d.t -= dt; d.v.y -= 9.81 * dt; d.m.position.addScaledVector(d.v, dt); d.m.rotation.x += d.w.x * dt; d.m.rotation.y += d.w.y * dt; d.m.rotation.z += d.w.z * dt;
124
- if (d.m.position.y < d.hh * .35) { d.m.position.y = d.hh * .35; d.v.y = Math.abs(d.v.y) * .3; d.v.x *= .6; d.v.z *= .6; d.w.multiplyScalar(.6); }
125
- if (d.t < 1) d.m.scale.setScalar(Math.max(.01, d.t)); if (d.t <= 0) d.m.visible = false;
126
- }
127
- for (let i = downs.length - 1; i >= 0; i--) { const D = downs[i]; if ((D.t -= dt) <= 0 && Math.hypot(D.q.x - cam.x, D.q.z - cam.z) > 80) { city.props.restore(D.q); downs.splice(i, 1); } }
128
- if (smashT > 0 && (smashT -= dt) <= 0 && smashN) { game.api.addScore(smashCash, smashN > 1 ? `Smashed ${smashN} props` : "Smashed a prop"); smashN = smashCash = 0; }
129
- }
130
-
131
- // ---- the first minute: the neon launch ramp ahead of the spawn (a ring over the jump and chevrons leading in) ----
132
- {
133
- const neon = new THREE.MeshBasicMaterial({ color: new THREE.Color(0xff3df0).multiplyScalar(2.2), toneMapped: false });
134
- const ring = add(new THREE.Mesh(new THREE.TorusGeometry(9, .7, 10, 44), neon)); ring.position.set(RAMP_X + 46, 20, LZ); ring.rotation.y = Math.PI / 2;
135
- game.RINGS.push({ m: ring, x: RAMP_X + 46, y: 20, z: LZ, nx: 1, nz: 0, done: 0, side: 0 });
136
- const chevMat = new THREE.MeshBasicMaterial({ color: new THREE.Color(0xff3df0).multiplyScalar(1.6), toneMapped: false, transparent: true, opacity: .85, depthWrite: false, polygonOffset: true, polygonOffsetFactor: -4, polygonOffsetUnits: -4 });
137
- for (const x of [RAMP_X - 70, RAMP_X - 45, RAMP_X - 20]) { const c = add(new THREE.Mesh(chevGeo, chevMat)); c.scale.setScalar(1.6); c.position.set(x, .07, LZ); }
138
- }
139
-
140
- // ---- key hints: each turns up once, the first time it's useful (the start screen only shows WASD, Shift and F) ----
141
- const seen = new Set(store.get("void.hints") || []), hintEl = $("gKeyHint"); let hintOn = null, hintT = 0, chk = 0, played = 0, stillT = 0, stuckT = 0, flyT = 0;
142
- const K = k => COARSE ? "" : `<kbd>${k}</kbd>`;
143
- function hint(id, html, t = 7) { if (seen.has(id) || hintOn || !hintEl) return; seen.add(id); store.set("void.hints", [...seen]); hintOn = id; hintT = t; hintEl.innerHTML = html; hintEl.hidden = false; sound.pop && sound.pop(); }
144
- const railDist = (x, z) => { let best = 1e9; for (const r of game.RAILS) { const a = Math.max(0, Math.min(r.len, (x - r.x) * r.c + (z - r.z) * r.s)); best = Math.min(best, Math.hypot(x - (r.x + r.c * a), z - (r.z + r.s * a))); } return best; };
145
- function hints(dt, s, S) {
146
- if (hintOn && (hintT -= dt) <= 0) { hintOn = null; hintEl.hidden = true; }
147
- played += dt; const sp = Math.hypot(s.vel.x, s.vel.z);
148
- stillT = s.veh === "car" && sp < 1 ? stillT + dt : 0;
149
- stuckT = s.veh === "car" && sp < 1.5 && s.brakeIn === 0 && S.load > .5 ? stuckT + dt : 0;
150
- flyT = s.mode === "air" && s.veh === "car" ? flyT + dt : 0;
151
- if (s.mode === "air" && s.veh === "car" && s.hover && !store.get("void.flew")) store.set("void.flew", 1);
152
- // the launch ramp: until you've flown once
153
- if (!store.get("void.flew") && s.mode === "drive" && s.veh === "car" && Math.cos(s.yaw) > .7 && s.x > RAMP_X - 160 && s.x < RAMP_X && Math.abs(s.z - LZ) < 10) game.api.say(COARSE ? "🚀 Hit the ramp, then tap Fly in mid-air!" : "🚀 Hit the ramp & press F in mid-air to fly!", .6);
154
- if ((chk -= dt) > 0) return; chk = .5;
155
- if (flyT > 5) hint("land", `${K("L")} Land: the car glides down and touches down softly${COARSE ? " (tap Land)" : ""}`);
156
- if (S.nitroFull && played > 40) hint("od", `Tap ${K("Shift")} for a kick · hold it from full for ⚡ OVERDRIVE`);
157
- if (stuckT > 2.5) hint("reset", `${K("R")} Stuck? Back on your wheels right here${COARSE ? " (↺)" : ""}`);
158
- if ((s.veh === "foot" || sp < 9) && railDist(s.x, s.z) < 35) hint("board", COARSE ? "🛹 Hoverboard (Menu ☰ → Vehicle): grind these rails" : `${K("Y")} Hoverboard: grind these rails, ollie with Space`);
159
- if (played > 50 && stillT > 4) hint("foot", COARSE ? "🚶 Get out and walk · take any car" : `${K("E")} Get out and walk · take any car`);
160
- if (o.dealer && o.dealer() && o.dealer().sites.some(st => Math.hypot(st.x - s.x, st.z - s.z) < 45)) hint("garage", `${K("G")} VOID Motors: your garage, every car is yours`);
161
- if (played > 120 && stillT > 3 && Math.abs(s.x) < 1000 && s.z > -700 && s.z < 2100) hint("taxi", COARSE ? "🚕 Taxi jobs (Menu ☰): passengers pay cash" : `${K("J")} Taxi jobs: passengers pay cash`);
162
- if (played > 90) hint("radio", COARSE ? "📻 Change the station: Menu ☰ → Radio" : `${K("U")} Change the radio station`);
163
- if (played > 360) hint("route", COARSE ? "🏁 Build your own race (Menu ☰ → Routes)" : `${K("B")} Build your own race route and race your ghost`);
164
- }
165
- addEventListener("keydown", e => { if (e.code === "KeyU" && !e.repeat && game.api.active() && !/INPUT|TEXTAREA/.test(document.activeElement.tagName)) o.radioNext && o.radioNext(); });
166
-
167
- let odWas = false;
168
- return {
169
- props, pop, onScore,
170
- update(dt, time, S, cam) {
171
- const s = game.state; if (!s || !s.started) { columnsUpdate(dt, cam, false); return; }
172
- columnsUpdate(dt, cam, s.mode === "air");
173
- gpsUpdate(time, s); trailsUpdate(dt, s, S); debrisUpdate(dt, cam); hints(dt, s, S);
174
- const nos = $("gNos"); if (nos) { nos.classList.toggle("od", !!S.od); nos.classList.toggle("full", !!S.nitroFull && !S.od); }
175
- if (S.od && !odWas) pop("⚡ OVERDRIVE", "hot"); odWas = !!S.od;
176
- // the shockwave: a ring that bursts out across the flight path
177
- if (S.sonic > .95 && shockT <= 0) { shockT = .9; shock.position.copy(S.pos); shock.lookAt(S.pos.x + s.vel.x, S.pos.y + s.vel.y, S.pos.z + s.vel.z); shock.visible = true; for (let k = 0; k < 16; k++) puff(S.pos.x, S.pos.y, S.pos.z, rnd() * 30, rnd() * 30, rnd() * 30, 0xffffff, .8, .6); }
178
- if (shockT > 0) { shockT -= dt; const k = 1 - shockT / .9; shock.scale.setScalar(3 + k * 80); shockMat.opacity = (1 - k) * .55; if (shockT <= 0) shock.visible = false; }
179
- // the cloud deck fades in as you climb; above it pays once a flight
180
- cloudMat.opacity = Math.max(0, Math.min(1, (cam.y - 140) / 160)) * (W.timeOfDay === "night" ? .32 : .6);
181
- clouds.visible = cloudMat.opacity > .01;
182
- if (s.mode === "air" && s.y > 470 && !aboveDone) { aboveDone = true; game.api.addScore(300, "☁️ Above the clouds"); }
183
- if (s.mode !== "air") aboveDone = false;
184
- },
185
- };
186
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // New Legion: the layer on top of the game that makes the first minute click and keeps every minute after it
2
+ // worth playing. Three keys to start and the neon launch ramp, key hints that turn up when you need them, the GPS
3
+ // beam and arrow, drift trails, the sonic boom and the cloud deck, smashable street props, smoke and fireballs when
4
+ // traffic falls out of the sky, score pops, and the city's light columns only where they help. And the places: fifteen
5
+ // rooftop stunt pads, six neon paint shops that wipe your wanted level, the Sky Park's loop and boost pads, and the
6
+ // secret tunnel under the Hudson with a harbor at the far end.
7
+ import * as THREE from "three";
8
+ import { RAMP_X, LZ } from "./world.js";
9
+ import { GRID, TUNNEL } from "./city.js";
10
+
11
+ export function createLegion(o) {
12
+ const { W, game, sound, store, life, COARSE } = o, scene = W.scene, city = W.city, fx = W.fx, $ = id => document.getElementById(id);
13
+ const add = m => { scene.add(m); return m; };
14
+ const puff = (x, y, z, vx, vy, vz, col, size, life = 1) => { const pf = fx.puffs[fx.puffI++ % fx.puffs.length]; pf.s.position.set(x, y, z); pf.life = life; pf.s.visible = true; pf.s.scale.setScalar(size); pf.grow = size; pf.s.material.color.set(col); pf.v.set(vx, vy, vz); };
15
+ const rnd = () => Math.random() - .5;
16
+
17
+ // ---- score pops: the big moments get a word in the middle of the screen ----
18
+ const popEl = $("gPop"); let popAt = 0;
19
+ function pop(text, cls = "") { if (!popEl || performance.now() - popAt < 220) return; popAt = performance.now(); popEl.className = "g-pop"; popEl.textContent = text; void popEl.offsetWidth; popEl.className = "g-pop on " + cls; }
20
+ function onScore(why, pts) {
21
+ if (/^NEAR MISS/.test(why)) pop(`${why} +$${pts}`);
22
+ else if (/SONIC BOOM/.test(why)) pop(`💥 SONIC BOOM +$${pts}`, "hot");
23
+ else if (/SKY CHAIN/.test(why)) pop(`⚡ SKY CHAIN +$${pts.toLocaleString()}`, "gold");
24
+ else if (/^⚡ Sky boost/.test(why)) pop(why);
25
+ else if (/^Drift ×/.test(why)) pop(`${why.toUpperCase()} +$${pts.toLocaleString()}`, "hot");
26
+ else if (/^Full loop|^Landed at|^Butter landing|Above the clouds/.test(why)) pop(why.toUpperCase(), "gold");
27
+ }
28
+
29
+ // ---- light columns (race starts, VOID Motors, helipad beacons): only near enough to matter, never right on top of you,
30
+ // and the tall helipad beacons only while you fly. A render layer is switched, so the modules' own show/hide still works ----
31
+ const columns = [];
32
+ scene.traverse(m => { const P = m.isMesh && m.geometry.type === "CylinderGeometry" && m.geometry.parameters; if (!P || !P.openEnded || ![260, 80, 60, 34].includes(P.height)) return; m.updateMatrixWorld(); columns.push({ m, sky: P.height === 260, far: P.height === 80 ? 700 : 350, p: new THREE.Vector3().setFromMatrixPosition(m.matrixWorld) }); });
33
+ let colT = 0;
34
+ function columnsUpdate(dt, cam, air) {
35
+ if ((colT -= dt) > 0) return; colT = .25;
36
+ for (const c of columns) { if (c.m.parent !== scene) c.p.setFromMatrixPosition(c.m.matrixWorld); const d = c.p.distanceTo(cam); c.m.layers.set((c.sky ? air && d < 2500 : d > 28 && d < c.far) ? 0 : 30); }
37
+ }
38
+
39
+ // ---- traffic in the sky: a smoke trail on the way down, a fireball where it lands (or where two collide) ----
40
+ life.onSmoke = (x, y, z) => puff(x, y, z, rnd(), 1 + Math.random(), rnd(), 0x2b2b2b, 1.3, 1.3);
41
+ life.onBoom = (x, z, power, y = 0) => {
42
+ for (let k = 0; k < 36; k++) puff(x + rnd() * 3, y + 1 + Math.random() * 2, z + rnd() * 3, rnd() * 16, 3 + Math.random() * 12, rnd() * 16, k % 3 ? 0xff7a1a : k % 2 ? 0xffd23d : 0x222222, 1.6 + Math.random(), 1.4);
43
+ const s = game.state; if (!s) return; const d = Math.hypot(x - s.x, z - s.z);
44
+ if (d < 420) { sound.crash(); if (d < 140) s.shake = Math.min(1, (s.shake || 0) + .5 * (1 - d / 140)); }
45
+ };
46
+
47
+ // ---- the GPS: a light column on the destination and a floating arrow just ahead of the car pointing the way ----
48
+ const beamMat = new THREE.MeshBasicMaterial({ color: new THREE.Color(0x3dfcff).multiplyScalar(1.5), transparent: true, opacity: .2, blending: THREE.AdditiveBlending, depthWrite: false, toneMapped: false, side: THREE.DoubleSide });
49
+ const beam = add(new THREE.Mesh(new THREE.CylinderGeometry(1.8, 1.8, 420, 18, 1, true).translate(0, 210, 0), beamMat)), pad = add(new THREE.Mesh(new THREE.RingGeometry(5, 6.4, 40).rotateX(-Math.PI / 2), beamMat));
50
+ const chevGeo = new THREE.ShapeGeometry(new THREE.Shape([[0, 1.1], [1, -.45], [.5, -.45], [0, .25], [-.5, -.45], [-1, -.45]].map(([x, y]) => new THREE.Vector2(x, y)))).rotateX(-Math.PI / 2).rotateY(-Math.PI / 2);
51
+ const chev = add(new THREE.Mesh(chevGeo, new THREE.MeshBasicMaterial({ color: new THREE.Color(0x3dfcff).multiplyScalar(1.8), transparent: true, opacity: .9, toneMapped: false, side: THREE.DoubleSide, depthWrite: false })));
52
+ beam.visible = pad.visible = chev.visible = false;
53
+ function gpsUpdate(time, s) {
54
+ const R = o.races && o.races(), race = R && R.race && R.race.next, nav = o.nav && o.nav(), dest = nav && nav.dest, pts = nav ? nav.pts : [];
55
+ let tx = null, tz = null;
56
+ if (race) { tx = race[0]; tz = race[2]; }
57
+ else if (dest) {
58
+ tx = dest.x; tz = dest.z;
59
+ if (pts.length > 1) { let best = 0, bd = 1e9; pts.forEach(([x, z], i) => { const d = Math.hypot(x - s.x, z - s.z); if (d < bd) { bd = d; best = i; } }); for (let i = best; i < pts.length; i++) { const [x, z] = pts[i]; if (Math.hypot(x - s.x, z - s.z) > 25) { tx = x; tz = z; break; } } }
60
+ }
61
+ beam.visible = pad.visible = !!dest && Math.hypot(dest.x - s.x, dest.z - s.z) > 12;
62
+ if (beam.visible) { const gy = Math.max(0, dest.y || 0); beam.position.set(dest.x, gy, dest.z); pad.position.set(dest.x, gy + .15, dest.z); pad.scale.setScalar(1 + .12 * Math.sin(time * 4)); beamMat.opacity = .13 + .07 * Math.sin(time * 3); }
63
+ chev.visible = tx != null && s.veh !== "foot" && Math.hypot(tx - s.x, tz - s.z) > 14;
64
+ if (chev.visible) { const f = s.veh === "board" ? 4 : 7; chev.position.set(s.x + Math.cos(s.yaw) * f, s.y + 2.3 + Math.sin(time * 5) * .12, s.z + Math.sin(s.yaw) * f); chev.rotation.y = -Math.atan2(tz - s.z, tx - s.x); }
65
+ }
66
+
67
+ // ---- drift trails: two neon ribbons from the rear tyres while the car slides, fading over four seconds ----
68
+ const TQ = 320, tPos = new Float32Array(TQ * 18), tCol = new Float32Array(TQ * 18), tAge = new Float32Array(TQ).fill(99), tBase = new Float32Array(TQ * 3);
69
+ const tGeo = new THREE.BufferGeometry(); tGeo.setAttribute("position", new THREE.BufferAttribute(tPos, 3).setUsage(THREE.DynamicDrawUsage)); tGeo.setAttribute("color", new THREE.BufferAttribute(tCol, 3).setUsage(THREE.DynamicDrawUsage));
70
+ const trail = add(new THREE.Mesh(tGeo, new THREE.MeshBasicMaterial({ vertexColors: true, transparent: true, blending: THREE.AdditiveBlending, depthWrite: false, toneMapped: false, side: THREE.DoubleSide, polygonOffset: true, polygonOffsetFactor: -4, polygonOffsetUnits: -4 })));
71
+ trail.frustumCulled = false; let tq = 0, tLive = 0; const lastW = [null, null];
72
+ function trailsUpdate(dt, s, S) {
73
+ const on = S.slip > .35 && s.mode === "drive" && s.veh === "car" && s.y < .5, fx0 = Math.cos(s.yaw), fz0 = Math.sin(s.yaw), col = o.trailColor ? o.trailColor() : [1, .2, .85];
74
+ for (let w = 0; w < 2; w++) {
75
+ const sd = w ? .8 : -.8, x = s.x - fx0 * 1.35 - fz0 * sd, z = s.z - fz0 * 1.35 + fx0 * sd;
76
+ if (!on) { lastW[w] = null; continue; }
77
+ if (Math.random() < .35) puff(x, .3, z, rnd(), .8, rnd(), 0xd8d8dc, .5, .9);
78
+ const L = lastW[w]; if (L && Math.hypot(x - L[0], z - L[1]) < .45) continue;
79
+ if (L && Math.hypot(x - L[0], z - L[1]) < 6) {
80
+ const dx = x - L[0], dz = z - L[1], len = Math.hypot(dx, dz), nx = -dz / len * .16, nz = dx / len * .16, q = tq++ % TQ;
81
+ tPos.set([L[0] + nx, .05, L[1] + nz, L[0] - nx, .05, L[1] - nz, x - nx, .05, z - nz, L[0] + nx, .05, L[1] + nz, x - nx, .05, z - nz, x + nx, .05, z + nz], q * 18);
82
+ tAge[q] = 0; tBase.set(col, q * 3); tLive = 4.2;
83
+ }
84
+ lastW[w] = [x, z];
85
+ }
86
+ if (tLive <= 0) return; tLive -= dt;
87
+ for (let q = 0; q < TQ; q++) {
88
+ if (tAge[q] > 4) { if (tAge[q] < 90) { tAge[q] = 99; tCol.fill(0, q * 18, q * 18 + 18); } continue; }
89
+ tAge[q] += dt; const k = Math.max(0, 1 - tAge[q] / 4) * .9;
90
+ for (let i = 0; i < 6; i++) { const b = q * 18 + i * 3; tCol[b] = tBase[q * 3] * k; tCol[b + 1] = tBase[q * 3 + 1] * k; tCol[b + 2] = tBase[q * 3 + 2] * k; }
91
+ }
92
+ tGeo.attributes.position.needsUpdate = tGeo.attributes.color.needsUpdate = true;
93
+ }
94
+
95
+ // ---- the sonic boom (a shockwave ring round the car) and the cloud deck high over the city ----
96
+ const shockMat = new THREE.MeshBasicMaterial({ color: 0xffffff, transparent: true, opacity: 0, blending: THREE.AdditiveBlending, depthWrite: false, toneMapped: false, side: THREE.DoubleSide });
97
+ const shock = add(new THREE.Mesh(new THREE.RingGeometry(.86, 1, 56), shockMat)); shock.visible = false; let shockT = 0;
98
+ const cloudTex = (() => { const c = document.createElement("canvas"); c.width = c.height = 64; const g = c.getContext("2d"), r = g.createRadialGradient(32, 32, 2, 32, 32, 32); r.addColorStop(0, "rgba(255,255,255,.9)"); r.addColorStop(.5, "rgba(255,255,255,.35)"); r.addColorStop(1, "rgba(255,255,255,0)"); g.fillStyle = r; g.fillRect(0, 0, 64, 64); return new THREE.CanvasTexture(c); })();
99
+ const NCL = COARSE ? 260 : 620, cp = new Float32Array(NCL * 3);
100
+ for (let i = 0; i < NCL; i++) cp.set([-1600 + Math.random() * 4400, 405 + Math.random() * 55, -1300 + Math.random() * 3800], i * 3);
101
+ const cGeo = new THREE.BufferGeometry(); cGeo.setAttribute("position", new THREE.BufferAttribute(cp, 3));
102
+ const cloudMat = new THREE.PointsMaterial({ map: cloudTex, size: 150, sizeAttenuation: true, transparent: true, opacity: 0, depthWrite: false, color: 0xe4eaf4, fog: false });
103
+ const clouds = add(new THREE.Points(cGeo, cloudMat)); clouds.frustumCulled = false; let aboveDone = false;
104
+
105
+ // ---- smashable street props: lamps, hydrants, bins, benches, cones and barriers fly off the car (no speed lost) ----
106
+ const DEB = { lamp: [new THREE.CylinderGeometry(.1, .14, 8, 6), 0x22252b, 4], hydrant: [new THREE.CylinderGeometry(.22, .26, .8, 8), 0xc8202a, .4], bin: [new THREE.CylinderGeometry(.35, .3, 1, 8), 0x2d4a2d, .5],
107
+ bench: [new THREE.BoxGeometry(1.8, .5, .6), 0x4a3a2a, .3], cone: [new THREE.ConeGeometry(.24, .72, 10), 0xff5a12, .36], barrier: [new THREE.BoxGeometry(.12, .5, 2.4), 0xe8e8e8, .5] };
108
+ const debMat = {}; for (const k in DEB) debMat[k] = new THREE.MeshStandardMaterial({ color: DEB[k][1], roughness: .6 });
109
+ const debris = [], downs = []; let smashN = 0, smashCash = 0, smashT = 0;
110
+ function props(x, z, y, vel) {
111
+ const sp = Math.hypot(vel.x, vel.z); if (y > 4 || sp < 4 || !city.props) return;
112
+ for (const q of city.props.near(x, z, 1.7)) {
113
+ city.props.hide(q); downs.push({ q, t: 50 });
114
+ const [geo, , hh] = DEB[q.kind] || DEB.bin;
115
+ let d = debris.find(e => !e.m.visible && e.kind === q.kind);
116
+ if (!d && debris.length >= 36) d = debris.find(e => e.kind === q.kind);
117
+ if (!d) { d = { m: add(new THREE.Mesh(geo, debMat[q.kind] || debMat.bin)), kind: q.kind, v: new THREE.Vector3(), w: new THREE.Vector3() }; d.m.castShadow = true; debris.push(d); }
118
+ d.m.visible = true; d.m.scale.setScalar(1); d.t = 7; d.hh = hh; d.m.position.set(q.x, hh, q.z); d.m.rotation.set(0, Math.random() * 6, 0);
119
+ d.v.set(vel.x * .9 + rnd() * 4, 3 + sp * .18 + Math.random() * 3, vel.z * .9 + rnd() * 4); d.w.set(rnd() * 10, rnd() * 6, rnd() * 10);
120
+ for (let k = 0; k < 5; k++) puff(q.x, .6, q.z, rnd() * 6, 1 + Math.random() * 3, rnd() * 6, q.kind === "lamp" ? 0xffd27a : 0xb0b0b0, .25, .5);
121
+ smashN++; smashCash += q.kind === "lamp" ? 40 : q.kind === "barrier" ? 25 : 15; smashT = .7; sound.thud && sound.thud(.45);
122
+ }
123
+ }
124
+ function debrisUpdate(dt, cam) {
125
+ for (const d of debris) if (d.m.visible) {
126
+ d.t -= dt; d.v.y -= 9.81 * dt; d.m.position.addScaledVector(d.v, dt); d.m.rotation.x += d.w.x * dt; d.m.rotation.y += d.w.y * dt; d.m.rotation.z += d.w.z * dt;
127
+ if (d.m.position.y < d.hh * .35) { d.m.position.y = d.hh * .35; d.v.y = Math.abs(d.v.y) * .3; d.v.x *= .6; d.v.z *= .6; d.w.multiplyScalar(.6); }
128
+ if (d.t < 1) d.m.scale.setScalar(Math.max(.01, d.t)); if (d.t <= 0) d.m.visible = false;
129
+ }
130
+ for (let i = downs.length - 1; i >= 0; i--) { const D = downs[i]; if ((D.t -= dt) <= 0 && Math.hypot(D.q.x - cam.x, D.q.z - cam.z) > 80) { city.props.restore(D.q); downs.splice(i, 1); } }
131
+ if (smashT > 0 && (smashT -= dt) <= 0 && smashN) { game.api.addScore(smashCash, smashN > 1 ? `Smashed ${smashN} props` : "Smashed a prop"); smashN = smashCash = 0; }
132
+ }
133
+
134
+ // ---- the first minute: the neon launch ramp ahead of the spawn (a ring over the jump and chevrons leading in) ----
135
+ {
136
+ const neon = new THREE.MeshBasicMaterial({ color: new THREE.Color(0xff3df0).multiplyScalar(2.2), toneMapped: false });
137
+ const ring = add(new THREE.Mesh(new THREE.TorusGeometry(9, .7, 10, 44), neon)); ring.position.set(RAMP_X + 46, 20, LZ); ring.rotation.y = Math.PI / 2;
138
+ game.RINGS.push({ m: ring, x: RAMP_X + 46, y: 20, z: LZ, nx: 1, nz: 0, done: 0, side: 0 });
139
+ const chevMat = new THREE.MeshBasicMaterial({ color: new THREE.Color(0xff3df0).multiplyScalar(1.6), toneMapped: false, transparent: true, opacity: .85, depthWrite: false, polygonOffset: true, polygonOffsetFactor: -4, polygonOffsetUnits: -4 });
140
+ for (const x of [RAMP_X - 70, RAMP_X - 45, RAMP_X - 20]) { const c = add(new THREE.Mesh(chevGeo, chevMat)); c.scale.setScalar(1.6); c.position.set(x, .07, LZ); }
141
+ }
142
+
143
+ // ---- key hints: each turns up once, the first time it's useful (the start screen only shows WASD, Shift and F) ----
144
+ const seen = new Set(store.get("void.hints") || []), hintEl = $("gKeyHint"); let hintOn = null, hintT = 0, chk = 0, played = 0, stillT = 0, stuckT = 0, flyT = 0;
145
+ const K = k => COARSE ? "" : `<kbd>${k}</kbd>`;
146
+ function hint(id, html, t = 7) { if (seen.has(id) || hintOn || !hintEl) return; seen.add(id); store.set("void.hints", [...seen]); hintOn = id; hintT = t; hintEl.innerHTML = html; hintEl.hidden = false; sound.pop && sound.pop(); }
147
+ const railDist = (x, z) => { let best = 1e9; for (const r of game.RAILS) { const a = Math.max(0, Math.min(r.len, (x - r.x) * r.c + (z - r.z) * r.s)); best = Math.min(best, Math.hypot(x - (r.x + r.c * a), z - (r.z + r.s * a))); } return best; };
148
+ function hints(dt, s, S) {
149
+ if (hintOn && (hintT -= dt) <= 0) { hintOn = null; hintEl.hidden = true; }
150
+ played += dt; const sp = Math.hypot(s.vel.x, s.vel.z);
151
+ stillT = s.veh === "car" && sp < 1 ? stillT + dt : 0;
152
+ stuckT = s.veh === "car" && sp < 1.5 && s.brakeIn === 0 && S.load > .5 ? stuckT + dt : 0;
153
+ flyT = s.mode === "air" && s.veh === "car" ? flyT + dt : 0;
154
+ if (s.mode === "air" && s.veh === "car" && s.hover && !store.get("void.flew")) store.set("void.flew", 1);
155
+ // the launch ramp: until you've flown once
156
+ if (!store.get("void.flew") && s.mode === "drive" && s.veh === "car" && Math.cos(s.yaw) > .7 && s.x > RAMP_X - 160 && s.x < RAMP_X && Math.abs(s.z - LZ) < 10) game.api.say(COARSE ? "🚀 Hit the ramp, then tap Fly in mid-air!" : "🚀 Hit the ramp & press F in mid-air to fly!", .6);
157
+ if ((chk -= dt) > 0) return; chk = .5;
158
+ if (flyT > 5) hint("land", `${K("L")} Land: the car glides down and touches down softly${COARSE ? " (tap Land)" : ""}`);
159
+ if (S.nitroFull && played > 40) hint("od", `Tap ${K("Shift")} for a kick · hold it from full for ⚡ OVERDRIVE`);
160
+ if (stuckT > 2.5) hint("reset", `${K("R")} Stuck? Back on your wheels right here${COARSE ? " (↺)" : ""}`);
161
+ if ((s.veh === "foot" || sp < 9) && railDist(s.x, s.z) < 35) hint("board", COARSE ? "🛹 Hoverboard (Menu ☰ → Vehicle): grind these rails" : `${K("Y")} Hoverboard: grind these rails, ollie with Space`);
162
+ if (played > 50 && stillT > 4) hint("foot", COARSE ? "🚶 Get out and walk · take any car" : `${K("E")} Get out and walk · take any car`);
163
+ if (o.dealer && o.dealer() && o.dealer().sites.some(st => Math.hypot(st.x - s.x, st.z - s.z) < 45)) hint("garage", `${K("G")} VOID Motors: your garage, every car is yours`);
164
+ if (played > 120 && stillT > 3 && Math.abs(s.x) < 1000 && s.z > -700 && s.z < 2100) hint("taxi", COARSE ? "🚕 Taxi jobs (Menu ☰): passengers pay cash" : `${K("J")} Taxi jobs: passengers pay cash`);
165
+ if (played > 90) hint("radio", COARSE ? "📻 Change the station: Menu ☰ → Radio" : `${K("U")} Change the radio station`);
166
+ if (played > 360) hint("route", COARSE ? "🏁 Build your own race (Menu ☰ → Routes)" : `${K("B")} Build your own race route and race your ghost`);
167
+ }
168
+ addEventListener("keydown", e => { if (e.code === "KeyU" && !e.repeat && game.api.active() && !/INPUT|TEXTAREA/.test(document.activeElement.tagName)) o.radioNext && o.radioNext(); });
169
+
170
+ const textTex = (lines, w = 512, h = 128, bg = "rgba(0,0,0,.65)", col = "#ff3df0") => { const c = document.createElement("canvas"); c.width = w; c.height = h; const g = c.getContext("2d"); g.fillStyle = bg; g.fillRect(0, 0, w, h); g.fillStyle = col; g.shadowColor = col; g.shadowBlur = 18; g.font = `900 ${Math.round(h * .55)}px Unbounded, Impact, sans-serif`; g.textAlign = "center"; g.textBaseline = "middle"; g.fillText(lines, w / 2, h / 2); const t = new THREE.CanvasTexture(c); t.colorSpace = THREE.SRGBColorSpace; return t; };
171
+ const neonMat = col => new THREE.MeshBasicMaterial({ color: new THREE.Color(col).multiplyScalar(2), toneMapped: false });
172
+
173
+ // ---- 15 rooftop stunt pads on the tallest towers: each new one pays more, a bullseye doubles it ----
174
+ const padHits = new Set(store.get("void.padtargets") || []), TGT = [];
175
+ {
176
+ const hp = city.helipads.slice().sort((a, b) => b.y - a.y), pick = [];
177
+ for (const h of hp) { if (pick.length >= 15) break; if (pick.every(q => Math.hypot(q.x - h.x, q.z - h.z) > 140)) pick.push(h); }
178
+ const tex = (() => { const c = document.createElement("canvas"); c.width = c.height = 256; const g = c.getContext("2d"); for (const [r0, col] of [[124, "#ff3df0"], [100, "rgba(0,0,0,0)"], [80, "#ffffff"], [58, "rgba(0,0,0,0)"], [38, "#ff3df0"], [16, "#ffffff"]]) { g.beginPath(); g.arc(128, 128, r0, 0, 7); g.fillStyle = col; g.globalCompositeOperation = col === "rgba(0,0,0,0)" ? "destination-out" : "source-over"; g.fill(); } return new THREE.CanvasTexture(c); })();
179
+ const mat = new THREE.MeshBasicMaterial({ map: tex, transparent: true, toneMapped: false, depthWrite: false, color: new THREE.Color(1.6, 1.6, 1.6), polygonOffset: true, polygonOffsetFactor: -4, polygonOffsetUnits: -4 });
180
+ pick.forEach((h, i) => { const rr = Math.max(6, Math.min(9, h.r || 8)), m = add(new THREE.Mesh(new THREE.PlaneGeometry(rr * 2, rr * 2).rotateX(-Math.PI / 2), mat)); m.position.set(h.x, h.y + .15, h.z); TGT.push({ id: i, x: h.x, y: h.y, z: h.z, r: rr, done: padHits.has(i) }); });
181
+ }
182
+ const chips = $("gCoins") && $("gCoins").parentElement, padChip = document.createElement("span");
183
+ if (chips) { padChip.id = "gPadsChip"; chips.appendChild(padChip); }
184
+ const padText = () => { padChip.textContent = `🎯 ${padHits.size}/15`; }; padText();
185
+ function onLand(s, down) {
186
+ for (const t of TGT) {
187
+ const d = Math.hypot(s.x - t.x, s.z - t.z); if (d > t.r + 1 || Math.abs(s.y - t.y) > 3) continue;
188
+ if (t.done) { if (d < 2) game.api.addScore(250, "🎯 Bullseye again"); else game.api.say("🎯 Already landed here. Find another tower!", 2); return; }
189
+ const mult = d < 2 ? 2 : d < 4.5 ? 1.5 : 1, pay = Math.round(1000 * (padHits.size + 1) * mult * (down < 4 ? 1.2 : 1));
190
+ t.done = true; padHits.add(t.id); store.set("void.padtargets", [...padHits]); padText();
191
+ game.api.addScore(pay, `🎯 ${mult === 2 ? "BULLSEYE" : mult > 1 ? "Close" : "Pad"} ${padHits.size}/15`); pop(`🎯 ${mult === 2 ? "BULLSEYE" : "ROOFTOP"} +$${pay.toLocaleString()}`, "gold"); return;
192
+ }
193
+ }
194
+
195
+ // ---- six neon paint shops: drive through one and the police lose you, and you come out in a new colour ----
196
+ const SHOPS = [];
197
+ {
198
+ const frame = new THREE.MeshStandardMaterial({ color: 0x1b1d24, metalness: .6, roughness: .4 }), nA = neonMat(0xff3df0), nB = neonMat(0x3df5ff), sign = new THREE.MeshBasicMaterial({ map: textTex("🎨 PAINT"), toneMapped: false, side: THREE.DoubleSide });
199
+ for (const [i, j] of [[2, 6], [10, 12], [4, 21], [8, 29], [1, 35], [11, 3]]) {
200
+ const x = GRID.ax(i), z = (GRID.sz(j) + GRID.sz(j + 1)) / 2, w = GRID.avW(i) / 2 + .6, g = new THREE.Group(); g.position.set(x, 0, z);
201
+ for (const sd of [-1, 1]) { const pil = new THREE.Mesh(new THREE.BoxGeometry(.9, 7.4, 2.4), frame); pil.position.set(sd * w, 3.7, 0); g.add(pil); const st = new THREE.Mesh(new THREE.BoxGeometry(.12, 7, .12), sd < 0 ? nA : nB); st.position.set(sd * (w - .5), 3.6, 1.25); g.add(st); }
202
+ const top = new THREE.Mesh(new THREE.BoxGeometry(w * 2 + .9, 1.3, 2.4), frame); top.position.y = 7.6; g.add(top);
203
+ for (const fz of [-1.25, 1.25]) { const n = new THREE.Mesh(new THREE.BoxGeometry(w * 2, .14, .14), fz < 0 ? nB : nA); n.position.set(0, 6.9, fz); g.add(n); const sg = new THREE.Mesh(new THREE.PlaneGeometry(6, 1.5), sign); sg.position.set(0, 7.6, fz * 1.02); if (fz < 0) sg.rotation.y = Math.PI; g.add(sg); }
204
+ add(g); SHOPS.push({ x, z, w, t: 0 });
205
+ }
206
+ }
207
+ function shops(dt, s) {
208
+ for (const sh of SHOPS) {
209
+ if (sh.t > 0) { sh.t -= dt; continue; }
210
+ if (s.veh !== "car" || s.y > 3 || Math.abs(s.z - sh.z) > 2.5 || Math.abs(s.x - sh.x) > sh.w) continue;
211
+ sh.t = 20; const name = o.respray ? o.respray() : null, col = o.paintHex ? o.paintHex() : 0xffffff;
212
+ for (let k = 0; k < 26; k++) puff(sh.x + rnd() * sh.w * 1.6, 1 + Math.random() * 5, sh.z + rnd() * 2, rnd() * 3, -1 - Math.random() * 2, rnd() * 3, col, .9, 1.2);
213
+ const hot = o.stars && o.stars() > 0; if (hot && o.policeClear) o.policeClear();
214
+ game.api.say(`🎨 ${name ? `Fresh paint: ${name}` : "Fresh paint"}${hot ? " · the police lost you" : ""}`, 3); pop(hot ? "🎨 HEAT CLEARED" : "🎨 NEW PAINT", "gold"); sound.whoosh && sound.whoosh();
215
+ }
216
+ }
217
+
218
+ // ---- boost pads: the Sky Park run-up and the tunnel floor kick you forward ----
219
+ const BOOSTS = [];
220
+ const boostMat = new THREE.MeshBasicMaterial({ color: new THREE.Color(0x3df5ff).multiplyScalar(1.8), toneMapped: false, transparent: true, opacity: .9, depthWrite: false, polygonOffset: true, polygonOffsetFactor: -4, polygonOffsetUnits: -4, side: THREE.DoubleSide });
221
+ const boostPad = (x, y, z, yaw) => { const c = add(new THREE.Mesh(chevGeo, boostMat)); c.scale.setScalar(2.2); c.position.set(x, y + .06, z); c.rotation.y = -yaw; BOOSTS.push({ x, y, z, t: 0 }); };
222
+ function boosts(dt, s) {
223
+ for (const b of BOOSTS) {
224
+ if (b.t > 0) { b.t -= dt; continue; }
225
+ if (s.mode !== "drive" || Math.abs(s.x - b.x) > 3 || Math.abs(s.z - b.z) > 3 || Math.abs(s.y - b.y) > 2) continue;
226
+ b.t = 1.2; const sp = Math.hypot(s.vel.x, s.vel.z) || 1, nv = Math.min(105, sp + 20); s.vel.x *= nv / sp; s.vel.z *= nv / sp; s.shake = .4; game.api.say("⚡ BOOST", 1); sound.whoosh && sound.whoosh();
227
+ }
228
+ }
229
+
230
+ // ---- Sky Park: the loop's track (it twists a few metres sideways so you come out beside where you went in), boost pads, a sign ----
231
+ {
232
+ const L2 = game.LOOP2, N = 120, pos = [], hw = 3.6;
233
+ const at = (th, side) => [L2.x + L2.R * Math.sin(th), L2.R * (1 - Math.cos(th)) - .05 * Math.cos(th), L2.z + L2.shift * th / (2 * Math.PI) + side];
234
+ for (let i = 0; i < N; i++) { const a = i / N * 2 * Math.PI, b = (i + 1) / N * 2 * Math.PI, p1 = at(a, -hw), p2 = at(a, hw), p3 = at(b, hw), p4 = at(b, -hw); pos.push(...p1, ...p2, ...p3, ...p1, ...p3, ...p4); }
235
+ const g = new THREE.BufferGeometry(); g.setAttribute("position", new THREE.Float32BufferAttribute(pos, 3)); g.computeVertexNormals();
236
+ add(new THREE.Mesh(g, new THREE.MeshStandardMaterial({ color: 0x1d1e24, roughness: .6, metalness: .3, side: THREE.DoubleSide })));
237
+ for (const sd of [-hw, hw]) { const pts = []; for (let i = 0; i <= 64; i++) pts.push(new THREE.Vector3(...at(i / 64 * 2 * Math.PI, sd))); add(new THREE.Mesh(new THREE.TubeGeometry(new THREE.CatmullRomCurve3(pts), 160, .14, 6), neonMat(0xff3df0))); }
238
+ for (const x of [-905, -870, -835]) boostPad(x, 0, -1000, 0);
239
+ boostPad(L2.x - 40, 0, L2.z, 0); boostPad(L2.x - 70, 0, L2.z, 0);
240
+ const sg = add(new THREE.Mesh(new THREE.PlaneGeometry(36, 9), new THREE.MeshBasicMaterial({ map: textTex("SKY PARK", 1024, 256), toneMapped: false, side: THREE.DoubleSide }))); sg.position.set(-500, 16, -775);
241
+ }
242
+
243
+ // ---- the secret tunnel: down a trench south of downtown, a lit tube under the Hudson, up a trench into the harbor ----
244
+ const T = TUNNEL, covered = x => x <= T.a0 - 100 && x >= T.b1 + 100, floorAt = x => x > T.a1 ? T.floor * (T.a0 - x) / (T.a0 - T.a1) : x < T.b0 ? T.floor * (x - T.b1) / (T.b0 - T.b1) : T.floor;
245
+ {
246
+ const xs = []; for (let x = T.a0; x > T.a1; x -= 12) xs.push(x); xs.push(T.a0 - 100, T.a1, T.b0); for (let x = T.b0 - 12; x > T.b1; x -= 12) xs.push(x); xs.push(T.b1 + 100, T.b1);
247
+ xs.sort((a, b) => b - a);
248
+ const prof = x => { const f = floorAt(x), top = covered(x) ? T.ceil : .3, pts = [[-T.half, top], [-T.half, f + 2.6]]; for (let k = 1; k <= 6; k++) { const b = -T.half + 2.8 * k / 6, e = (Math.abs(b) - 4.2) / 2.8; pts.push([b, f + 2.6 * Math.max(0, e) ** 2]); } for (let k = 0; k <= 6; k++) { const b = 4.2 + 2.8 * k / 6, e = (b - 4.2) / 2.8; pts.push([b, f + 2.6 * e * e]); } pts.push([T.half, top]); return pts; };
249
+ const pos = [];
250
+ for (let i = 0; i < xs.length - 1; i++) { const A = prof(xs[i]), B = prof(xs[i + 1]); for (let k = 0; k < A.length - 1; k++) { const q = [[xs[i], A[k]], [xs[i + 1], B[k]], [xs[i + 1], B[k + 1]], [xs[i], A[k + 1]]].map(([x, [b, y]]) => [x, y, T.z + b]); pos.push(...q[0], ...q[1], ...q[2], ...q[0], ...q[2], ...q[3]); } }
251
+ const cx0 = T.a0 - 100, cx1 = T.b1 + 100, Z0 = T.z - T.half, Z1 = T.z + T.half;
252
+ pos.push(cx0, T.ceil, Z0, cx1, T.ceil, Z0, cx1, T.ceil, Z1, cx0, T.ceil, Z0, cx1, T.ceil, Z1, cx0, T.ceil, Z1); // the roof
253
+ for (const x of [cx0, cx1]) pos.push(x, T.ceil, Z0, x, .3, Z0, x, .3, Z1, x, T.ceil, Z0, x, .3, Z1, x, T.ceil, Z1); // the walls over each portal
254
+ const g = new THREE.BufferGeometry(); g.setAttribute("position", new THREE.Float32BufferAttribute(pos, 3)); g.computeVertexNormals();
255
+ const tun = add(new THREE.Mesh(g, new THREE.MeshStandardMaterial({ color: 0x6d7078, roughness: .85, side: THREE.DoubleSide }))); tun.receiveShadow = true;
256
+ // the grass over the covered ends of the trenches (the holes in the ground are cut a little longer than the open part)
257
+ const grass = new THREE.MeshStandardMaterial({ color: 0x5a7a44, roughness: 1 });
258
+ for (const [x0, x1] of [[T.a1 - 12, cx0], [cx1, T.b0 + 12]]) { const slab = add(new THREE.Mesh(new THREE.BoxGeometry(Math.abs(x1 - x0), .3, T.half * 2 + 1.2), grass)); slab.position.set((x0 + x1) / 2, -.27, T.z); }
259
+ // light strips along the roof and the walls, boost pads on the floor every 250 m, and a sign over each portal
260
+ const stripMat = neonMat(0xbfefff), len = cx0 - cx1;
261
+ for (const sd of [-5.4, 5.4]) { const st = add(new THREE.Mesh(new THREE.BoxGeometry(len, .06, .3), stripMat)); st.position.set((cx0 + cx1) / 2, T.ceil - .06, T.z + sd); }
262
+ for (const sd of [-T.half + .05, T.half - .05]) { const st = add(new THREE.Mesh(new THREE.BoxGeometry(T.a1 - T.b0, .14, .06), neonMat(0x3df5ff))); st.position.set((T.a1 + T.b0) / 2, T.floor + 3.4, T.z + sd); }
263
+ for (let x = T.a1 - 150; x > T.b0 + 100; x -= 250) boostPad(x, T.floor, T.z, Math.PI);
264
+ const tsign = new THREE.MeshBasicMaterial({ map: textTex("VOID TUNNEL", 1024, 192, "rgba(0,0,0,.75)", "#3df5ff"), toneMapped: false, side: THREE.DoubleSide });
265
+ for (const [x, ry] of [[T.a0 - 2, Math.PI / 2], [T.b1 + 2, -Math.PI / 2]]) { const sg = add(new THREE.Mesh(new THREE.PlaneGeometry(14, 2.6), tsign)); sg.position.set(x, 4, T.z); sg.rotation.y = ry; for (const sd of [-1, 1]) { const post = add(new THREE.Mesh(new THREE.BoxGeometry(.4, 4.5, .4), stripMat)); post.position.set(x, 2.25, T.z + sd * 7.2); } }
266
+ // the harbor at the far end: stacks of shipping containers either side of the road out
267
+ const box = new THREE.BoxGeometry(12, 2.6, 2.5), cols = [0xb8322a, 0x1f5aa8, 0x2e7a3a, 0xd98a1f, 0x6a6e78], cm = new THREE.InstancedMesh(box, new THREE.MeshStandardMaterial({ roughness: .7, metalness: .3 }), 120);
268
+ let n = 0; const M4 = new THREE.Matrix4(), C3 = new THREE.Color();
269
+ for (let i = 0; i < 6; i++) for (const zs of [-1, 1]) for (let row = 0; row < 3; row++) for (let lvl = 0; lvl < (i + row) % 3 + 1; lvl++) { if (n >= 120) break; M4.makeTranslation(T.b1 - 20 - i * 14, 1.3 + lvl * 2.6, T.z + zs * (14 + row * 3)); cm.setMatrixAt(n, M4); cm.setColorAt(n, C3.setHex(cols[(i * 3 + row + lvl) % 5])); n++; }
270
+ cm.count = n; cm.castShadow = true; add(cm);
271
+ }
272
+ function tunnel(x, z, y) {
273
+ if (Math.abs(z - T.z) > T.half || x > T.a0 || x < T.b1) return null;
274
+ const cov = covered(x); if (cov && y > T.ceil - .5) return null; // up on the grass over the tube
275
+ const inA = x > T.a1, inB = x < T.b0, b = z - T.z, e = Math.max(0, (Math.abs(b) - 4.2) / 2.8);
276
+ return { h: floorAt(x) + 2.6 * e * e, tunnel: T, ceil: cov ? T.ceil : null, slopeX: inA ? -T.floor / (T.a0 - T.a1) : inB ? T.floor / (T.b0 - T.b1) : 0, side: Math.sign(b) * 2 * 2.6 * e / 2.8 };
277
+ }
278
+
279
+ // ---- the coin chime: a soft ping that quickens as you close in on a hidden coin (inside 60 m) ----
280
+ let chimeT = 0;
281
+ function chime(dt) { const d = o.extras ? o.extras().nearestCoin() : 1e9; if (d > 60) { chimeT = 0; return; } if ((chimeT -= dt) <= 0) { chimeT = .22 + d / 60 * 1.1; sound.chime && sound.chime(880 + (60 - d) * 9); } }
282
+
283
+ let odWas = false;
284
+ return {
285
+ props, pop, onScore, onLand, tunnel,
286
+ pads: () => TGT, mapData: () => ({ targets: TGT, shops: SHOPS, tunnel: T }),
287
+ update(dt, time, S, cam) {
288
+ const s = game.state; if (!s || !s.started) { columnsUpdate(dt, cam, false); return; }
289
+ columnsUpdate(dt, cam, s.mode === "air");
290
+ gpsUpdate(time, s); trailsUpdate(dt, s, S); debrisUpdate(dt, cam); hints(dt, s, S); shops(dt, s); boosts(dt, s); chime(dt);
291
+ const nos = $("gNos"); if (nos) { nos.classList.toggle("od", !!S.od); nos.classList.toggle("full", !!S.nitroFull && !S.od); }
292
+ if (S.od && !odWas) pop("⚡ OVERDRIVE", "hot"); odWas = !!S.od;
293
+ // the shockwave: a ring that bursts out across the flight path
294
+ if (S.sonic > .95 && shockT <= 0) { shockT = .9; shock.position.copy(S.pos); shock.lookAt(S.pos.x + s.vel.x, S.pos.y + s.vel.y, S.pos.z + s.vel.z); shock.visible = true; for (let k = 0; k < 16; k++) puff(S.pos.x, S.pos.y, S.pos.z, rnd() * 30, rnd() * 30, rnd() * 30, 0xffffff, .8, .6); }
295
+ if (shockT > 0) { shockT -= dt; const k = 1 - shockT / .9; shock.scale.setScalar(3 + k * 80); shockMat.opacity = (1 - k) * .55; if (shockT <= 0) shock.visible = false; }
296
+ // the cloud deck fades in as you climb; above it pays once a flight
297
+ cloudMat.opacity = Math.max(0, Math.min(1, (cam.y - 140) / 160)) * (W.timeOfDay === "night" ? .32 : .6);
298
+ clouds.visible = cloudMat.opacity > .01;
299
+ if (s.mode === "air" && s.y > 470 && !aboveDone) { aboveDone = true; game.api.addScore(300, "☁️ Above the clouds"); }
300
+ if (s.mode !== "air") aboveDone = false;
301
+ },
302
+ };
303
+ }
static/main.js CHANGED
@@ -59,8 +59,18 @@ const sound = new Sound();
59
  const watch = createWatch(W, car, interior);
60
  const DENSITY = { few: .55, normal: 1, busy: 1.3 }[(store.get("void.settings") || {}).crowd || (LITE ? "few" : "normal")] || 1;
61
  const life = createLife(scene, W.roads, W.walkways, COARSE || LITE, DENSITY); lt("life");
62
- const TIMES = ["night", "sunset", "day"];
63
- function cycleTime() { const k = TIMES[(TIMES.indexOf(W.timeOfDay) + 1) % 3]; W.setTime(k); store.set("void.time", k); toast({ night: "Night in the city", sunset: "Golden hour", day: "Daytime" }[k]); cubeN = 0; }
 
 
 
 
 
 
 
 
 
 
64
  let police, races, nav, legion = null;
65
  const net = createNet(); lt("net");
66
  setInterval(() => { if (document.hidden) net.tick(.5, null); }, 500); // a hosting tab in the background still relays everyone
@@ -69,11 +79,12 @@ setInterval(() => { if (document.hidden) net.tick(.5, null); }, 500); // a h
69
  const GPU = (() => { try { const c = renderer.getContext(), e = c.getExtension("WEBGL_debug_renderer_info"); return e ? c.getParameter(e.UNMASKED_RENDERER_WEBGL) : ""; } catch { return ""; } })();
70
  const STRONG = /RTX|GTX 1[06-9]|GTX 9[78]|Radeon RX|Radeon Pro|Apple M[1-9]/i.test(GPU) && !COARSE;
71
  const TOP = /RTX\s?(40[6-9]0|50[5-9]0)|RTX\s?A?[45]\d{3}/i.test(GPU) && !COARSE; // recent RTX cards start on Ultra
72
- const SET = Object.assign({ q: LITE ? "lite" : TOP ? "ultra" : STRONG ? "high" : COARSE ? "low" : "medium", sens: 1, autogas: "off", steer: "stick", weather: "clear", radio: "score", cycle: "off", handling: "arcade", motion: "on", text: "normal", board: "ion", crowd: LITE ? "few" : "normal", fps: "off", voice: "open" }, store.get("void.settings") || {});
73
  const gameOpts = {
74
  handling: () => SET.handling, buyFood: () => { if (cash < 10) return false; cash -= 10; store.set("void.cash", cash); earn(0); return true; }, heroOwned: () => !!store.get("void.hero"), starter: () => { const m = life.models.find(m => m.id === "compact-3") || life.models.find(m => m.kind.id === "compact"); return { model: { ...m, top: 31, acc: .7, grip: .9 }, color: 0x6b5a44, rust: .75, owned: true }; }, onSteal: c => { police && police.event("steal"); goals.stats.steals = (goals.stats.steals || 0) + 1; },
75
  garage: () => openGarage(true), cycleTime, hornType: () => build.horn, autoGas: () => SET.autogas === "on", onRepair: () => car.repair && car.repair(),
76
  props: (x, z, y, vel) => legion && legion.props(x, z, y, vel),
 
77
  onScore: (n, why, pts) => { if (legion) legion.onScore(why, pts ?? n); if (/^Drift/.test(why)) goals.drift(n); if (/^(🥇|🥈|🥉)/.test(why)) goals.stats.meds = (goals.stats.meds || 0) + 1; { const gm = /^Grind (\d+) m/.exec(why); if (gm) goals.stats.grind = (goals.stats.grind || 0) + +gm[1]; const sp = /^(\d+)( |$)/.exec(why); if (sp && +sp[1] >= 720) goals.stats.b720 = 1; if (/Kickflip|Heelflip/.test(why) && / \+ /.test(why)) goals.stats.combo = (goals.stats.combo || 0) + 1; } goals.note(why); earn(pts ?? n); },
78
  onSmash: kind => police && police.event("smash", kind), policeClear: () => police && police.clear(),
79
  autopilot: (g, dt, over) => nav ? nav.controls(g, dt, over) : null, openGps: () => document.getElementById("gGpsBtn").click(),
@@ -83,6 +94,22 @@ const gameOpts = {
83
  if (police) for (const c of police.cops) if (c.on) { const [a, b] = P(c.x, c.z); mx.fillStyle = Math.sin(performance.now() / 90) > 0 ? "#ff3040" : "#3060ff"; mx.beginPath(); mx.arc(a, b, 4, 0, 7); mx.fill(); }
84
  if (races && races.race && races.race.next) { const [a, b] = P(races.race.next[0], races.race.next[2]); mx.strokeStyle = "#ffd23d"; mx.lineWidth = 3; mx.beginPath(); mx.arc(a, b, 7, 0, 7); mx.stroke(); }
85
  for (const r of remotes.values()) if (r.at) { const [a, b] = P(r.at.x, r.at.z); mx.fillStyle = "#c07dff"; mx.beginPath(); mx.arc(a, b, 4.5, 0, 7); mx.fill(); }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  mx.font = "bold 12px sans-serif"; mx.textAlign = "center"; for (const st of W.city.stations) { const [a, b] = P(st.x, st.z); if (Math.abs(a) < 90 && Math.abs(b) < 90) { mx.save(); mx.translate(a, b); mx.rotate(g.yaw + Math.PI / 2); mx.fillText("⛽", 0, 4); mx.restore(); } }
87
  // VOID Motors: a gold "$" badge on every counter in view (beside the pump icon), and an arrow on the rim pointing at the nearest one when none is
88
  const dl = gameOpts.dealer; if (dl) { let seen = false; for (const st of dl.sites) { const [a, b] = P(st.x, st.z); if (Math.hypot(a, b) < 82) { seen = true; mx.save(); mx.translate(a, b); mx.rotate(g.yaw + Math.PI / 2); const ox = st.main ? 0 : 9, oy = st.main ? 0 : -9; mx.fillStyle = "#ffd23d"; mx.strokeStyle = "#000"; mx.lineWidth = 2; mx.beginPath(); mx.arc(ox, oy, 6.5, 0, 7); mx.fill(); mx.stroke(); mx.fillStyle = "#000"; mx.font = "900 10px sans-serif"; mx.textAlign = "center"; mx.fillText("$", ox, oy + 3.5); mx.restore(); } }
@@ -100,7 +127,7 @@ function renderGoals() {
100
  document.getElementById("gStatsRow").innerHTML = `<div><b>${(S.best || 0).toLocaleString()}</b><span>Best score</span></div><div><b>${Math.round(S.top)}</b><span>Top km/h</span></div><div><b>${S.km.toFixed(1)}</b><span>km travelled</span></div><div><b>${goals.done.size}/${GOALS.length}</b><span>Trophies</span></div><div><b>$${cash.toLocaleString()}</b><span>Cash · spend in Garage</span></div>`;
101
  }
102
  const WX_ICON = { clear: "☀️ Clear", rain: "🌧 Rain", storm: "⛈ Storm", fog: "🌫 Fog", snow: "❄️ Snow" }, RADIO = { score: "🎵 VOID Score", synth: "🌆 Cyber Synth", chill: "🌙 Chill Night Drive", chase: "🔥 High-Octane Chase", voidfm: "📻 VOID FM", off: "🔇 Radio off" };
103
- function chips() { document.getElementById("gChips").innerHTML = `<span>${{ night: "🌙", sunset: "🌇", day: "☀️" }[W.timeOfDay]} ${W.timeOfDay}</span><span>${WX_ICON[atmos.weather]}</span>`; document.getElementById("gWeather").innerHTML = `<b>${WX_ICON[SET.weather].split(" ")[0]}</b>${WX_ICON[SET.weather].split(" ").slice(1).join(" ")}`; document.getElementById("gRadio").innerHTML = `<b>${RADIO[SET.radio].split(" ")[0]}</b>${RADIO[SET.radio].split(" ").slice(1).join(" ")}`; }
104
  document.getElementById("gWeather").onclick = () => { SET.weather = WEATHERS[(WEATHERS.indexOf(SET.weather) + 1) % WEATHERS.length]; atmos.setWeather(SET.weather); store.set("void.settings", SET); chips(); toast(WX_ICON[SET.weather]); };
105
  document.getElementById("gRadio").onclick = () => { const k = Object.keys(RADIO); SET.radio = k[(k.indexOf(SET.radio) + 1) % k.length]; if (!sound.on) setSound(true); sound.setRadio(SET.radio); store.set("void.settings", SET); chips(); toast(RADIO[SET.radio]); };
106
  // ---------- the menu (☰ or Esc): everything that isn't driving lives here ----------
@@ -621,7 +648,7 @@ function frameLoop(fixed) {
621
  W.city.poolMat.opacity = W.timeOfDay === "night" ? 1 : W.timeOfDay === "sunset" ? .45 : 0; W.city.poolMat.visible = W.timeOfDay !== "day";
622
  extras.sky(dt, time);
623
  // the living city: when switched on, the day turns and the weather changes on its own
624
- if (SET.cycle === "on" && mode === "play" && (cycleT += dt) > 150) { cycleT = 0; cycleTime(); if (Math.random() < .5) { const w = ["clear", "clear", "rain", "fog", "storm", "snow"][Math.floor(Math.random() * 6)]; atmos.setWeather(w); SET.weather = w; } }
625
  life.raining = atmos.weather === "rain" || atmos.weather === "storm"; life.night = W.timeOfDay !== "day";
626
  // the El train is solid: you get shoved off the track (and hurt if you hit it hard)
627
  if (mode === "play" && W.city.el && game.state) { const T = W.city.el.train, s = game.state; if (Math.abs(s.x - W.city.el.x) < 2.6 && s.y > W.city.el.top - .5 && s.y < W.city.el.top + 4 && Math.abs(s.z - T.z) < T.len / 2 + 1) { s.x = W.city.el.x + (s.x >= W.city.el.x ? 3 : -3); const sp = Math.hypot(s.vel.x, s.vel.z); if (sp > 8 || T.v > 5) { game.api.hurt(8 + T.v, "Hit by the train"); sound.crash(); } } }
@@ -736,7 +763,10 @@ try {
736
  });
737
  if (parts.length) { const geo = mergeGeometries(parts); geo.translate(0, -.02, 0); life.setVoidGeo(geo); life.setVoidDetail(W.quality !== "lite"); window.__voidTris = geo.attributes.position.count / 3; }
738
  } catch (e) { console.warn("VOID flyers keep the simple shape", e); }
 
 
739
  legion = createLegion({ W, game, sound, store, life, COARSE, races: () => races, nav: () => nav, dealer: () => dealer, radioNext: () => document.getElementById("gRadio").click(),
 
740
  trailColor: () => { const v = OPTS.glow.items[build.glow][1]; return v ? new THREE.Color(v).toArray() : [1, .2, .85]; } });
741
  setLoad(95);
742
  await precompile(); lt("compile");
 
59
  const watch = createWatch(W, car, interior);
60
  const DENSITY = { few: .55, normal: 1, busy: 1.3 }[(store.get("void.settings") || {}).crowd || (LITE ? "few" : "normal")] || 1;
61
  const life = createLife(scene, W.roads, W.walkways, COARSE || LITE, DENSITY); lt("life");
62
+ const TIMES = ["night", "dawn", "day", "sunset"];
63
+ function cycleTime() { const k = TIMES[(TIMES.indexOf(W.timeOfDay) + 1) % TIMES.length]; W.setTime(k); store.set("void.time", k); toast({ night: "Night in the city", dawn: "Dawn", sunset: "Golden hour", day: "Daytime" }[k]); cubeN = 0; }
64
+ // the living city: the day turns by itself, blending smoothly into each next time of day (night may bring rain)
65
+ const CYCLE = ["day", "sunset", "night", "dawn"], cyc = { t: 0, b: 0, from: "day", to: "sunset" };
66
+ function dayTurn(dt) {
67
+ if (!cyc.b) { if ((cyc.t += dt) > 110) { cyc.from = W.timeOfDay; cyc.to = CYCLE[(CYCLE.indexOf(cyc.from) + 1) % CYCLE.length]; cyc.b = .0001; } return; }
68
+ cyc.b = Math.min(1, cyc.b + dt / 14); W.blendTime(cyc.from, cyc.to, cyc.b);
69
+ if (cyc.b >= 1) {
70
+ cyc.b = 0; cyc.t = 0; store.set("void.time", cyc.to); cubeN = 0;
71
+ if (cyc.to === "night" && Math.random() < .5) { atmos.setWeather("rain"); SET.weather = "rain"; } else if (cyc.to === "day" && SET.weather !== "clear") { atmos.setWeather("clear"); SET.weather = "clear"; }
72
+ }
73
+ }
74
  let police, races, nav, legion = null;
75
  const net = createNet(); lt("net");
76
  setInterval(() => { if (document.hidden) net.tick(.5, null); }, 500); // a hosting tab in the background still relays everyone
 
79
  const GPU = (() => { try { const c = renderer.getContext(), e = c.getExtension("WEBGL_debug_renderer_info"); return e ? c.getParameter(e.UNMASKED_RENDERER_WEBGL) : ""; } catch { return ""; } })();
80
  const STRONG = /RTX|GTX 1[06-9]|GTX 9[78]|Radeon RX|Radeon Pro|Apple M[1-9]/i.test(GPU) && !COARSE;
81
  const TOP = /RTX\s?(40[6-9]0|50[5-9]0)|RTX\s?A?[45]\d{3}/i.test(GPU) && !COARSE; // recent RTX cards start on Ultra
82
+ const SET = Object.assign({ q: LITE ? "lite" : TOP ? "ultra" : STRONG ? "high" : COARSE ? "low" : "medium", sens: 1, autogas: "off", steer: "stick", weather: "clear", radio: "score", cycle: "on", handling: "arcade", motion: "on", text: "normal", board: "ion", crowd: LITE ? "few" : "normal", fps: "off", voice: "open" }, store.get("void.settings") || {});
83
  const gameOpts = {
84
  handling: () => SET.handling, buyFood: () => { if (cash < 10) return false; cash -= 10; store.set("void.cash", cash); earn(0); return true; }, heroOwned: () => !!store.get("void.hero"), starter: () => { const m = life.models.find(m => m.id === "compact-3") || life.models.find(m => m.kind.id === "compact"); return { model: { ...m, top: 31, acc: .7, grip: .9 }, color: 0x6b5a44, rust: .75, owned: true }; }, onSteal: c => { police && police.event("steal"); goals.stats.steals = (goals.stats.steals || 0) + 1; },
85
  garage: () => openGarage(true), cycleTime, hornType: () => build.horn, autoGas: () => SET.autogas === "on", onRepair: () => car.repair && car.repair(),
86
  props: (x, z, y, vel) => legion && legion.props(x, z, y, vel),
87
+ tunnel: (x, z, y) => legion ? legion.tunnel(x, z, y) : null, pads: () => legion ? ZONES.concat(legion.pads()) : ZONES, onLand: (g, d) => legion && legion.onLand(g, d),
88
  onScore: (n, why, pts) => { if (legion) legion.onScore(why, pts ?? n); if (/^Drift/.test(why)) goals.drift(n); if (/^(🥇|🥈|🥉)/.test(why)) goals.stats.meds = (goals.stats.meds || 0) + 1; { const gm = /^Grind (\d+) m/.exec(why); if (gm) goals.stats.grind = (goals.stats.grind || 0) + +gm[1]; const sp = /^(\d+)( |$)/.exec(why); if (sp && +sp[1] >= 720) goals.stats.b720 = 1; if (/Kickflip|Heelflip/.test(why) && / \+ /.test(why)) goals.stats.combo = (goals.stats.combo || 0) + 1; } goals.note(why); earn(pts ?? n); },
89
  onSmash: kind => police && police.event("smash", kind), policeClear: () => police && police.clear(),
90
  autopilot: (g, dt, over) => nav ? nav.controls(g, dt, over) : null, openGps: () => document.getElementById("gGpsBtn").click(),
 
94
  if (police) for (const c of police.cops) if (c.on) { const [a, b] = P(c.x, c.z); mx.fillStyle = Math.sin(performance.now() / 90) > 0 ? "#ff3040" : "#3060ff"; mx.beginPath(); mx.arc(a, b, 4, 0, 7); mx.fill(); }
95
  if (races && races.race && races.race.next) { const [a, b] = P(races.race.next[0], races.race.next[2]); mx.strokeStyle = "#ffd23d"; mx.lineWidth = 3; mx.beginPath(); mx.arc(a, b, 7, 0, 7); mx.stroke(); }
96
  for (const r of remotes.values()) if (r.at) { const [a, b] = P(r.at.x, r.at.z); mx.fillStyle = "#c07dff"; mx.beginPath(); mx.arc(a, b, 4.5, 0, 7); mx.fill(); }
97
+ const inView = (a, b) => Math.abs(a) < 92 && Math.abs(b) < 92;
98
+ // police sight cones (where each cruiser is looking), race starts, hidden coins close by, taxi passengers and the drop-off
99
+ if (police) for (const c of police.cops) if (c.on && !c.wreck) { const [a, b] = P(c.x, c.z); mx.fillStyle = "rgba(255,60,70,.22)"; mx.beginPath(); mx.moveTo(a, b); mx.arc(a, b, 26, c.yaw - .5, c.yaw + .5); mx.closePath(); mx.fill(); }
100
+ if (races) for (const st of races.starts) { const [a, b] = P(st.x, st.z); if (!inView(a, b)) continue; mx.fillStyle = "#fff"; mx.fillRect(a - 3, b - 3, 3, 3); mx.fillRect(a, b, 3, 3); mx.fillStyle = "#111"; mx.fillRect(a, b - 3, 3, 3); mx.fillRect(a - 3, b, 3, 3); }
101
+ {
102
+ mx.fillStyle = "#ffc23d"; for (const [x, z] of extras.coinsNear(g.x, g.z, 160)) { const [a, b] = P(x, z); mx.beginPath(); mx.arc(a, b, 2.6, 0, 7); mx.fill(); }
103
+ const tx = extras.taxi(); if (tx.on) { for (const [x, z, vip] of tx.waiting) { const [a, b] = P(x, z); mx.fillStyle = vip ? "#d84dff" : "#ffd23d"; mx.beginPath(); mx.arc(a, b, 4, 0, 7); mx.fill(); } if (tx.fare) { const [a, b] = P(tx.fare.x, tx.fare.z); mx.strokeStyle = "#3dff8a"; mx.lineWidth = 2.5; mx.beginPath(); mx.arc(a, b, 6, 0, 7); mx.stroke(); } }
104
+ }
105
+ // rooftop stunt pads, paint shops, the secret tunnel (dashed), the Sky Park
106
+ if (legion) {
107
+ const L = legion.mapData(); mx.lineWidth = 2;
108
+ for (const t of L.targets) { const [a, b] = P(t.x, t.z); if (!inView(a, b)) continue; mx.strokeStyle = t.done ? "#777" : "#ff3df0"; mx.beginPath(); mx.arc(a, b, 5, 0, 7); mx.stroke(); mx.beginPath(); mx.arc(a, b, 1.5, 0, 7); mx.stroke(); }
109
+ mx.font = "12px sans-serif"; mx.textAlign = "center"; for (const sh of L.shops) { const [a, b] = P(sh.x, sh.z); if (!inView(a, b)) continue; mx.save(); mx.translate(a, b); mx.rotate(g.yaw + Math.PI / 2); mx.fillText("🎨", 0, 4); mx.restore(); }
110
+ const T = L.tunnel, [ta, tb] = P(T.a0, T.z), [tc, td] = P(T.b1, T.z); mx.setLineDash([5, 4]); mx.strokeStyle = "#3df5ff"; mx.lineWidth = 3; mx.beginPath(); mx.moveTo(ta, tb); mx.lineTo(tc, td); mx.stroke(); mx.setLineDash([]);
111
+ const [s0, s1] = P(-920, -1320), [s2, s3] = P(760, -760); mx.strokeStyle = "rgba(255,61,240,.7)"; mx.lineWidth = 2; mx.strokeRect(s0, s1, s2 - s0, s3 - s1);
112
+ }
113
  mx.font = "bold 12px sans-serif"; mx.textAlign = "center"; for (const st of W.city.stations) { const [a, b] = P(st.x, st.z); if (Math.abs(a) < 90 && Math.abs(b) < 90) { mx.save(); mx.translate(a, b); mx.rotate(g.yaw + Math.PI / 2); mx.fillText("⛽", 0, 4); mx.restore(); } }
114
  // VOID Motors: a gold "$" badge on every counter in view (beside the pump icon), and an arrow on the rim pointing at the nearest one when none is
115
  const dl = gameOpts.dealer; if (dl) { let seen = false; for (const st of dl.sites) { const [a, b] = P(st.x, st.z); if (Math.hypot(a, b) < 82) { seen = true; mx.save(); mx.translate(a, b); mx.rotate(g.yaw + Math.PI / 2); const ox = st.main ? 0 : 9, oy = st.main ? 0 : -9; mx.fillStyle = "#ffd23d"; mx.strokeStyle = "#000"; mx.lineWidth = 2; mx.beginPath(); mx.arc(ox, oy, 6.5, 0, 7); mx.fill(); mx.stroke(); mx.fillStyle = "#000"; mx.font = "900 10px sans-serif"; mx.textAlign = "center"; mx.fillText("$", ox, oy + 3.5); mx.restore(); } }
 
127
  document.getElementById("gStatsRow").innerHTML = `<div><b>${(S.best || 0).toLocaleString()}</b><span>Best score</span></div><div><b>${Math.round(S.top)}</b><span>Top km/h</span></div><div><b>${S.km.toFixed(1)}</b><span>km travelled</span></div><div><b>${goals.done.size}/${GOALS.length}</b><span>Trophies</span></div><div><b>$${cash.toLocaleString()}</b><span>Cash · spend in Garage</span></div>`;
128
  }
129
  const WX_ICON = { clear: "☀️ Clear", rain: "🌧 Rain", storm: "⛈ Storm", fog: "🌫 Fog", snow: "❄️ Snow" }, RADIO = { score: "🎵 VOID Score", synth: "🌆 Cyber Synth", chill: "🌙 Chill Night Drive", chase: "🔥 High-Octane Chase", voidfm: "📻 VOID FM", off: "🔇 Radio off" };
130
+ function chips() { document.getElementById("gChips").innerHTML = `<span>${{ night: "🌙", sunset: "🌇", dawn: "🌅", day: "☀️" }[W.timeOfDay]} ${W.timeOfDay}</span><span>${WX_ICON[atmos.weather]}</span>`; document.getElementById("gWeather").innerHTML = `<b>${WX_ICON[SET.weather].split(" ")[0]}</b>${WX_ICON[SET.weather].split(" ").slice(1).join(" ")}`; document.getElementById("gRadio").innerHTML = `<b>${RADIO[SET.radio].split(" ")[0]}</b>${RADIO[SET.radio].split(" ").slice(1).join(" ")}`; }
131
  document.getElementById("gWeather").onclick = () => { SET.weather = WEATHERS[(WEATHERS.indexOf(SET.weather) + 1) % WEATHERS.length]; atmos.setWeather(SET.weather); store.set("void.settings", SET); chips(); toast(WX_ICON[SET.weather]); };
132
  document.getElementById("gRadio").onclick = () => { const k = Object.keys(RADIO); SET.radio = k[(k.indexOf(SET.radio) + 1) % k.length]; if (!sound.on) setSound(true); sound.setRadio(SET.radio); store.set("void.settings", SET); chips(); toast(RADIO[SET.radio]); };
133
  // ---------- the menu (☰ or Esc): everything that isn't driving lives here ----------
 
648
  W.city.poolMat.opacity = W.timeOfDay === "night" ? 1 : W.timeOfDay === "sunset" ? .45 : 0; W.city.poolMat.visible = W.timeOfDay !== "day";
649
  extras.sky(dt, time);
650
  // the living city: when switched on, the day turns and the weather changes on its own
651
+ if (SET.cycle === "on" && mode === "play") dayTurn(dt);
652
  life.raining = atmos.weather === "rain" || atmos.weather === "storm"; life.night = W.timeOfDay !== "day";
653
  // the El train is solid: you get shoved off the track (and hurt if you hit it hard)
654
  if (mode === "play" && W.city.el && game.state) { const T = W.city.el.train, s = game.state; if (Math.abs(s.x - W.city.el.x) < 2.6 && s.y > W.city.el.top - .5 && s.y < W.city.el.top + 4 && Math.abs(s.z - T.z) < T.len / 2 + 1) { s.x = W.city.el.x + (s.x >= W.city.el.x ? 3 : -3); const sp = Math.hypot(s.vel.x, s.vel.z); if (sp > 8 || T.v > 5) { game.api.hurt(8 + T.v, "Hit by the train"); sound.crash(); } } }
 
763
  });
764
  if (parts.length) { const geo = mergeGeometries(parts); geo.translate(0, -.02, 0); life.setVoidGeo(geo); life.setVoidDetail(W.quality !== "lite"); window.__voidTris = geo.attributes.position.count / 3; }
765
  } catch (e) { console.warn("VOID flyers keep the simple shape", e); }
766
+ // a paint shop's free respray: a new colour (never the same one) and a random finish
767
+ function respray() { const P = OPTS.paint.items; let k = build.paint; for (let t = 0; t < 10 && k === build.paint; t++) k = Math.floor(Math.random() * P.length); build.paint = k; build.finish = Math.floor(Math.random() * OPTS.finish.items.length); applyBuild(); return P[k][0]; }
768
  legion = createLegion({ W, game, sound, store, life, COARSE, races: () => races, nav: () => nav, dealer: () => dealer, radioNext: () => document.getElementById("gRadio").click(),
769
+ respray, paintHex: () => parseInt(OPTS.paint.items[build.paint][1].replace("#", ""), 16), stars: () => police.stars, policeClear: () => police.clear(), extras: () => extras,
770
  trailColor: () => { const v = OPTS.glow.items[build.glow][1]; return v ? new THREE.Color(v).toArray() : [1, .2, .85]; } });
771
  setLoad(95);
772
  await precompile(); lt("compile");
static/police.js CHANGED
@@ -1,7 +1,9 @@
1
  // Police chases: smash traffic or speed past a cop and you get wanted stars. Cruisers spawn out of sight and hunt
2
  // you through the street grid (straight at you when the road is clear, round the blocks when it isn't), ram you,
3
  // and box you in: stop near them for a few seconds and you are busted. Lose them for long enough and the stars
4
- // fall away. From three stars a helicopter joins in with a searchlight, so flying away is not a free escape.
 
 
5
  // Also: the AI driver that the street racers use.
6
  import * as THREE from "three";
7
  import { GRID } from "./city.js";
@@ -67,6 +69,36 @@ export function createPolice(scene, api, sound, life) {
67
  heli.visible = false; scene.add(heli);
68
  }
69
  const H = { on: false, x: 0, y: 80, z: 0, yaw: 0 };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  let heat = 0, stars = 0, evade = 0, bust = 0, speedT = 0, cool = 0;
71
  const starsOf = h => { let s = 0; for (let k = 1; k < HEAT.length; k++) if (h >= HEAT[k]) s = k; return s; };
72
  function addHeat(n, why) {
@@ -88,6 +120,7 @@ export function createPolice(scene, api, sound, life) {
88
  heat = 0; stars = 0; evade = 0; bust = 0;
89
  for (const c of cops) { c.on = false; c.g.visible = false; }
90
  H.on = false; heli.visible = false; if (msg) api.say(msg, 3);
 
91
  }
92
  return {
93
  get stars() { return stars; }, get bust() { return bust; }, cops, clear,
@@ -150,6 +183,32 @@ export function createPolice(scene, api, sound, life) {
150
  heli.beam.lookAt(p.x, p.y, p.z); heli.beam.rotateX(-Math.PI / 2); heli.spot.intensity = d < 160 ? 900 : 0; heli.spot.position.set(H.x, H.y - 1.5, H.z); heli.spot.target.position.set(p.x, p.y, p.z); heli.spot.target.updateMatrixWorld();
151
  if (d < 120) nearest = Math.min(nearest, d * .5);
152
  } else if (H.on) { H.on = false; heli.visible = false; heli.spot.intensity = 0; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153
  // busted: stopped with a cruiser right beside you
154
  if (close && ps < 4 && !air) { bust += dt; if (bust > 3) { const lost = Math.round(p.score * .15); p.score -= lost; api.busted(`BUSTED! The police fined you ${lost} points`); clear(); return; } } else bust = Math.max(0, bust - dt * 2);
155
  // losing them
 
1
  // Police chases: smash traffic or speed past a cop and you get wanted stars. Cruisers spawn out of sight and hunt
2
  // you through the street grid (straight at you when the road is clear, round the blocks when it isn't), ram you,
3
  // and box you in: stop near them for a few seconds and you are busted. Lose them for long enough and the stars
4
+ // fall away. From three stars a helicopter joins in with a searchlight and roadblocks go up ahead of you (two cruisers
5
+ // and an EMP strip that kills your engine for a moment); at five stars pursuit drones chase you even in the air, firing
6
+ // EMP pulses (ram one to bring it down).
7
  // Also: the AI driver that the street racers use.
8
  import * as THREE from "three";
9
  import { GRID } from "./city.js";
 
69
  heli.visible = false; scene.add(heli);
70
  }
71
  const H = { on: false, x: 0, y: 80, z: 0, yaw: 0 };
72
+ // ---- roadblocks: two cruisers parked across the road and an EMP strip in front of them ----
73
+ const empMat = new THREE.MeshBasicMaterial({ color: new THREE.Color(.3, .9, 2.6), toneMapped: false, transparent: true, opacity: .85, depthWrite: false });
74
+ const blocks = [0, 1].map(() => {
75
+ const g = new THREE.Group(), strip = new THREE.Mesh(new THREE.BoxGeometry(1.4, .06, 15), empMat); strip.position.set(-9, .06, 0); g.add(strip);
76
+ const bars = [];
77
+ for (const sd of [-1, 1]) {
78
+ const c = new THREE.Group(), body = new THREE.Mesh(geo.body, bodyMat), lights = new THREE.Mesh(geo.lights, lightMat), rr = new THREE.Mesh(new THREE.BoxGeometry(.32, .18, .5), red), bb = new THREE.Mesh(new THREE.BoxGeometry(.32, .18, .5), blue);
79
+ rr.position.set(-.2, 1.82, .32); bb.position.set(-.2, 1.82, -.32); body.castShadow = true; c.add(body, lights, rr, bb); c.position.set(0, 0, sd * 3.2); c.rotation.y = Math.PI / 2 + sd * .3; g.add(c); bars.push([rr, bb]);
80
+ }
81
+ g.visible = false; scene.add(g); return { g, bars, on: false, x: 0, z: 0, yaw: 0, t: 0, hit: false };
82
+ });
83
+ let blockT = 6;
84
+ function placeBlock(B, p) {
85
+ const fx = Math.cos(p.yaw), fz = Math.sin(p.yaw), alongX = Math.abs(fx) > Math.abs(fz);
86
+ let x = p.x + fx * 190, z = p.z + fz * 190;
87
+ if (alongX) { z = GRID.sz(clamp(Math.round((p.z - GRID.Z0) / GRID.ST), 0, GRID.NZ - 1)); } else { x = GRID.ax(clamp(Math.round((p.x - GRID.X0) / GRID.AV), 0, GRID.NX - 1)); }
88
+ if (api.hitBox(x, z, .5, 4) || api.isWater(x, z)) return;
89
+ Object.assign(B, { on: true, x, z, yaw: alongX ? (fx > 0 ? 0 : Math.PI) : (fz > 0 ? Math.PI / 2 : -Math.PI / 2), t: 40, hit: false });
90
+ B.g.position.set(x, 0, z); B.g.rotation.y = -B.yaw; B.g.visible = true; api.say("🚧 Roadblock ahead!", 2);
91
+ }
92
+ // ---- pursuit drones (five stars): four rotors, a red eye, and an EMP pulse when they get close ----
93
+ const droneMat = new THREE.MeshStandardMaterial({ color: 0x15181f, metalness: .6, roughness: .35 }), boltMat = new THREE.MeshBasicMaterial({ color: new THREE.Color(.5, 1.2, 3), toneMapped: false, transparent: true, opacity: .9, depthWrite: false });
94
+ const drones = [0, 1, 2].map(k => {
95
+ const g = new THREE.Group(); g.add(new THREE.Mesh(new THREE.BoxGeometry(1.3, .35, 1.3), droneMat));
96
+ for (const [x, z] of [[1, 1], [-1, 1], [1, -1], [-1, -1]]) { const rotor = new THREE.Mesh(new THREE.CylinderGeometry(.5, .5, .04, 14), droneMat); rotor.position.set(x, .22, z); g.add(rotor); }
97
+ const eye = new THREE.Mesh(new THREE.SphereGeometry(.2, 8, 6), red); eye.position.set(.7, 0, 0); g.add(eye);
98
+ const tag = new THREE.Mesh(new THREE.BoxGeometry(.2, .12, .6), blue); tag.position.set(-.5, .25, 0); g.add(tag);
99
+ const bolt = new THREE.Mesh(new THREE.CylinderGeometry(.08, .08, 1, 6).translate(0, .5, 0), boltMat); bolt.visible = false; scene.add(bolt);
100
+ g.visible = false; scene.add(g); return { g, bolt, on: false, x: 0, y: 0, z: 0, vx: 0, vy: 0, vz: 0, shotT: 3 + k, boltT: 0, down: 0, ph: k * 2.1 };
101
+ });
102
  let heat = 0, stars = 0, evade = 0, bust = 0, speedT = 0, cool = 0;
103
  const starsOf = h => { let s = 0; for (let k = 1; k < HEAT.length; k++) if (h >= HEAT[k]) s = k; return s; };
104
  function addHeat(n, why) {
 
120
  heat = 0; stars = 0; evade = 0; bust = 0;
121
  for (const c of cops) { c.on = false; c.g.visible = false; }
122
  H.on = false; heli.visible = false; if (msg) api.say(msg, 3);
123
+ for (const B of blocks) { B.on = false; B.g.visible = false; } for (const d of drones) { d.on = false; d.g.visible = false; d.bolt.visible = false; }
124
  }
125
  return {
126
  get stars() { return stars; }, get bust() { return bust; }, cops, clear,
 
183
  heli.beam.lookAt(p.x, p.y, p.z); heli.beam.rotateX(-Math.PI / 2); heli.spot.intensity = d < 160 ? 900 : 0; heli.spot.position.set(H.x, H.y - 1.5, H.z); heli.spot.target.position.set(p.x, p.y, p.z); heli.spot.target.updateMatrixWorld();
184
  if (d < 120) nearest = Math.min(nearest, d * .5);
185
  } else if (H.on) { H.on = false; heli.visible = false; heli.spot.intensity = 0; }
186
+ // roadblocks from three stars: one goes up ahead of you every so often
187
+ if (stars >= 3 && !air && (blockT -= dt) < 0) { blockT = 18 + Math.random() * 10; const B = blocks.find(b => !b.on); if (B) placeBlock(B, p); }
188
+ for (const B of blocks) {
189
+ if (!B.on) continue;
190
+ const flash = Math.sin(time * 16 + B.x) > 0; for (const [rr, bb] of B.bars) { rr.visible = flash; bb.visible = !flash; }
191
+ const dx = p.x - B.x, dz = p.z - B.z, along = dx * Math.cos(B.yaw) + dz * Math.sin(B.yaw), side = -dx * Math.sin(B.yaw) + dz * Math.cos(B.yaw);
192
+ if (!B.hit && p.mode === "drive" && p.y < 2 && Math.abs(along + 9) < 1.3 && Math.abs(side) < 7.5) { B.hit = true; api.emp && api.emp(1.8); }
193
+ if (p.y < 2.5 && Math.abs(along) < 2.8 && Math.abs(Math.abs(side) - 3.2) < 2.8 && ps > 3) { const rel = ps; api.hurt(4 + rel * .5, "Hit the roadblock"); p.vel.multiplyScalar(-.25); p.x -= Math.cos(B.yaw) * 1.5; p.z -= Math.sin(B.yaw) * 1.5; sound.crash(); api.impact && api.impact(p.x, p.z, rel); }
194
+ if ((B.t -= dt) < 0 || along > 140) { B.on = false; B.g.visible = false; }
195
+ nearest = Math.min(nearest, Math.hypot(dx, dz) + 60);
196
+ }
197
+ // drones at five stars: they find you anywhere, even flying, and fire EMP pulses from close up
198
+ for (const d of drones) {
199
+ d.boltT = Math.max(0, d.boltT - dt); d.bolt.visible = d.boltT > 0;
200
+ if (stars < 5) { if (d.on) { d.on = false; d.g.visible = false; } continue; }
201
+ if (d.down > 0) { d.down -= dt; d.vy -= 9.81 * dt; d.y = Math.max(0, d.y + d.vy * dt); d.g.position.set(d.x, d.y, d.z); d.g.rotation.x += dt * 6; if (d.down <= 0) { d.on = false; d.g.visible = false; } continue; }
202
+ if (!d.on) { const a = p.yaw + Math.PI + (Math.random() - .5); Object.assign(d, { on: true, x: p.x + Math.cos(a) * 140, y: p.y + 30, z: p.z + Math.sin(a) * 140, vx: 0, vy: 0, vz: 0 }); d.g.visible = true; d.g.rotation.set(0, 0, 0); if (d === drones[0]) api.say("🛸 Police drones!", 2.5); }
203
+ const ang = time * .9 + d.ph, tx = p.x + Math.cos(ang) * 14 + p.vel.x * .6, ty = Math.max(p.y + 6, 4), tz = p.z + Math.sin(ang) * 14 + p.vel.z * .6;
204
+ const ax = (tx - d.x) * 2.2 - d.vx * 1.6, ay = (ty - d.y) * 2.2 - d.vy * 1.6, az = (tz - d.z) * 2.2 - d.vz * 1.6;
205
+ d.vx += ax * dt; d.vy += ay * dt; d.vz += az * dt; const sp = Math.hypot(d.vx, d.vy, d.vz); if (sp > 80) { d.vx *= 80 / sp; d.vy *= 80 / sp; d.vz *= 80 / sp; }
206
+ d.x += d.vx * dt; d.y += d.vy * dt; d.z += d.vz * dt;
207
+ d.g.position.set(d.x, d.y, d.z); d.g.rotation.set(Math.min(.4, Math.hypot(d.vx, d.vz) / 160), -Math.atan2(d.vz, d.vx), 0, "YXZ");
208
+ const dd = Math.hypot(p.x - d.x, p.y - d.y, p.z - d.z); nearest = Math.min(nearest, dd);
209
+ if ((d.shotT -= dt) < 0 && dd < 28) { d.shotT = 6 + Math.random() * 3; api.emp && api.emp(1.2); d.boltT = .18; d.bolt.position.set(d.x, d.y, d.z); d.bolt.scale.set(1, dd, 1); d.bolt.lookAt(p.x, p.y, p.z); d.bolt.rotateX(Math.PI / 2); }
210
+ if (dd < 4.2 && ps > 22) { d.down = 2.5; d.vy = 4; api.addScore(500, "Drone down!"); sound.crash(); }
211
+ }
212
  // busted: stopped with a cruiser right beside you
213
  if (close && ps < 4 && !air) { bust += dt; if (bust > 3) { const lost = Math.round(p.score * .15); p.score -= lost; api.busted(`BUSTED! The police fined you ${lost} points`); clear(); return; } } else bust = Math.max(0, bust - dt * 2);
214
  // losing them
static/sound.js CHANGED
@@ -226,6 +226,11 @@ export class Sound {
226
  this.env(g, t, .004, 1.1, 1.6); o.connect(g).connect(this.musicIn); o.start(t); o.stop(t + 1.7);
227
  this.noiseHit(t, "lowpass", 6000, .5, .55, 1.5, this.musicIn);
228
  }
 
 
 
 
 
229
  // a body thud scaled by how hard you hit (walls, landings)
230
  thud(p = .5) { if (!this.on) return; const t = this.ctx.currentTime, k = Math.min(1, p); this.noiseHit(t, "lowpass", 400 + k * 1600, .7, .35 + k * .65, .15 + k * .4, this.sfx); if (k > .5) this.noiseHit(t + .01, "bandpass", 2600, 1.2, (k - .5) * .7, .25, this.sfx); }
231
  whoosh() { if (this.on) this.noiseHit(this.ctx.currentTime, "bandpass", 700, .8, .5, .9, this.sfx); }
 
226
  this.env(g, t, .004, 1.1, 1.6); o.connect(g).connect(this.musicIn); o.start(t); o.stop(t + 1.7);
227
  this.noiseHit(t, "lowpass", 6000, .5, .55, 1.5, this.musicIn);
228
  }
229
+ // the coin chime: a soft bell, higher the closer you are
230
+ chime(fr) {
231
+ if (!this.on || !this.ctx || this.ctx.state !== "running") return; const C = this.ctx, t = C.currentTime, o = C.createOscillator(), g = C.createGain();
232
+ o.type = "sine"; o.frequency.setValueAtTime(fr, t); this.env(g, t, .004, .16, .35); o.connect(g).connect(this.sfx); o.start(t); o.stop(t + .4);
233
+ }
234
  // a body thud scaled by how hard you hit (walls, landings)
235
  thud(p = .5) { if (!this.on) return; const t = this.ctx.currentTime, k = Math.min(1, p); this.noiseHit(t, "lowpass", 400 + k * 1600, .7, .35 + k * .65, .15 + k * .4, this.sfx); if (k > .5) this.noiseHit(t + .01, "bandpass", 2600, 1.2, (k - .5) * .7, .25, this.sfx); }
236
  whoosh() { if (this.on) this.noiseHit(this.ctx.currentTime, "bandpass", 700, .8, .5, .9, this.sfx); }
static/world.js CHANGED
@@ -36,7 +36,10 @@ export async function createWorld(canvas, COARSE) {
36
  night: { stops: [[0, "#060b18"], [.4, "#13203d"], [.55, "#2c3a63"], [.63, "#6a5a7a"], [.7, "#2a2d3c"], [1, "#1a1c24"]], fog: 0x2c3550, hemi: [0x9fb0d8, 0x22242c, 1.0], sun: [0x9fb4ff, .55], exp: 1.15, glow: 1, stars: true, sunPos: [-300, 420, -500] },
37
  sunset: { stops: [[0, "#1d2a55"], [.35, "#4a4a8a"], [.5, "#c46a6a"], [.58, "#ff9a4a"], [.64, "#ffd27a"], [.7, "#6a5048"], [1, "#2a2420"]], fog: 0x8a6a6a, hemi: [0xffc8a8, 0x3a3030, 1.2], sun: [0xffa860, 2.4], exp: 1.1, glow: .55, stars: false, sunPos: [-800, 160, -300] },
38
  day: { stops: [[0, "#2a6ad0"], [.4, "#5a9ae8"], [.58, "#a8d0f4"], [.66, "#e4eef6"], [.7, "#9aa4ac"], [1, "#6a7078"]], fog: 0xb8cce0, hemi: [0xdfeeff, 0x6a7a5a, 1.5], sun: [0xfff4e0, 3.2], exp: 1.0, glow: .12, stars: false, sunPos: [-400, 700, -350] },
 
39
  };
 
 
40
  // (a new texture each time: three caches the cube it makes from an equirect background)
41
  let skyTex = null;
42
  const paintSky = k => {
@@ -126,27 +129,41 @@ export async function createWorld(canvas, COARSE) {
126
  }
127
  let timeOfDay = "night", wxDim = 1, wxOver = false, hemiBase = 1;
128
  const sunDir = new THREE.Vector3(-300, 420, -500).normalize();
129
- function setTime(k) {
130
- const S = SKIES[k]; timeOfDay = k; paintSky(k);
 
 
 
 
 
 
 
 
131
  sky.visible = k !== "night" && !wxOver;
132
- if (wxOver) { // overcast: a flat grey sky (darker at night)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
133
  const c = document.createElement("canvas"); c.width = 4; c.height = 512; const g2 = c.getContext("2d"), gr = g2.createLinearGradient(0, 0, 0, 512);
134
  const top = k === "night" ? "#0d1016" : k === "sunset" ? "#4a4650" : "#7c838e", mid = k === "night" ? "#1d222b" : k === "sunset" ? "#7a6a6a" : "#a9b0b8";
135
  gr.addColorStop(0, top); gr.addColorStop(.6, mid); gr.addColorStop(1, top); g2.fillStyle = gr; g2.fillRect(0, 0, 4, 512);
136
  if (skyTex) skyTex.dispose(); skyTex = new THREE.CanvasTexture(c); skyTex.colorSpace = THREE.SRGBColorSpace; skyTex.mapping = THREE.EquirectangularReflectionMapping; scene.background = skyTex;
137
  }
138
- if (sky.visible) { skyU.turbidity.value = k === "day" ? 3 : 8; skyU.rayleigh.value = k === "day" ? 1.2 : 2.8; skyU.mieCoefficient.value = k === "day" ? .004 : .008; skyU.mieDirectionalG.value = .85; skyU.sunPosition.value.set(...S.sunPos).normalize(); }
139
- scene.fog.color.setHex(S.fog); hemi.color.setHex(S.hemi[0]); hemi.groundColor.setHex(S.hemi[1]); hemi.intensity = S.hemi[2];
140
- sun.color.setHex(S.sun[0]); sun.intensity = S.sun[1]; sunDir.set(...S.sunPos).normalize();
141
- hemi.intensity *= wxDim; sun.intensity *= wxDim * wxDim; hemiBase = hemi.intensity;
142
- if (wxOver) scene.fog.color.lerp(new THREE.Color(k === "night" ? 0x151820 : 0x8a919a), .7);
143
- renderer.toneMappingExposure = S.exp; stars.visible = S.stars && !wxOver; key.intensity = k === "day" ? .4 : 1.1;
144
- for (const m of city.emissive) {
145
- if (m.isMeshStandardMaterial) { if (m.userData.base0 == null) m.userData.base0 = m.emissiveIntensity; m.emissiveIntensity = m.userData.base0 * S.glow; }
146
- else { if (!m.userData.base0) m.userData.base0 = m.color.clone(); m.color.copy(m.userData.base0).multiplyScalar(Math.max(.55, S.glow)); }
147
- }
148
- bloom.strength = k === "day" ? .18 : k === "sunset" ? .32 : .42;
149
- captureCity();
150
  }
151
  // quality: Low / Medium / High / Ultra (the adaptive system steps it down by itself when frames run slow)
152
  const QUALITY = { lite: { pr: .7, shadow: 0, bloom: false, grade: false, msaa: 0, bres: .25, shEvery: 9, flat: true }, low: { pr: .75, shadow: 0, bloom: false, grade: false, msaa: 0, bres: .25 }, medium: { pr: 1, shadow: 1024, bloom: true, grade: true, msaa: 0, bres: .3, shEvery: 4 }, high: { pr: 1.25, shadow: 2048, bloom: true, grade: true, msaa: 4, bres: .5, shEvery: 3 }, ultra: { pr: 2, shadow: 4096, bloom: true, grade: true, msaa: 4, bres: .5, shEvery: 2 } };
@@ -164,7 +181,7 @@ export async function createWorld(canvas, COARSE) {
164
  for (const t of [composer.renderTarget1, composer.renderTarget2]) if (t.samples !== Q.msaa) { t.samples = Q.msaa; t.dispose(); }
165
  return Math.min(devicePixelRatio || 1, Q.pr);
166
  }
167
- function setWeatherLook(dim, over) { wxDim = dim; wxOver = over; setTime(timeOfDay); }
168
  function setFlash(f) { hemi.intensity = hemiBase + f * 5; }
169
  function follow(p) { sun.position.copy(p).addScaledVector(sunDir, 600); sun.target.position.copy(p); sun.target.updateMatrixWorld(); }
170
 
@@ -256,7 +273,7 @@ export async function createWorld(canvas, COARSE) {
256
  for (let i = 0; i < 90; i++) { const s = new THREE.Sprite(new THREE.SpriteMaterial({ map: smokeTex, transparent: true, depthWrite: false, opacity: 0 })); s.visible = false; scene.add(s); puffs.push({ s, life: 0, v: new THREE.Vector3() }); }
257
 
258
  return {
259
- renderer, scene, camera, composer, bloom, grade, sky, sunDir, setWeatherLook, setFlash, weatherFog: 1, setQuality, get quality() { return quality; }, QUALITY, get bloomRes() { return W0.bres; }, camLight, canvasTex, radial, buildings, city, setTime, follow, captureCity, get timeOfDay() { return timeOfDay; }, studioEnv,
260
  roads: city.roads, footprints: city.footprints, parks: city.parks, water: city.water, beaches: city.beaches, walkways: city.walkways, bounds: city.bounds, credit: city.credit,
261
  track: { P, F, S, U, D, N, loopIn, loopOut, rampIn, roadEnd, idxX, sample },
262
  fx: { shadow, glow, lines, LINES, lineSeed, puffs, puffI: 0 },
 
36
  night: { stops: [[0, "#060b18"], [.4, "#13203d"], [.55, "#2c3a63"], [.63, "#6a5a7a"], [.7, "#2a2d3c"], [1, "#1a1c24"]], fog: 0x2c3550, hemi: [0x9fb0d8, 0x22242c, 1.0], sun: [0x9fb4ff, .55], exp: 1.15, glow: 1, stars: true, sunPos: [-300, 420, -500] },
37
  sunset: { stops: [[0, "#1d2a55"], [.35, "#4a4a8a"], [.5, "#c46a6a"], [.58, "#ff9a4a"], [.64, "#ffd27a"], [.7, "#6a5048"], [1, "#2a2420"]], fog: 0x8a6a6a, hemi: [0xffc8a8, 0x3a3030, 1.2], sun: [0xffa860, 2.4], exp: 1.1, glow: .55, stars: false, sunPos: [-800, 160, -300] },
38
  day: { stops: [[0, "#2a6ad0"], [.4, "#5a9ae8"], [.58, "#a8d0f4"], [.66, "#e4eef6"], [.7, "#9aa4ac"], [1, "#6a7078"]], fog: 0xb8cce0, hemi: [0xdfeeff, 0x6a7a5a, 1.5], sun: [0xfff4e0, 3.2], exp: 1.0, glow: .12, stars: false, sunPos: [-400, 700, -350] },
39
+ dawn: { stops: [[0, "#24305c"], [.4, "#5a5c96"], [.52, "#c88aa8"], [.6, "#ffc0a0"], [.66, "#ffe6c2"], [.7, "#6a5a60"], [1, "#2a2630"]], fog: 0x9a8a9c, hemi: [0xffd4cc, 0x3a3440, 1.15], sun: [0xffbe96, 1.9], exp: 1.08, glow: .7, stars: false, sunPos: [760, 150, 320] },
40
  };
41
+ // the sky shader, bloom and the fill light for each time of day (blended between them as the day turns)
42
+ const SKYU = { day: [3, 1.2, .004], sunset: [8, 2.8, .008], dawn: [6, 2.2, .006] }, BLOOM = { day: .18, sunset: .32, dawn: .3, night: .42 }, KEYL = { day: .4, sunset: 1.1, dawn: .8, night: 1.1 };
43
  // (a new texture each time: three caches the cube it makes from an equirect background)
44
  let skyTex = null;
45
  const paintSky = k => {
 
129
  }
130
  let timeOfDay = "night", wxDim = 1, wxOver = false, hemiBase = 1;
131
  const sunDir = new THREE.Vector3(-300, 420, -500).normalize();
132
+ function setTime(k) { applySky(k, k, 0); captureCity(); }
133
+ // between two times of day: light, fog, exposure, the sun's path and the window glow all blend; the sun sinks to the
134
+ // horizon before night and rises from it after; the backdrop switches halfway and the reflections are re-shot at the end
135
+ function blendTime(a, b, t) { applySky(a, b, Math.min(1, t)); if (t >= 1) captureCity(); }
136
+ let bgKey = "";
137
+ const cA = new THREE.Color(), cB = new THREE.Color();
138
+ function applySky(a, b, t) {
139
+ const A = SKIES[a], B = SKIES[b], k = t < .5 ? a : b, S = SKIES[k], L = (x, y) => x + (y - x) * t, C = (x, y) => cA.setHex(x).lerp(cB.setHex(y), t);
140
+ timeOfDay = k;
141
+ if (bgKey !== k + wxOver) { bgKey = k + wxOver; paintSky(k); if (wxOver) overcast(k); }
142
  sky.visible = k !== "night" && !wxOver;
143
+ if (sky.visible) {
144
+ const ua = SKYU[a] || SKYU[b], ub = SKYU[b] || SKYU[a]; skyU.turbidity.value = L(ua[0], ub[0]); skyU.rayleigh.value = L(ua[1], ub[1]); skyU.mieCoefficient.value = L(ua[2], ub[2]); skyU.mieDirectionalG.value = .85;
145
+ const sp = b === "night" ? [A.sunPos[0], A.sunPos[1] * Math.max(0, 1 - 2 * t) - 8, A.sunPos[2]] : a === "night" ? [B.sunPos[0], B.sunPos[1] * Math.max(0, 2 * t - 1) - 8, B.sunPos[2]] : [L(A.sunPos[0], B.sunPos[0]), L(A.sunPos[1], B.sunPos[1]), L(A.sunPos[2], B.sunPos[2])];
146
+ skyU.sunPosition.value.set(...sp).normalize();
147
+ }
148
+ scene.fog.color.copy(C(A.fog, B.fog)); hemi.color.copy(C(A.hemi[0], B.hemi[0])); hemi.groundColor.copy(C(A.hemi[1], B.hemi[1])); hemi.intensity = L(A.hemi[2], B.hemi[2]);
149
+ sun.color.copy(C(A.sun[0], B.sun[0])); sun.intensity = L(A.sun[1], B.sun[1]); sunDir.set(L(A.sunPos[0], B.sunPos[0]), L(A.sunPos[1], B.sunPos[1]), L(A.sunPos[2], B.sunPos[2])).normalize();
150
+ hemi.intensity *= wxDim; sun.intensity *= wxDim * wxDim; hemiBase = hemi.intensity;
151
+ if (wxOver) scene.fog.color.lerp(cA.set(k === "night" ? 0x151820 : 0x8a919a), .7);
152
+ renderer.toneMappingExposure = L(A.exp, B.exp); stars.visible = S.stars && !wxOver; key.intensity = L(KEYL[a], KEYL[b]);
153
+ const glow = L(A.glow, B.glow);
154
+ for (const m of city.emissive) {
155
+ if (m.isMeshStandardMaterial) { if (m.userData.base0 == null) m.userData.base0 = m.emissiveIntensity; m.emissiveIntensity = m.userData.base0 * glow; }
156
+ else { if (!m.userData.base0) m.userData.base0 = m.color.clone(); m.color.copy(m.userData.base0).multiplyScalar(Math.max(.55, glow)); }
157
+ }
158
+ bloom.strength = L(BLOOM[a], BLOOM[b]);
159
+ }
160
+ function overcast(k) {
161
+ { // overcast: a flat grey sky (darker at night)
162
  const c = document.createElement("canvas"); c.width = 4; c.height = 512; const g2 = c.getContext("2d"), gr = g2.createLinearGradient(0, 0, 0, 512);
163
  const top = k === "night" ? "#0d1016" : k === "sunset" ? "#4a4650" : "#7c838e", mid = k === "night" ? "#1d222b" : k === "sunset" ? "#7a6a6a" : "#a9b0b8";
164
  gr.addColorStop(0, top); gr.addColorStop(.6, mid); gr.addColorStop(1, top); g2.fillStyle = gr; g2.fillRect(0, 0, 4, 512);
165
  if (skyTex) skyTex.dispose(); skyTex = new THREE.CanvasTexture(c); skyTex.colorSpace = THREE.SRGBColorSpace; skyTex.mapping = THREE.EquirectangularReflectionMapping; scene.background = skyTex;
166
  }
 
 
 
 
 
 
 
 
 
 
 
 
167
  }
168
  // quality: Low / Medium / High / Ultra (the adaptive system steps it down by itself when frames run slow)
169
  const QUALITY = { lite: { pr: .7, shadow: 0, bloom: false, grade: false, msaa: 0, bres: .25, shEvery: 9, flat: true }, low: { pr: .75, shadow: 0, bloom: false, grade: false, msaa: 0, bres: .25 }, medium: { pr: 1, shadow: 1024, bloom: true, grade: true, msaa: 0, bres: .3, shEvery: 4 }, high: { pr: 1.25, shadow: 2048, bloom: true, grade: true, msaa: 4, bres: .5, shEvery: 3 }, ultra: { pr: 2, shadow: 4096, bloom: true, grade: true, msaa: 4, bres: .5, shEvery: 2 } };
 
181
  for (const t of [composer.renderTarget1, composer.renderTarget2]) if (t.samples !== Q.msaa) { t.samples = Q.msaa; t.dispose(); }
182
  return Math.min(devicePixelRatio || 1, Q.pr);
183
  }
184
+ function setWeatherLook(dim, over) { wxDim = dim; wxOver = over; bgKey = ""; setTime(timeOfDay); }
185
  function setFlash(f) { hemi.intensity = hemiBase + f * 5; }
186
  function follow(p) { sun.position.copy(p).addScaledVector(sunDir, 600); sun.target.position.copy(p); sun.target.updateMatrixWorld(); }
187
 
 
273
  for (let i = 0; i < 90; i++) { const s = new THREE.Sprite(new THREE.SpriteMaterial({ map: smokeTex, transparent: true, depthWrite: false, opacity: 0 })); s.visible = false; scene.add(s); puffs.push({ s, life: 0, v: new THREE.Vector3() }); }
274
 
275
  return {
276
+ renderer, scene, camera, composer, bloom, grade, sky, sunDir, setWeatherLook, setFlash, weatherFog: 1, setQuality, get quality() { return quality; }, QUALITY, blendTime, get bloomRes() { return W0.bres; }, camLight, canvasTex, radial, buildings, city, setTime, follow, captureCity, get timeOfDay() { return timeOfDay; }, studioEnv,
277
  roads: city.roads, footprints: city.footprints, parks: city.parks, water: city.water, beaches: city.beaches, walkways: city.walkways, bounds: city.bounds, credit: city.credit,
278
  track: { P, F, S, U, D, N, loopIn, loopOut, rampIn, roadEnd, idxX, sample },
279
  fx: { shadow, glow, lines, LINES, lineSeed, puffs, puffI: 0 },