big update

This commit is contained in:
2026-11-18 15:18:38 +01:00
parent e0496fa089
commit 64c5b65543
39 changed files with 1938 additions and 367 deletions

View File

@@ -182,9 +182,9 @@
return M;
}
// shop: the robot is framed in the left column, not in the middle of the stage
const GARAGE_OFF_X = 455, GARAGE_OFF_Y = 16;
const GARAGE_OFF_X = 300, GARAGE_OFF_Y = 16; // robot centered in the free area left of the shop panel
// shop zoom: 0.6 = furthest out (the default, whole robot in frame), 1.9 = closest
const GZ_MIN = 0.6, GZ_MAX = 1.9, GZ_DEF = GZ_MIN;
const GZ_MIN = 0.6, GZ_MAX = 1.9, GZ_DEF = 0.72; // default framing of the robot in the shop
const box = (w, h, d, m) => { const o = new T.Mesh(new T.BoxGeometry(w, h, d), m); o.castShadow = true; o.receiveShadow = true; return o; };
const cyl = (r1, r2, h, m, seg = 20) => { const o = new T.Mesh(new T.CylinderGeometry(r1, r2, h, seg), m); o.castShadow = true; return o; };
@@ -237,6 +237,20 @@
return g;
}
// position the weapon-mount group from the robot's mount (front/back/left/right + height).
// weapons are built along +x; this turns that onto the chosen side and pulls side mounts in to the hull edge.
function placeMount(g, st, L, Wd) {
const th = -(st.mountA || 0), dx0 = ((st.mountAxis === 'wid' ? Wd : L) / 2) - L / 2;
g.rotation.y = th;
g.position.set(Math.cos(th) * dx0, st.mountUp || 0, -Math.sin(th) * dx0);
}
// pointer (client px) -> normalised device coords on the garage canvas
function ndcOf(canvas, cx, cy) {
const b = canvas.getBoundingClientRect();
return new T.Vector2(((cx - b.left) / b.width) * 2 - 1, -((cy - b.top) / b.height) * 2 + 1);
}
function buildRobot(build, paint) {
const m = mats(), st = RC.stats(build), P = RC.PARTS;
const ch = P[build.chassis], wh = P[build.wheels], ar = build.armour ? P[build.armour] : null;
@@ -245,7 +259,8 @@
const drawn = !!(paint.layer && paint.drawn); // own artwork: no stock stripes, painted armour
const accent = new T.MeshStandardMaterial({ color: paint.accent, metalness: 0.3, roughness: 0.45 });
const armour = ar ? (drawn ? body : new T.MeshStandardMaterial({ color: ar.tint, metalness: 0.9, roughness: 0.28 })) : null;
const root = new T.Group(), tilt = new T.Group();
const root = new T.Group();
let tilt = new T.Group(); // let: the weapon block points it at a mount group, then restores it
root.add(tilt);
const out = { root, tilt, body, skin, st, build, roll: 0, flash: 0, spinA: 0, sawA: 0, gunA: 0, smokeT: 0 };
const sk = (geo, w, h, d, y0) => { const o = new T.Mesh(skinUV(geo, w, d, h, y0), body); o.castShadow = o.receiveShadow = true; return o; };
@@ -459,18 +474,25 @@
mark('lights');
// main weapon (front = +x)
const w = st.weapon;
if (w) {
const WS = m.wsteel, ED = m.wedge, HZ = m.stripe; // weapon steel, edge, hazard stripe
// main weapons: each built facing +x, then rotated/moved to its mounted side + height
const WS = m.wsteel, ED = m.wedge, HZ = m.stripe; // weapon steel, edge, hazard stripe
out.weapons = []; out.st = st;
const _tilt = tilt;
for (let wi = 0; wi < (st.weapons || []).length; wi++) {
const inst = st.weapons[wi], w = inst.part, wo = {};
const wmount = new T.Group();
placeMount(wmount, { mountA: inst.mountA, mountAxis: inst.mountAxis, mountUp: inst.mountUp }, L, Wd);
_tilt.add(wmount); wo.wmount = wmount; out.weapons[wi] = wo;
tilt = wmount;
if (w.type === 'wedge') {
if (w.id === 'lance') {
// long spike lance on a sleeve - it thrusts forward when fired (poseRobot drives out.lance.position.x)
const g = new T.Group(); g.position.set(L / 2, c + H * 0.4, 0); g.userData.baseX = L / 2; tilt.add(g);
const sleeve = cyl(0.07, 0.08, 0.3, m.steel, 10); sleeve.rotation.z = Math.PI / 2; sleeve.position.x = -0.05; tilt.add(sleeve);
// long spike lance on a sleeve - retracted at rest, thrusts forward when fired (poseRobot drives out.lance.position.x)
const baseX = L / 2 - 0.45; // rest: tip sits just past the body, not poking far out
const g = new T.Group(); g.position.set(baseX, c + H * 0.4, 0); g.userData.baseX = baseX; tilt.add(g);
const sleeve = cyl(0.08, 0.1, 0.42, m.steel, 10); sleeve.rotation.z = Math.PI / 2; sleeve.position.set(L / 2 - 0.3, c + H * 0.4, 0); tilt.add(sleeve);
const shaft = cyl(0.05, 0.05, 0.85, m.dark, 8); shaft.rotation.z = Math.PI / 2; shaft.position.x = 0.42; g.add(shaft);
const tip = cyl(0.001, 0.13, 0.42, HZ, 12); tip.rotation.z = -Math.PI / 2; tip.position.x = 0.95; g.add(tip);
out.lance = g;
wo.lance = g;
} else {
// short ramp plate at the front (as before - stays close to the body so it does not poke through)
const p = box(0.5, 0.05, Wd * 1.05, ED); p.position.set(L / 2 + 0.18, c * 0.5 + 0.08, 0); p.rotation.z = -0.42; tilt.add(p);
@@ -483,7 +505,7 @@
const s = box(0.78 * lf, 0.03, Wd * 0.4, accent); s.position.set(0.39 * lf, 0.06, 0); piv.add(s);
const edge = box(0.12, 0.14, Wd * 0.98 * wf, HZ); edge.position.set(0.78 * lf, 0, 0); piv.add(edge);
const pist = cyl(0.05, 0.05, 0.4, m.hub, 8); pist.rotation.z = 1.0; pist.position.set(0.2, -0.16, 0); tilt.add(pist); // ram
out.flipper = piv;
wo.flipper = piv;
} else if (w.type === 'hammer') {
const post = box(0.16, 0.26, 0.24, m.dark); post.position.set(-L * 0.1, top + 0.11, 0); tilt.add(post);
const piv = new T.Group(); piv.position.set(-L * 0.1, top + 0.16, 0); tilt.add(piv);
@@ -496,7 +518,7 @@
const face = box(0.1, 0.44, 0.28, HZ); face.position.set(L * 0.82 + 0.17, -0.12, 0); piv.add(face);
const spike = box(0.18, 0.12, 0.12, accent); spike.position.set(L * 0.82, 0.12, 0); piv.add(spike);
}
out.hammer = piv;
wo.hammer = piv;
} else if (w.type === 'saw') {
const arm = box(0.4, 0.12, 0.12, m.dark); arm.position.set(L / 2 + 0.06, c + H * 0.5, 0); tilt.add(arm);
if (w.id === 'drill') {
@@ -504,7 +526,7 @@
const g = new T.Group(); g.position.set(L / 2 + 0.42, c + H * 0.5, 0); tilt.add(g);
const cone = cyl(0.001, 0.2, 0.72, WS, 14); cone.rotation.z = -Math.PI / 2; cone.castShadow = true; g.add(cone);
for (let k = 0; k < 3; k++) { const fl = box(0.6, 0.03, 0.06, HZ); fl.position.x = -0.1; fl.rotation.x = k / 3 * Math.PI * 2; g.add(fl); }
out.saw = g; out.sawAxis = 'x';
wo.saw = g; wo.sawAxis = 'x';
} else {
const guard = new T.Mesh(new T.TorusGeometry(0.42, 0.05, 8, 20, Math.PI), accent); // orange guard over the top
guard.position.set(L / 2 + 0.28, c + H * 0.5, 0); tilt.add(guard);
@@ -512,7 +534,7 @@
const d = cyl(0.38, 0.38, 0.04, WS, 32); d.rotation.x = Math.PI / 2; g.add(d);
for (let k = 0; k < 16; k++) { const t = box(0.11, 0.06, 0.05, WS); const a = k / 16 * Math.PI * 2; t.position.set(Math.cos(a) * 0.4, Math.sin(a) * 0.4, 0); t.rotation.z = a + 0.6; g.add(t); }
const hub = cyl(0.09, 0.09, 0.07, accent, 12); hub.rotation.x = Math.PI / 2; g.add(hub);
out.saw = g;
wo.saw = g;
}
} else if (w.type === 'spinner') {
if (w.id === 'drum') {
@@ -520,14 +542,14 @@
const g = new T.Group(); g.position.set(L / 2 + 0.12, c + H * 0.34, 0); tilt.add(g);
const drum = cyl(0.3, 0.3, 0.52, WS, 20); drum.castShadow = true; g.add(drum);
for (const sx of [-1, 1]) { const tb = box(0.14, 0.54, 0.12, HZ); tb.position.set(sx * 0.3, 0, 0); g.add(tb); }
out.spinner = g;
wo.spinner = g;
} else {
const post = cyl(0.1, 0.12, 0.3, m.dark, 12); post.position.set(L / 2 + 0.04, c + H * 0.32, 0); tilt.add(post);
const g = new T.Group(); g.position.set(L / 2 + 0.04, c + H * 0.3, 0); tilt.add(g);
const bar = box(1.5, 0.12, 0.22, WS); g.add(bar);
const stripe = box(1.5, 0.13, 0.08, HZ); g.add(stripe);
for (const sx of [-1, 1]) { const t = box(0.18, 0.16, 0.32, accent); t.position.x = sx * 0.72; g.add(t); }
out.spinner = g;
wo.spinner = g;
}
} else if (w.type === 'lifter') {
const piv = new T.Group(); piv.position.set(L / 2 - 0.08, c + H * 0.16, 0); tilt.add(piv);
@@ -536,7 +558,7 @@
const prong = box(0.85, 0.07, Wd * 0.26, WS); prong.position.set(0.46, 0, sz * Wd * 0.3); piv.add(prong);
const tip = box(0.16, 0.1, Wd * 0.28, HZ); tip.position.set(0.9, 0.015, sz * Wd * 0.3); piv.add(tip);
}
out.flipper = piv;
wo.flipper = piv;
} else if (w.type === 'vspinner') {
const arm = box(0.3, 0.14, 0.14, m.dark); arm.position.set(L / 2 + 0.02, c + H * 0.45, 0); tilt.add(arm);
const g = new T.Group(); g.position.set(L / 2 + 0.32, c + H * 0.42, 0); tilt.add(g);
@@ -546,19 +568,20 @@
tth.position.set(Math.cos(a) * 0.45, Math.sin(a) * 0.45, 0); tth.rotation.z = a; g.add(tth);
}
const hub = cyl(0.1, 0.1, 0.14, accent, 12); hub.rotation.x = Math.PI / 2; g.add(hub);
out.vspin = g;
wo.vspin = g;
} else if (w.type === 'crusher') {
out.jaws = [];
wo.jaws = [];
for (const sz of [-1, 1]) {
const piv = new T.Group(); piv.position.set(L / 2 - 0.02, c + H * 0.45, sz * Wd * 0.32); tilt.add(piv);
const j = box(0.68, 0.2, 0.14, WS); j.position.x = 0.34; piv.add(j);
for (let k = 0; k < 3; k++) { const tooth = box(0.1, 0.18, 0.14, accent); tooth.position.set(0.3 + k * 0.18, -sz * 0.02, -sz * 0.07); tooth.rotation.z = -sz * 0.25; piv.add(tooth); }
piv.userData.side = sz; out.jaws.push(piv);
piv.userData.side = sz; wo.jaws.push(piv);
}
}
tilt = _tilt; // restore before the next weapon / the tower
mark('weapon' + wi); // tag this weapon's mount group so breakPart can hide just it
}
mark('weapon');
out.wmount = out.weapons[0] && out.weapons[0].wmount; // editor drag targets a weapon (default the first)
// tower on top
const tw = st.tower;
@@ -636,23 +659,28 @@
R.tilt.position.y = (1 - Math.cos(R.roll)) / 2 * h;
const sp = Math.hypot(r.vx, r.vz) * (Math.cos(r.a) * r.vx + Math.sin(r.a) * r.vz >= 0 ? 1 : -1);
for (const wl of R.wheels) wl.rotation.z -= sp * dt / (R.wheelR || 0.16);
if (R.flipper) R.flipper.rotation.z = -0.32 + (r.flipAnim > 0 ? Math.sin((1 - r.flipAnim / 0.35) * Math.PI) * 1.5 : 0);
if (R.lance) {
// boost is set for 0.8 s when the lance fires -> fast stab out and back
const k = r.boost > 0 ? r.boost / 0.8 : 0;
R.lance.position.x = R.lance.userData.baseX + Math.sin(Math.min(1, (1 - k) * 2.2) * Math.PI) * 0.55;
// animate each mounted weapon from its own state r.W[i]
const wlist = R.weapons || [];
for (let i = 0; i < wlist.length; i++) {
const wo = wlist[i], W = (r.W && r.W[i]) || {}, w = R.st.weapons[i] && R.st.weapons[i].part;
if (!wo || !w) continue;
if (wo.flipper) wo.flipper.rotation.z = -0.32 + ((W.flipAnim || 0) > 0 ? Math.sin((1 - W.flipAnim / 0.35) * Math.PI) * 1.5 : 0);
if (wo.lance) { // W.fire runs 0.8s on a thrust -> fast, deep stab out and back
const k = (W.fire || 0) > 0 ? W.fire / 0.8 : 0;
wo.lance.position.x = wo.lance.userData.baseX + Math.sin(Math.min(1, (1 - k) * 2.2) * Math.PI) * 0.95;
}
if (wo.hammer) {
let ang = 1.9;
if ((W.swing || 0) > 0) { const k = 1 - W.swing / 0.28; ang = lerp(1.9, -0.25, k * k); }
else if (W.cd > w.cd - 0.28 - 0.15) ang = -0.25;
else if (W.cd > 0) ang = lerp(-0.25, 1.9, clamp((w.cd - 0.43 - W.cd) / 0.5, 0, 1));
wo.hammer.rotation.z = ang;
}
if (wo.saw) { if (W.sawOn) wo.sawA = (wo.sawA || 0) + dt * 40; wo.saw.rotation[wo.sawAxis || 'z'] = -(wo.sawA || 0); }
if (wo.spinner) { wo.spinA = (wo.spinA || 0) + dt * (W.spin || 0) * 38; wo.spinner.rotation.y = wo.spinA; }
if (wo.vspin) { wo.spinA = (wo.spinA || 0) + dt * (W.spin || 0) * 40; wo.vspin.rotation.z = -wo.spinA; }
if (wo.jaws) for (const j of wo.jaws) j.rotation.y = j.userData.side * ((W.grab || 0) > 0 ? -0.18 : 0.45);
}
if (R.hammer) {
let ang = 1.9;
if (r.swing > 0) { const k = 1 - r.swing / 0.28; ang = lerp(1.9, -0.25, k * k); }
else if (w && r.cd > w.cd - 0.28 - 0.15) ang = -0.25;
else if (w && r.cd > 0) ang = lerp(-0.25, 1.9, clamp((w.cd - 0.43 - r.cd) / 0.5, 0, 1));
R.hammer.rotation.z = ang;
}
if (R.saw) { if (r.sawOn) R.sawA += dt * 40; R.saw.rotation[R.sawAxis || 'z'] = -R.sawA; }
if (R.spinner) { R.spinA += dt * r.spin * 38; R.spinner.rotation.y = R.spinA; }
if (R.vspin) { R.spinA += dt * r.spin * 40; R.vspin.rotation.z = -R.spinA; }
if (R.jaws) for (const j of R.jaws) j.rotation.y = j.userData.side * (r.grab > 0 ? -0.18 : 0.45);
if (R.turret) R.turret.rotation.y = -(r.turretA - r.a);
if (R.flame) {
const tw2 = R.st.tower, beam = r.flameOn || (tw2 && tw2.type === 'zapper' && r.gunOn);
@@ -1038,7 +1066,7 @@
// intro / title: perspective camera flying over the arena
const pcam = new T.PerspectiveCamera(40, asp, 0.1, 120);
let mode = 'garage', gRobot = null, robots = [], state = null, shake = 0, flashT = 0, introT = 0, scale = 1, hold = 0;
let mode = 'garage', gRobot = null, robots = [], state = null, shake = 0, flashT = 0, introT = 0, scale = 1, hold = 0, editSel = 0, introLightK = 0, comfort = true;
let quality = 'high', fxMul = 1, camMode = 'iso', chaseInit = false, gcamZoom = GZ_DEF;
placeGarageCam(); // after gcamZoom exists: start fully zoomed out
// workshop: show what the fitted weapon / turret actually does, on a short loop
@@ -1047,17 +1075,19 @@
const R = gRobot; if (!R) return;
demoT += dt;
const c = demoT % 3; // one signature move every 3 s
if (R.saw) { R.sawA += dt * 26; R.saw.rotation[R.sawAxis || 'z'] = -R.sawA; }
if (R.spinner) { R.spinA += dt * 17; R.spinner.rotation.y = R.spinA; }
if (R.vspin) { R.spinA += dt * 19; R.vspin.rotation.z = -R.spinA; }
if (R.hammer) {
const k = c < 0.35 ? c / 0.35 : c < 1.2 ? 1 - (c - 0.35) / 0.85 : 0;
R.hammer.rotation.z = lerp(1.9, -0.25, k);
}
if (R.flipper) R.flipper.rotation.z = -0.32 + (c < 0.3 ? Math.sin(c / 0.3 * Math.PI) * 1.5 : 0);
if (R.jaws) {
const k = c < 1.2 ? Math.abs(Math.sin(c / 1.2 * Math.PI)) : 0;
for (const j of R.jaws) j.rotation.y = j.userData.side * (0.45 - k * 0.63);
for (const wo of R.weapons || []) {
if (wo.saw) { wo.sawA = (wo.sawA || 0) + dt * 26; wo.saw.rotation[wo.sawAxis || 'z'] = -wo.sawA; }
if (wo.spinner) { wo.spinA = (wo.spinA || 0) + dt * 17; wo.spinner.rotation.y = wo.spinA; }
if (wo.vspin) { wo.spinA = (wo.spinA || 0) + dt * 19; wo.vspin.rotation.z = -wo.spinA; }
if (wo.hammer) {
const k = c < 0.35 ? c / 0.35 : c < 1.2 ? 1 - (c - 0.35) / 0.85 : 0;
wo.hammer.rotation.z = lerp(1.9, -0.25, k);
}
if (wo.flipper) wo.flipper.rotation.z = -0.32 + (c < 0.3 ? Math.sin(c / 0.3 * Math.PI) * 1.5 : 0);
if (wo.jaws) {
const k = c < 1.2 ? Math.abs(Math.sin(c / 1.2 * Math.PI)) : 0;
for (const j of wo.jaws) j.rotation.y = j.userData.side * (0.45 - k * 0.63);
}
}
if (R.gun) { R.gunA += dt * 16; R.gun.rotation.x = R.gunA; }
const shooting = c > 1.5 && c < 2.3;
@@ -1096,7 +1126,7 @@
// intro fly-over, then a slow orbit behind the title screen; skip() jumps to the orbit
showIntro(builds, paints) {
api.showArena(RC.Combat.create({ robots: builds.map(b => RC.stats(b)), seed: 3, arena: 'workshop' }), builds, paints);
mode = 'intro'; introT = 0; pointMode(true);
mode = 'intro'; introT = 0; introLightK = 0; pointMode(true);
// compile every shader up front, otherwise the first seconds stutter while they are built
try { renderer.compile(arenaScene, pcam); } catch (e) { /* older three: just carry on */ }
},
@@ -1108,6 +1138,39 @@
gRobot.root.position.y = 0.12;
garage.turntable.add(gRobot.root);
},
// editor: stop / resume the turntable auto-spin so the robot holds still
freeze(on) { hold = on ? 1e9 : 0; },
setEditWeapon(i) { editSel = i | 0; },
// which weapon (index) is under the pointer, or -1
pickWeaponAt(cx, cy) {
if (!gRobot || !gRobot.weapons) return -1;
const r = new T.Raycaster(); r.setFromCamera(ndcOf(canvas, cx, cy), gcam);
for (let i = 0; i < gRobot.weapons.length; i++) {
const wo = gRobot.weapons[i];
if (wo && wo.wmount && r.intersectObject(wo.wmount, true).length) return i;
}
return -1;
},
// drag the selected weapon: snap to the nearest side + set height; returns { side, up } or null
dragWeapon(cx, cy) {
if (!gRobot || !gRobot.weapons || !gRobot.weapons[editSel]) return null;
const wo = gRobot.weapons[editSel], st = gRobot.st, inst = st.weapons[editSel];
const clamp = x => Math.max(-0.3, Math.min(0.6, x));
gRobot.root.updateWorldMatrix(true, false);
const center = new T.Vector3(); gRobot.root.getWorldPosition(center); center.y += st.h * 0.5;
const r = new T.Raycaster(); r.setFromCamera(ndcOf(canvas, cx, cy), gcam);
const hz = new T.Vector3();
if (!r.ray.intersectPlane(new T.Plane(new T.Vector3(0, 1, 0), -center.y), hz)) return null;
const loc = gRobot.root.worldToLocal(hz.clone()), ang = Math.atan2(loc.z, loc.x);
const side = Math.abs(ang) < Math.PI / 4 ? 'front' : Math.abs(ang) > 3 * Math.PI / 4 ? 'back' : ang > 0 ? 'right' : 'left';
let up = inst.mountUp || 0;
const n = new T.Vector3().subVectors(gcam.position, center); n.y = 0; n.normalize();
const vp = new T.Vector3();
if (r.ray.intersectPlane(new T.Plane(n, -n.dot(center)), vp)) up = clamp(vp.y - center.y);
inst.mountA = RC.MOUNTS[side].a; inst.mountAxis = RC.MOUNTS[side].axis; inst.mountUp = up;
placeMount(wo.wmount, inst, st.len, st.wid);
return { side, up };
},
// live update while painting (colour or drawing changed, no rebuild)
setPaint(paint) { if (gRobot) gRobot.skin.redraw(paint); },
// camera for the paint booth: closer, robot centred in the left part
@@ -1189,10 +1252,12 @@
get camMode() { return camMode; },
setCam(m) {
camMode = m; chaseInit = false;
pcam.fov = m === 'fpv' ? 72 : 55; pcam.updateProjectionMatrix();
pcam.fov = m === 'fpv' ? (comfort ? 62 : 70) : 55; pcam.updateProjectionMatrix(); // narrower fpv fov = less vection
if (mode === 'arena') pointMode(m !== 'iso');
if (robots[0] && robots[0].turret) robots[0].turret.visible = m !== 'fpv';
},
// comfort mode: smoother cockpit follow, narrower fov, weaker shake (reduces motion sickness)
setComfort(on) { comfort = !!on; pcam.fov = camMode === 'fpv' ? (comfort ? 62 : 70) : 55; pcam.updateProjectionMatrix(); },
project(x, y, z) {
const v = new T.Vector3(x, y, z).project(mode === 'arena' && camMode !== 'iso' ? pcam : cam);
// behind the camera (chase / cockpit): off screen
@@ -1217,7 +1282,8 @@
animateArena(dt, now);
sparks.update(dt, 9, 1.2); smoke.update(dt, -0.6, 1.4); fire.update(dt, -2.5, 2);
shake = Math.max(0, shake - dt * 1.2);
const sx = (Math.random() - 0.5) * shake, sz = (Math.random() - 0.5) * shake;
const sk = comfort ? 0.4 : 1; // comfort: soften camera shake
const sx = (Math.random() - 0.5) * shake * sk, sz = (Math.random() - 0.5) * shake * sk;
flashT = Math.max(0, flashT - dt * 3);
arena.flashLight.intensity = flashT * 4;
if (camMode !== 'iso' && state && robots[0]) {
@@ -1241,7 +1307,11 @@
const k = R.st.len * 0.08;
px = r.x + fx * k; pz = r.z + fz * k; py = Math.max(0.25, r.y) + R.top + 0.55;
lx = px + fx * 6; lz = pz + fz * 6; ly = py - 1.25;
cpos.set(px + sx * 0.3, py, pz + sz * 0.3); clook.set(lx, ly, lz);
// smooth the eye + aim instead of snapping 1:1 to the robot's yaw/bounce -> the main motion-sickness fix
const sm = chaseInit ? Math.min(1, dt * (comfort ? 9 : 16)) : 1;
chaseInit = true;
cpos.lerp(new T.Vector3(px + sx * 0.3, py, pz + sz * 0.3), sm);
clook.lerp(new T.Vector3(lx, ly, lz), sm);
} else {
px = Kit.clamp(r.x - fx * 3.6, -half - 1.2, half + 1.2); pz = Kit.clamp(r.z - fz * 3.6, -half - 1.2, half + 1.2); py = 2.2 + r.y * 0.5;
lx = r.x + fx * 1.6; lz = r.z + fz * 1.6; ly = 0.3 + r.y * 0.5;
@@ -1261,21 +1331,27 @@
if (L.hemi) L.hemi.intensity = 0.55 * (0.12 + 0.88 * k);
M.lamp.emissiveIntensity = 1.5 * k;
}
const smoother = u => u * u * u * (u * (u * 6 - 15) + 10); // smootherstep: zero velocity at both ends
function introScript(dt) {
const t = introT, s = state;
// floodlights: off, flicker, on
lightsOn(t < 0.25 ? 0.12 : t < 0.4 ? 1 : t < 0.55 ? 0.15 : t < 0.7 ? 0.9 : t < 0.85 ? 0.3 : 1);
// camera path, then a slow orbit
// floodlights: dark -> two quick flickers -> full; softened by easing the intensity toward the target
const target = t < 0.25 ? 0.12 : t < 0.4 ? 1 : t < 0.52 ? 0.2 : t < 0.64 ? 1 : t < 0.78 ? 0.45 : 1;
introLightK += (target - introLightK) * Math.min(1, dt * 16);
lightsOn(introLightK);
// one continuous cinematic dolly: low & close -> rise and pull back to a hero 3/4, with a gentle orbit throughout
const orbit = t * 0.05;
let ang, r, h, lx, lz;
if (t < INTRO_END) {
const e = ease(Math.min(1, t / INTRO_END));
ang = lerp(-2.4, Math.PI / 4, e); r = lerp(9, 20.5, e); h = lerp(2.4, 13.5, Math.pow(e, 1.4));
lx = lerp(RC.ARENA.pit.x, -0.6, e); lz = lerp(RC.ARENA.pit.z, -0.6, e);
const u = smoother(Math.min(1, t / INTRO_END));
ang = lerp(-2.4, Math.PI / 4, u) + orbit;
r = lerp(8.2, 19.5, u);
h = lerp(1.7, 13, u);
lx = lerp(RC.ARENA.pit.x * 0.5, -0.3, u); lz = lerp(RC.ARENA.pit.z * 0.5, -0.3, u);
} else {
ang = Math.PI / 4 + (t - INTRO_END) * 0.05; r = 20.5; h = 13.5; lx = lz = 0;
ang = Math.PI / 4 + orbit; r = 19.5; h = 13; lx = -0.3; lz = -0.3; // seamless: matches the sweep's end
}
pcam.position.set(Math.cos(ang) * r, h, Math.sin(ang) * r);
pcam.lookAt(lx, 0.3, lz);
pcam.lookAt(lx, 0.45, lz);
// robots lowered in from above, landing with sparks
s.t = t + 2; // trap timing: flames ignite once the lights are on
s.robots.forEach((rb, i) => {
@@ -1342,7 +1418,7 @@
const main = kill[0];
for (const o of kill) if (o !== main) o.visible = false;
dropPiece(main);
if (part === 'weapon') { R.saw = null; R.spinner = null; R.hammer = null; R.flipper = null; R.jaws = null; }
if (/^weapon\d/.test(part)) { const wi = +part.slice(6); if (R.weapons && R.weapons[wi]) R.weapons[wi] = null; } // stop animating the torn-off weapon
if (part === 'tower') { R.turret = null; R.flame = null; R.gun = null; R.muzzle = null; }
}
@@ -1353,21 +1429,20 @@
robots.forEach((R, i) => {
const r = s.robots[i];
poseRobot(R, r, dt);
// long front weapons must stop at the enemy, not stab through it
if (R.lance) {
const e = s.robots[1 - i];
if (e && !e.out) {
const dx = e.x - r.x, dz = e.z - r.z, d = Math.hypot(dx, dz) || 1;
const fx = Math.cos(r.a), fz = Math.sin(r.a), facing = (dx * fx + dz * fz) / d;
if (facing > 0.55) {
const reach = d - e.st.rad * 0.85, base = R.st.len / 2 + 0.95;
const maxThrust = Math.max(0, reach - base), bx = R.lance.userData.baseX;
if (R.lance.position.x - bx > maxThrust) {
const hit = R.lance.position.x - bx - maxThrust > 0.04;
R.lance.position.x = bx + maxThrust;
if (hit && Math.random() < 0.6) burst(e.x - fx * e.st.rad, 0.4, e.z - fz * e.st.rad, 10, 5, [1, 0.8, 0.4]);
}
}
// each lance must stop at the enemy (in its own mount direction), not stab through it
const e = s.robots[1 - i];
for (let wi = 0; e && !e.out && wi < (R.weapons || []).length; wi++) {
const wo = R.weapons[wi]; if (!wo || !wo.lance) continue;
const inst = R.st.weapons[wi];
const dx = e.x - r.x, dz = e.z - r.z, d = Math.hypot(dx, dz) || 1;
const a = r.a + (inst ? inst.mountA : 0), fx = Math.cos(a), fz = Math.sin(a), facing = (dx * fx + dz * fz) / d;
if (facing <= 0.55) continue;
const reach = d - e.st.rad * 0.85, bx = wo.lance.userData.baseX;
const maxThrust = reach - (bx + 0.95); // may be negative -> pull the lance back into the sleeve
if (wo.lance.position.x - bx > maxThrust) {
const hit = wo.lance.position.x - bx - maxThrust > 0.04;
wo.lance.position.x = bx + Math.max(-0.45, maxThrust);
if (hit && Math.random() < 0.6) burst(e.x - fx * e.st.rad, 0.4, e.z - fz * e.st.rad, 10, 5, [1, 0.8, 0.4]);
}
}
// damaged robots smoke, dead ones burn