27:18Gemini 4 Hydrogen: Cheaper Tokens, More Expensive Answers?
Nov 13, 2026 · YouTube
18:40ERNIE 5.5 Flash Preview vs GLM 5.3 Flash: Baidu's new model is very impressive!
Nov 11, 2026 · YouTube
36:22Fable 5.2 robbing me blind, plus: Nex AGI's N2.6 vs GLM 5.3 Flash
Nov 11, 2026 · YouTube
14:03Gemini 4 Carbon: Can it handle my challenges? (First look with one-shot coding tests)
Nov 10, 2026 · YouTube
47:51Ranking major U.S. Open-Weights Models. (Where does Ripple 65B fit in?)
Nov 6, 2026 · YouTube
10:57"Crouton Alpha": the latest super-efficient coding model by Meta?
Nov 3, 2026 · YouTube
38:58Testing Particle-1: a post-trained DeepSeek V4.1 Flash specializing in coding and efficiency
Oct 28, 2026 · YouTube
22:14GPT-6.1 Terra Pro vs Terra: How Much Better Is Pro?
Oct 27, 2026 · YouTube
29:55Kimi K3.1 Pro Looked Incredible. Then I Kept Testing.
Oct 26, 2026 · YouTube
31:28Is this company reselling GPT Sol 6.1 at a loss (for non-agentic/text-only)?🤔 Is this sustainable?
Oct 20, 2026 · YouTube
17:58Nemotron 3.5 Super VL vs Opus 5.5: Testing NVIDIA’s new coding juggernaut
Oct 15, 2026 · YouTube
16:04Testing a *massive* new open-weights model 🤯: Muse Spark Open (vs. Nemotron, Opus 5.5, and more)
Oct 15, 2026 · YouTube
16:43Gemini 4 Argon: Great 🐈 Animation, but a broken escalator. (Coding challenge vs Opus 5.5, Sol 6.1)
Oct 13, 2026 · YouTube
16:37Meta's new "Muse Wonder" AI is impressive... but can it compete with Anthropic's models?
Oct 12, 2026 · YouTube
11:12WOW... Haiku 5.5 is very impressive. RIP OpenAI?
Oct 7, 2026 · YouTube
22:47Mistral Large 4 Is Cheap. But Is It Good Enough to Compete?
Oct 6, 2026 · YouTube
22:02Is Pareto 26.10 Preview Just Routing to GPT Sol? I Tested It Against Sol 6.1 Pro
Oct 1, 2026 · YouTube
11:22I Tested Sonnet 5.5 Against Opus 5.5. Is It Actually Cheaper?
Sep 28, 2026 · YouTube
30:00Did Elon Musk's team "train the gay away"... and make Grok 4.7 worse?
Sep 26, 2026 · YouTube
10:58So... how much better is Claude Opus 5.5 vs. GPT-6 Sol, really?
Sep 23, 2026 · YouTube
9:38Claude Opus 5.5... the BEST new model for coding!! 🤩
Sep 22, 2026 · YouTube
29:00Grok 4.7: improved, but GLM 5.3 FlashX beat it anyway (benchmark against Gemini, Sol, etc.)
Sep 22, 2026 · YouTube
16:54Stealth Union Alpha: Is this another cheap GPT model? (better than Luna, cheaper than Terra?)
Sep 16, 2026 · YouTube
16:45DeepSeek V4.1 Flash Is Shockingly Good for the Price
Sep 10, 2026 · YouTube
17:14How much better is GPT-6 Astra over Claude Opus 5? Real Website and Coding Tests
Sep 5, 2026 · YouTube
29:13Implementing a multiplayer game with GPT-6 Astra (+ Gemini 3.8, Opus 5, Sol Pro)
Sep 5, 2026 · YouTube
19:42Meta Muse Spark 1.3 Review: A Huge Leap Forward
Sep 2, 2026 · YouTube
17:31Testing Gemini 3.8 Flash on Real Coding Challenges (vs. other models)
Sep 2, 2026 · YouTube
19:45Fable 5.1 writes an animated novel using Ren'Py... did it do better than Sol Pro 5.6?
Sep 1, 2026 · YouTube
14:09Testing IBM Granite-4.2-8B! Can it name 100 women?
Aug 31, 2026 · YouTube
17:37Tencent Hy4 Preview Tested: Is It Really Better Than Kimi K3 and GLM 5.3?
Aug 28, 2026 · YouTube
23:58Qwen 3.8 Flash Tested: UI, Coding, Physics & more - compared to Opus 5, Sol Pro, Grok
Aug 27, 2026 · YouTube
You are a game developer who ships browser demos that have to work on the first click, in front of an audience, on someone else's laptop.
Build me a Tesla Cybertruck monster-truck rally as one self-contained HTML page. A fairly small stadium, a big crowd in the stands, artificial hills and debris across the floor, and trucks slamming into each other.
Then make it match the spec below exactly. The spec is the challenge; a great-looking rally that ignores it is a miss.
.html page. No build step. Saved to disk and double-clicked, it runs.localStorage, sessionStorage, cookies or indexedDB. It runs in a sandboxed frame where touching them throws.Both are checkable in ten seconds, which is why they are here.
#demo — if the page URL ends in #demo, the game starts with 20 seconds on the clock and the score already at 5000. This must run through the real game state, not a cosmetic overlay. Everything else behaves normally.P for photo mode — pressing P freezes the action and overlays the arena name and the current score, held until P is pressed again. The simulation stops; it does not keep playing behind the card.One sentence: the name of your rally and what it looks like.
Exactly one fenced html block containing the whole page and nothing else.
Exactly four bullets.
#demo sets, and why it is not an overlay.P is pressed — the render loop, the physics step, or both.Iron Halo Rally packs five angular monster trucks into a crowded, dirt-floored stadium for a chaotic metallic brawl.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Iron Halo Rally</title>
<link rel="icon" href="data:,">
<style>
* { box-sizing: border-box; }
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; }
body {
background: #10151c;
color: #fff;
font-family: Arial, Helvetica, sans-serif;
}
canvas { display: block; width: 100%; height: 100%; }
#hud {
position: absolute;
z-index: 2;
top: 18px;
left: 18px;
right: 18px;
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 12px;
pointer-events: none;
text-shadow: 0 2px 8px #000;
}
.panel {
background: rgba(11, 17, 23, .82);
border: 1px solid rgba(255, 255, 255, .22);
border-left: 4px solid #f3b846;
padding: 11px 15px;
box-shadow: 0 4px 20px rgba(0,0,0,.25);
}
.name {
color: #f3b846;
font-size: 12px;
font-weight: 900;
letter-spacing: .19em;
}
.value {
font-size: clamp(22px, 4vw, 35px);
font-weight: 900;
font-variant-numeric: tabular-nums;
}
.small {
margin-top: 4px;
color: #d4dde0;
font-size: 11px;
font-weight: 700;
letter-spacing: .06em;
}
#stats { text-align: right; min-width: 120px; }
#impact {
position: absolute;
z-index: 2;
top: 120px;
left: 50%;
transform: translateX(-50%);
color: #ffe08a;
font-weight: 900;
font-size: 20px;
text-shadow: 0 2px 6px #000;
opacity: 0;
pointer-events: none;
}
.cover {
position: absolute;
z-index: 5;
inset: 0;
display: none;
place-items: center;
background: rgba(5, 9, 14, .72);
text-align: center;
}
.cover.visible { display: grid; }
.card {
max-width: 90vw;
padding: 30px 42px;
background: rgba(15, 22, 29, .95);
border: 1px solid #8a7551;
box-shadow: 0 18px 70px #000a;
}
.card h1 {
color: #f3b846;
margin: 0 0 10px;
font-size: clamp(28px, 6vw, 54px);
letter-spacing: .05em;
}
.card p { margin: 8px 0; color: #e1e8e9; }
.card .big { color: white; font-size: 36px; font-weight: 900; }
#photo { z-index: 6; pointer-events: none; }
#error { z-index: 10; }
@media (max-width: 520px) {
#hud { top: 8px; left: 8px; right: 8px; }
.panel { padding: 8px 10px; }
.small { font-size: 9px; }
}
</style>
</head>
<body>
<div id="hud">
<div class="panel">
<div class="name">IRON HALO RALLY</div>
<div class="small">WASD / ARROWS: DRIVE · P: PHOTO</div>
</div>
<div id="stats" class="panel">
<div class="name">SCORE</div>
<div id="score" class="value">0</div>
<div id="clock" class="small">01:30</div>
</div>
</div>
<div id="impact"></div>
<div id="photo" class="cover">
<div class="card">
<div class="name">PHOTO MODE</div>
<h1>IRON HALO RALLY</h1>
<p>SCORE</p>
<div id="photoScore" class="big">0</div>
<p>Press P to resume</p>
</div>
</div>
<div id="finish" class="cover">
<div class="card">
<div class="name">FINAL SCORE</div>
<h1>TIME'S UP</h1>
<div id="finalScore" class="big">0</div>
<p>Press R to rally again</p>
</div>
</div>
<div id="error" class="cover">
<div class="card">
<h1>ENGINE UNAVAILABLE</h1>
<p>Three.js could not be loaded. Check the network connection and reopen this page.</p>
</div>
</div>
<!-- The sole external request. -->
<script src="https://cdn.jsdelivr.net/npm/three@0.160.1/build/three.min.js"></script>
<script>
(() => {
"use strict";
if (typeof THREE === "undefined") {
document.getElementById("error").classList.add("visible");
return;
}
const ARENA = "IRON HALO RALLY";
const isDemo = location.hash === "#demo";
const state = { time: isDemo ? 20 : 90, score: isDemo ? 5000 : 0, photo: false, over: false };
const scoreEl = document.getElementById("score");
const clockEl = document.getElementById("clock");
const photoEl = document.getElementById("photo");
const finishEl = document.getElementById("finish");
const impactEl = document.getElementById("impact");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x8395a2);
scene.fog = new THREE.Fog(0x8395a2, 65, 125);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 1.5));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.1;
document.body.prepend(renderer.domElement);
const camera = new THREE.PerspectiveCamera(53, window.innerWidth / window.innerHeight, 0.1, 180);
const hemi = new THREE.HemisphereLight(0xcce7ff, 0x594433, 2.1);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe5bd, 2.5);
sun.position.set(-20, 35, 12);
scene.add(sun);
const mat = (color, extra = {}) => new THREE.MeshStandardMaterial({ color, ...extra });
const dirtMat = mat(0x755c47, { roughness: 1 });
const hillMat = mat(0x937555, { roughness: 1 });
const concreteMat = mat(0x515a5c, { roughness: 1 });
const railMat = mat(0xc2bba5, { metalness: .5, roughness: .6 });
const darkMat = mat(0x1b2229, { roughness: .85 });
const tireMat = mat(0x171b1d, { roughness: 1 });
const hubMat = mat(0xa4acac, { metalness: .75, roughness: .35 });
const glassMat = mat(0x172c36, { metalness: .55, roughness: .25 });
const lampMat = new THREE.MeshBasicMaterial({ color: 0xffebac });
const boxGeo = new THREE.BoxGeometry(1, 1, 1);
function box(parent, material, x, y, z, sx, sy, sz, ry = 0) {
const m = new THREE.Mesh(boxGeo, material);
m.position.set(x, y, z);
m.scale.set(sx, sy, sz);
m.rotation.y = ry;
parent.add(m);
return m;
}
function flatRing(inner, outer, y, material) {
const m = new THREE.Mesh(new THREE.RingGeometry(inner, outer, 128), material);
m.rotation.x = -Math.PI / 2;
m.position.y = y;
scene.add(m);
return m;
}
const floor = new THREE.Mesh(new THREE.CircleGeometry(35, 128), dirtMat);
floor.rotation.x = -Math.PI / 2;
scene.add(floor);
const lineMat = new THREE.MeshBasicMaterial({ color: 0xc9ae7d, side: THREE.DoubleSide });
flatRing(30.8, 31.05, .025, lineMat);
flatRing(19.8, 19.88, .024, lineMat);
flatRing(9.8, 9.88, .023, lineMat);
// Stepped annular stands and railings encircle the entire arena.
const standMaterial = mat(0x596267, { side: THREE.DoubleSide, roughness: 1 });
for (let row = 0; row < 7; row++) {
flatRing(35 + row * 1.75, 36.75 + row * 1.75, .5 + row * .7, standMaterial);
}
const wall = new THREE.Mesh(
new THREE.CylinderGeometry(35, 35, 1.6, 128, 1, true),
mat(0x39444a, { side: THREE.DoubleSide })
);
wall.position.y = .8;
scene.add(wall);
const wallStripe = new THREE.Mesh(
new THREE.CylinderGeometry(35.05, 35.05, .18, 128, 1, true),
mat(0xe0a83f, { side: THREE.DoubleSide })
);
wallStripe.position.y = 1.4;
scene.add(wallStripe);
// Instanced heads and torsos: a crowd, rather than a painted backdrop.
const crowdCount = 7 * 176;
const bodyMesh = new THREE.InstancedMesh(new THREE.BoxGeometry(.36, .5, .24), mat(0xffffff), crowdCount);
const headMesh = new THREE.InstancedMesh(new THREE.SphereGeometry(.15, 7, 5), mat(0xffffff), crowdCount);
const dummy = new THREE.Object3D();
const color = new THREE.Color();
const shirts = [0xce654c, 0x527f9b, 0xe7b65a, 0xd7d7c9, 0x6a8069, 0x883e44, 0x343e50];
const skins = [0xe9bb93, 0xbc8461, 0x795341, 0xf0cfad, 0x98694f];
let seed = 57421;
function rand() {
seed = (seed * 1664525 + 1013904223) >>> 0;
return seed / 4294967296;
}
let ci = 0;
for (let row = 0; row < 7; row++) {
for (let j = 0; j < 176; j++) {
const a = (j + (row % 2) * .5 + (rand() - .5) * .25) / 176 * Math.PI * 2;
const r = 35.85 + row * 1.75 + (rand() - .5) * .25;
const y = .5 + row * .7;
dummy.position.set(Math.sin(a) * r, y + .28, Math.cos(a) * r);
dummy.rotation.set(0, a, 0);
dummy.scale.set(1, .8 + rand() * .35, 1);
dummy.updateMatrix();
bodyMesh.setMatrixAt(ci, dummy.matrix);
bodyMesh.setColorAt(ci, color.setHex(shirts[Math.floor(rand() * shirts.length)]));
dummy.position.y = y + .69;
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
headMesh.setMatrixAt(ci, dummy.matrix);
headMesh.setColorAt(ci, color.setHex(skins[Math.floor(rand() * skins.length)]));
ci++;
}
}
scene.add(bodyMesh, headMesh);
// Floodlight towers around the rim.
for (let i = 0; i < 8; i++) {
const a = i * Math.PI / 4;
const x = Math.sin(a) * 48, z = Math.cos(a) * 48;
box(scene, darkMat, x, 6.5, z, .45, 13, .45);
const rack = new THREE.Group();
rack.position.set(x, 12.8, z);
rack.rotation.y = a;
scene.add(rack);
box(rack, darkMat, 0, 0, 0, 4.4, .55, .5);
for (let k = -2; k <= 2; k++) box(rack, lampMat, k * .8, 0, -.28, .55, .34, .08);
}
// Raised ellipsoids are driveable hills. Their visible shape and height
// function use the same ellipse.
const hills = [
{ x: -13, z: -12, rx: 5.2, rz: 3.8, h: 1.65 },
{ x: 13, z: 11, rx: 4.8, rz: 3.5, h: 1.45 },
{ x: -13, z: 14, rx: 3.8, rz: 4.3, h: 1.15 },
{ x: 14, z: -15, rx: 4.2, rz: 3.1, h: 1.3 }
];
const hillGeo = new THREE.SphereGeometry(1, 32, 16);
for (const h of hills) {
const m = new THREE.Mesh(hillGeo, hillMat);
m.position.set(h.x, 0, h.z);
m.scale.set(h.rx, h.h, h.rz);
scene.add(m);
}
function groundHeight(x, z) {
let height = 0;
for (const h of hills) {
const dx = (x - h.x) / h.rx, dz = (z - h.z) / h.rz;
const q = 1 - dx * dx - dz * dz;
if (q > 0) height = Math.max(height, h.h * Math.sqrt(q));
}
return height;
}
// Solid obstacles: rocks and scrap barriers, each with a collision radius.
const obstacles = [];
const rockMat = mat(0x77796f, { roughness: 1 });
const scrapMat = mat(0xb86439, { metalness: .45, roughness: .75 });
const stripeMat = mat(0xe5ba63);
const rockGeo = new THREE.DodecahedronGeometry(1, 0);
function rock(x, z, r) {
const mesh = new THREE.Mesh(rockGeo, rockMat);
mesh.position.set(x, r * .48, z);
mesh.scale.set(r, r * .7, r * .85);
mesh.rotation.set(.2, rand() * 3, .15);
scene.add(mesh);
obstacles.push({ x, z, r: r * .85 });
}
function barrier(x, z, angle) {
const g = new THREE.Group();
g.position.set(x, 0, z);
g.rotation.y = angle;
scene.add(g);
box(g, scrapMat, 0, .48, 0, 2.8, .8, .8);
box(g, stripeMat, 0, .91, 0, 2.9, .12, .85);
box(g, darkMat, -.95, .25, 0, .16, .5, .85);
box(g, darkMat, .95, .25, 0, .16, .5, .85);
obstacles.push({ x, z, r: 1.35 });
}
rock(-4, -17, 1.35);
rock(6, 16, 1.4);
rock(-22, 1, 1.25);
rock(21, -4, 1.3);
rock(2, -3, 1.05);
barrier(-4, 9, .5);
barrier(8, -9, -.6);
barrier(-20, -20, .8);
barrier(20, 20, -.4);
// Small non-solid scattered debris.
for (let i = 0; i < 65; i++) {
const a = rand() * Math.PI * 2, r = 5 + rand() * 27;
const x = Math.sin(a) * r, z = Math.cos(a) * r;
const y = groundHeight(x, z) + .04;
box(scene, i % 3 ? concreteMat : scrapMat, x, y, z,
.15 + rand() * .4, .07, .2 + rand() * .5, rand() * Math.PI);
}
function polygon(points, material) {
const geometry = new THREE.BufferGeometry();
geometry.setAttribute("position", new THREE.Float32BufferAttribute(points.flat(), 3));
geometry.computeVertexNormals();
return new THREE.Mesh(geometry, material);
}
const wheelGeo = new THREE.CylinderGeometry(.53, .53, .42, 14);
const hubGeo = new THREE.CylinderGeometry(.26, .26, .44, 12);
const shadowMat = new THREE.MeshBasicMaterial({
color: 0x14100d, transparent: true, opacity: .35, depthWrite: false
});
function makeTruck(colorHex, x, z, angle, aiIndex) {
const group = new THREE.Group();
scene.add(group);
const bodyMat = mat(colorHex, { metalness: .72, roughness: .34, emissive: 0x000000 });
// Wedge body: nose is local +Z.
const v = [
[-.72,.48,-1.32], [.72,.48,-1.32],
[-.72,.48,1.32], [.72,.48,1.32],
[-.72,1.02,-1.2], [.72,1.02,-1.2],
[-.62,1.6,-.38], [.62,1.6,-.38],
[-.62,1.37,.45], [.62,1.37,.45],
[-.72,.91,1.27], [.72,.91,1.27]
];
const faces = [
0,4,5, 0,5,1, 2,3,11, 2,11,10,
0,2,10, 0,10,4, 4,10,8, 4,8,6,
1,5,11, 1,11,3, 5,7,9, 5,9,11,
4,6,7, 4,7,5, 6,8,9, 6,9,7,
8,10,11, 8,11,9, 0,1,3, 0,3,2
];
const bodyGeometry = new THREE.BufferGeometry();
bodyGeometry.setAttribute("position", new THREE.Float32BufferAttribute(v.flat(), 3));
bodyGeometry.setIndex(faces);
bodyGeometry.computeVertexNormals();
const body = new THREE.Mesh(bodyGeometry, bodyMat);
body.material.side = THREE.DoubleSide;
group.add(body);
// Dark side windows make the angular silhouette readable.
const windowMaterial = glassMat.clone();
windowMaterial.side = THREE.DoubleSide;
for (const s of [-1, 1]) {
group.add(polygon([
[s*.635,1.48,-.31], [s*.635,1.30,.36], [s*.70,1.07,.86],
[s*.635,1.48,-.31], [s*.70,1.07,.86], [s*.70,1.08,-.83]
], windowMaterial));
}
box(group, darkMat, 0, .48, 1.34, 1.5, .22, .18);
box(group, lampMat, 0, .88, 1.335, 1.32, .09, .04);
const tailMat = new THREE.MeshBasicMaterial({ color: 0xff594a });
box(group, tailMat, 0, .91, -1.325, 1.25, .08, .04);
const wheels = [];
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
const pivot = new THREE.Group();
pivot.position.set(sx * .87, .48, sz * .91);
group.add(pivot);
const tire = new THREE.Mesh(wheelGeo, tireMat);
tire.rotation.z = Math.PI / 2;
pivot.add(tire);
const hub = new THREE.Mesh(hubGeo, hubMat);
hub.rotation.z = Math.PI / 2;
pivot.add(hub);
wheels.push(pivot);
}
}
const shadow = new THREE.Mesh(new THREE.CircleGeometry(1, 24), shadowMat);
shadow.rotation.x = -Math.PI / 2;
shadow.scale.set(1.45, 2.05, 1);
scene.add(shadow);
return {
group, bodyMat, wheels, shadow, x, z, angle, vx: 0, vz: 0,
radius: 1.3, aiIndex, flash: 0
};
}
const starts = [
[0, 22, Math.PI],
[-17, -3, .8],
[16, -4, -.8],
[-9, -22, .2],
[10, -22, -.2]
];
const colors = [0xc7d1d1, 0xe27640, 0x4f94ac, 0xe0b449, 0xa16491];
const trucks = starts.map((s, i) => makeTruck(colors[i], s[0], s[1], s[2], i - 1));
const player = trucks[0];
const keys = Object.create(null);
const pairCooldown = Array.from({ length: 5 }, () => Array(5).fill(0));
let gameTime = 0;
let impactTime = 0;
let accumulator = 0;
let last = performance.now();
let cameraReady = false;
function wrapAngle(a) {
return Math.atan2(Math.sin(a), Math.cos(a));
}
function updateHUD() {
scoreEl.textContent = Math.floor(state.score).toLocaleString("en-US");
const seconds = Math.max(0, Math.ceil(state.time));
clockEl.textContent = String(Math.floor(seconds / 60)).padStart(2, "0") + ":" +
String(seconds % 60).padStart(2, "0");
}
function resetGame() {
state.time = isDemo ? 20 : 90;
state.score = isDemo ? 5000 : 0;
state.over = false;
state.photo = false;
gameTime = 0;
impactTime = 0;
accumulator = 0;
cameraReady = false;
for (const key in keys) delete keys[key];
trucks.forEach((t, i) => {
t.x = starts[i][0]; t.z = starts[i][1]; t.angle = starts[i][2];
t.vx = 0; t.vz = 0; t.flash = 0;
t.bodyMat.emissive.setHex(0x000000);
});
for (const row of pairCooldown) row.fill(0);
photoEl.classList.remove("visible");
finishEl.classList.remove("visible");
impactEl.style.opacity = "0";
last = performance.now();
updateHUD();
}
function aiControls(t) {
const i = t.aiIndex;
// Individual orbit radii, phases and speeds keep rivals pursuing different
// points. They periodically aim near the player to create encounters.
const phase = gameTime * (.22 + i * .025) + i * Math.PI / 2;
const radius = 10 + i * 2.2;
let tx = Math.sin(phase) * radius;
let tz = Math.cos(phase) * radius;
if (Math.sin(gameTime * .21 + i * 2.1) > .48) {
tx = player.x + Math.sin(phase * 1.7 + i) * 4;
tz = player.z + Math.cos(phase * 1.7 + i) * 4;
}
let dx = tx - t.x, dz = tz - t.z;
const len = Math.hypot(dx, dz) || 1;
dx /= len; dz /= len;
// Local avoidance is strongest at short range; collision physics still applies.
for (const other of trucks) {
if (other === t) continue;
const ox = t.x - other.x, oz = t.z - other.z;
const d = Math.hypot(ox, oz) || .01;
if (d < 5.5) {
const weight = (5.5 - d) / 5.5 * (other === player ? .45 : 1.5);
dx += ox / d * weight;
dz += oz / d * weight;
}
}
for (const o of obstacles) {
const ox = t.x - o.x, oz = t.z - o.z;
const d = Math.hypot(ox, oz) || .01;
if (d < o.r + 4) {
const weight = (o.r + 4 - d) / (o.r + 4) * 1.4;
dx += ox / d * weight;
dz += oz / d * weight;
}
}
const target = Math.atan2(dx, dz);
const difference = wrapAngle(target - t.angle);
return { throttle: 1, steer: THREE.MathUtils.clamp(difference * 1.6, -1, 1) };
}
function moveTruck(t, dt) {
let throttle, steer;
if (t === player) {
throttle = (keys["w"] || keys["arrowup"] ? 1 : 0) -
(keys["s"] || keys["arrowdown"] ? 1 : 0);
steer = (keys["d"] || keys["arrowright"] ? 1 : 0) -
(keys["a"] || keys["arrowleft"] ? 1 : 0);
} else {
const controls = aiControls(t);
throttle = controls.throttle;
steer = controls.steer;
}
const fx = Math.sin(t.angle), fz = Math.cos(t.angle);
const forwardSpeed = t.vx * fx + t.vz * fz;
const turnFactor = Math.min(1, .25 + Math.abs(forwardSpeed) / 5);
const reverse = forwardSpeed < -1 ? -1 : 1;
t.angle += steer * 1.9 * turnFactor * reverse * dt;
const nx = Math.sin(t.angle), nz = Math.cos(t.angle);
t.vx += nx * throttle * 13 * dt;
t.vz += nz * throttle * 13 * dt;
// Reduce sideways sliding without erasing collision impulses immediately.
const sideways = t.vx * nz - t.vz * nx;
t.vx -= sideways * nz * Math.min(1, 2.2 * dt);
t.vz += sideways * nx * Math.min(1, 2.2 * dt);
const drag = Math.exp(-.75 * dt);
t.vx *= drag; t.vz *= drag;
const speed = Math.hypot(t.vx, t.vz);
const maxSpeed = t === player ? 16 : 13.5;
if (speed > maxSpeed) {
t.vx *= maxSpeed / speed;
t.vz *= maxSpeed / speed;
}
t.x += t.vx * dt;
t.z += t.vz * dt;
const distance = Math.hypot(t.x, t.z);
const limit = 33.4;
if (distance > limit) {
const wx = t.x / distance, wz = t.z / distance;
t.x = wx * limit; t.z = wz * limit;
const outward = t.vx * wx + t.vz * wz;
if (outward > 0) {
t.vx -= 1.5 * outward * wx;
t.vz -= 1.5 * outward * wz;
}
}
for (const o of obstacles) {
let dx = t.x - o.x, dz = t.z - o.z;
let d = Math.hypot(dx, dz);
const min = t.radius + o.r;
if (d < min) {
if (d < .001) { dx = 1; dz = 0; d = 1; }
const ox = dx / d, oz = dz / d;
t.x += ox * (min - d);
t.z += oz * (min - d);
const toward = t.vx * ox + t.vz * oz;
if (toward < 0) {
t.vx -= 1.45 * toward * ox;
t.vz -= 1.45 * toward * oz;
if (toward < -3) t.flash = .14;
}
}
}
}
function collideTrucks(a, b, i, j) {
let dx = b.x - a.x, dz = b.z - a.z;
let d = Math.hypot(dx, dz);
const min = a.radius + b.radius;
if (d >= min) return;
if (d < .001) { dx = 1; dz = 0; d = 1; }
const nx = dx / d, nz = dz / d;
const overlap = min - d;
a.x -= nx * overlap * .5; a.z -= nz * overlap * .5;
b.x += nx * overlap * .5; b.z += nz * overlap * .5;
const relative = (b.vx - a.vx) * nx + (b.vz - a.vz) * nz;
if (relative < 0) {
// Equal masses, restitution .55.
const impulse = -(1 + .55) * relative / 2;
a.vx -= impulse * nx; a.vz -= impulse * nz;
b.vx += impulse * nx; b.vz += impulse * nz;
if (relative < -2) {
a.flash = .24; b.flash = .24;
if ((i === 0 || j === 0) && pairCooldown[i][j] <= 0) {
const points = Math.round(-relative * 25 / 10) * 10 + 100;
state.score += points;
impactEl.textContent = "RAM! +" + points;
impactTime = 1;
pairCooldown[i][j] = .75;
}
}
}
}
function syncTruck(t, dt) {
const y = groundHeight(t.x, t.z);
t.group.position.set(t.x, y, t.z);
t.group.rotation.y = t.angle;
const speed = Math.hypot(t.vx, t.vz);
for (const wheel of t.wheels) wheel.rotation.x += speed * dt * 1.8;
t.shadow.position.set(t.x, y + .035, t.z);
t.shadow.rotation.z = -t.angle;
t.flash = Math.max(0, t.flash - dt);
t.bodyMat.emissive.setHex(t.flash > 0 ? 0x995022 : 0x000000);
}
function step(dt) {
state.time = Math.max(0, state.time - dt);
gameTime += dt;
for (let i = 0; i < 5; i++) {
for (let j = i + 1; j < 5; j++) {
pairCooldown[i][j] = Math.max(0, pairCooldown[i][j] - dt);
}
}
for (const t of trucks) moveTruck(t, dt);
for (let i = 0; i < 5; i++) {
for (let j = i + 1; j < 5; j++) collideTrucks(trucks[i], trucks[j], i, j);
}
for (const t of trucks) syncTruck(t, dt);
impactTime = Math.max(0, impactTime - dt);
impactEl.style.opacity = String(Math.min(1, impactTime * 3));
if (state.time <= 0) {
state.over = true;
document.getElementById("finalScore").textContent =
Math.floor(state.score).toLocaleString("en-US");
finishEl.classList.add("visible");
}
updateHUD();
}
function updateCamera(dt) {
const fx = Math.sin(player.angle), fz = Math.cos(player.angle);
const y = groundHeight(player.x, player.z);
const desired = new THREE.Vector3(player.x - fx * 11, y + 8, player.z - fz * 11);
if (!cameraReady) {
camera.position.copy(desired);
cameraReady = true;
} else {
camera.position.lerp(desired, 1 - Math.exp(-3 * dt));
}
camera.lookAt(player.x + fx * 3, y + 1, player.z + fz * 3);
}
document.addEventListener("keydown", event => {
const key = event.key.toLowerCase();
if (["arrowup", "arrowdown", "arrowleft", "arrowright", " "].includes(key)) {
event.preventDefault();
}
if (key === "p" && !event.repeat) {
state.photo = !state.photo;
photoEl.classList.toggle("visible", state.photo);
document.getElementById("photoScore").textContent =
Math.floor(state.score).toLocaleString("en-US");
accumulator = 0;
last = performance.now();
return;
}
if (key === "r" && state.over && !state.photo && !event.repeat) {
resetGame();
return;
}
keys[key] = true;
});
document.addEventListener("keyup", event => {
keys[event.key.toLowerCase()] = false;
});
window.addEventListener("blur", () => {
for (const key in keys) keys[key] = false;
});
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
// Initialize the visible positions before the first simulation step.
for (const t of trucks) syncTruck(t, 0);
updateCamera(0);
updateHUD();
function frame(now) {
requestAnimationFrame(frame);
const elapsed = Math.min((now - last) / 1000, .1);
last = now;
if (!state.photo && !state.over) {
accumulator += elapsed;
const fixedStep = 1 / 60;
while (accumulator >= fixedStep && !state.over) {
step(fixedStep);
accumulator -= fixedStep;
}
updateCamera(elapsed);
} else {
accumulator = 0;
}
// Rendering continues in photo mode, but neither simulation nor camera moves.
renderer.render(scene, camera);
}
requestAnimationFrame(frame);
})();
</script>
</body>
</html>
const state = { time: isDemo ? 20 : 90, score: isDemo ? 5000 : 0, photo: false, over: false }; initializes the actual clock and score used by the simulation and HUD.P stops the physics steps, clock, and camera updates. The render loop continues drawing the frozen scene beneath the card.