Prompt specification
Build or customize the Three.js 3D scene "Clockwork Bridge Platform Challenge" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Clockwork Bridge Platform Challenge
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/clockwork-bridge-platform-challenge-x3479
Scene Description Prompt:
Use Three.js from cdnjs to build an original clockwork room with three periodic platforms and resting ledges. Use deterministic timing and visible mechanical supports so success depends on phase planning. Deliver one self-contained HTML file with visible voxel blocks.
Working Three.js Starter (clockwork-bridge-platform-challenge-x3479):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<title>Phase Shift — Clockwork Room</title>
<style>
:root {
--bg: #080d19;
--panel: rgba(10, 17, 31, 0.84);
--line: rgba(153, 190, 218, 0.22);
--text: #e9f3f5;
--muted: #8499aa;
--amber: #ffb84d;
--cyan: #53e0dc;
--pink: #ef77bd;
--danger: #ff667a;
}
* { box-sizing: border-box; }
html, body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family: "Courier New", Courier, monospace;
}
canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
button {
border: 1px solid rgba(255, 255, 255, 0.24);
border-radius: 3px;
background: rgba(255, 255, 255, 0.07);
color: var(--text);
padding: 9px 13px;
font: 700 12px/1 "Courier New", monospace;
letter-spacing: 0.08em;
cursor: pointer;
transition: 0.15s ease;
}
button:hover {
border-color: var(--cyan);
background: rgba(83, 224, 220, 0.12);
transform: translateY(-1px);
}
button.primary {
color: #071416;
border-color: var(--cyan);
background: var(--cyan);
box-shadow: 0 0 24px rgba(83, 224, 220, 0.2);
}
#hud {
position: fixed;
inset: 0;
pointer-events: none;
z-index: 5;
}
.topbar {
position: absolute;
top: 18px;
left: 20px;
right: 20px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 16px;
}
.brand {
padding: 13px 16px 14px;
background: linear-gradient(135deg, rgba(8, 14, 27, 0.93), rgba(8, 14, 27, 0.58));
border: 1px solid var(--line);
border-left: 3px solid var(--amber);
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.24);
}
.eyebrow {
color: var(--amber);
font-size: 10px;
letter-spacing: 0.2em;
margin-bottom: 5px;
}
h1 {
margin: 0;
font-size: 25px;
line-height: 1;
letter-spacing: 0.13em;
}
.subtitle {
color: var(--muted);
font-size: 10px;
letter-spacing: 0.12em;
margin-top: 8px;
}
.top-actions {
display: flex;
align-items: center;
gap: 8px;
pointer-events: auto;
}
.clock {
min-width: 104px;
padding: 11px 13px;
text-align: center;
background: var(--panel);
border: 1px solid var(--line);
color: var(--cyan);
font-size: 17px;
font-weight: 700;
letter-spacing: 0.1em;
}
.clock small {
display: block;
color: var(--muted);
font-size: 8px;
letter-spacing: 0.18em;
margin-top: 4px;
}
.route {
position: absolute;
left: 20px;
top: 122px;
width: 228px;
padding: 14px;
background: var(--panel);
border: 1px solid var(--line);
}
.panel-title {
color: var(--muted);
font-size: 9px;
letter-spacing: 0.19em;
margin-bottom: 11px;
}
.step {
position: relative;
display: flex;
align-items: center;
gap: 10px;
min-height: 32px;
color: #65788a;
font-size: 10px;
letter-spacing: 0.08em;
}
.step:not(:last-child)::after {
content: "";
position: absolute;
width: 1px;
height: 17px;
left: 8px;
top: 26px;
background: #314151;
}
.step-dot {
width: 17px;
height: 17px;
display: grid;
place-items: center;
flex: 0 0 auto;
border: 1px solid #455667;
background: #111b28;
color: #718394;
font-size: 8px;
}
.step.active {
color: var(--text);
}
.step.active .step-dot {
color: #061013;
background: var(--cyan);
border-color: var(--cyan);
box-shadow: 0 0 14px rgba(83, 224, 220, 0.4);
}
.step.done {
color: #8ca1ad;
}
.step.done .step-dot {
color: var(--cyan);
border-color: rgba(83, 224, 220, 0.65);
}
.safe-note {
border-top: 1px solid var(--line);
margin-top: 12px;
padding-top: 11px;
color: var(--muted);
font-size: 9px;
line-height: 1.55;
}
.safe-note b { color: var(--amber); }
.phase-dock {
position: absolute;
left: 50%;
bottom: 22px;
transform: translateX(-50%);
width: min(760px, calc(100vw - 32px));
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 10px;
}
.phase-card {
position: relative;
overflow: hidden;
padding: 12px 13px 10px;
background: var(--panel);
border: 1px solid var(--line);
backdrop-filter: blur(10px);
}
.phase-card::before {
content: "";
position: absolute;
inset: 0 auto 0 0;
width: 3px;
background: var(--device-color);
}
.phase-top {
display: flex;
align-items: center;
gap: 8px;
font-size: 10px;
letter-spacing: 0.09em;
}
.phase-number {
color: var(--device-color);
font-weight: 700;
}
.phase-name {
color: var(--muted);
}
.phase-state {
margin-left: auto;
color: var(--device-color);
font-size: 9px;
font-weight: 700;
}
.meter {
height: 5px;
margin: 10px 0 7px;
background: #202d3b;
overflow: hidden;
}
.meter i {
display: block;
width: 0;
height: 100%;
background: var(--device-color);
box-shadow: 0 0 12px var(--device-color);
}
.phase-detail {
color: #718596;
font-size: 8px;
letter-spacing: 0.08em;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.controls {
position: absolute;
right: 20px;
bottom: 22px;
padding: 10px 12px;
color: var(--muted);
background: rgba(8, 14, 27, 0.67);
border: 1px solid var(--line);
font-size: 9px;
line-height: 1.65;
letter-spacing: 0.05em;
}
.controls b { color: #cbd9df; }
#toast {
position: absolute;
top: 105px;
left: 50%;
transform: translate(-50%, -12px);
padding: 10px 15px;
background: rgba(8, 14, 27, 0.92);
border: 1px solid rgba(83, 224, 220, 0.5);
color: var(--cyan);
font-size: 10px;
letter-spacing: 0.08em;
opacity: 0;
transition: 0.22s ease;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
#pauseBadge {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
display: none;
padding: 16px 26px;
background: rgba(8, 14, 27, 0.92);
border: 1px solid var(--cyan);
color: var(--cyan);
font-weight: 700;
letter-spacing: 0.25em;
}
.screen {
position: fixed;
inset: 0;
z-index: 20;
display: grid;
place-items: center;
padding: 24px;
background: rgba(4, 8, 16, 0.66);
backdrop-filter: blur(7px);
opacity: 1;
transition: opacity 0.3s ease;
pointer-events: auto;
}
.screen.hidden {
opacity: 0;
pointer-events: none;
}
.modal {
width: min(560px, 100%);
padding: 30px;
background:
linear-gradient(135deg, rgba(16, 26, 42, 0.98), rgba(8, 14, 25, 0.98));
border: 1px solid rgba(150, 200, 220, 0.3);
box-shadow: 0 30px 100px rgba(0, 0, 0, 0.55), inset 0 0 0 1px rgba(255, 255, 255, 0.025);
}
.modal h2 {
margin: 8px 0 14px;
font-size: clamp(28px, 7vw, 48px);
line-height: 0.95;
letter-spacing: 0.08em;
}
.modal p {
color: #a6b6c1;
font-size: 12px;
line-height: 1.7;
}
.modal strong { color: var(--cyan); }
.modal-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 8px;
margin: 22px 0;
}
.modal-grid div {
padding: 12px 9px;
border: 1px solid var(--line);
background: rgba(255, 255, 255, 0.025);
color: var(--muted);
text-align: center;
font-size: 9px;
line-height: 1.45;
}
.modal-grid b {
display: block;
margin-bottom: 5px;
color: var(--text);
font-size: 15px;
}
.modal-actions {
display: flex;
align-items: center;
gap: 12px;
margin-top: 22px;
}
.modal-actions small {
color: var(--muted);
font-size: 9px;
line-height: 1.5;
}
.stat-row {
display: flex;
gap: 10px;
margin: 20px 0;
}
.stat {
flex: 1;
padding: 13px;
border: 1px solid var(--line);
color: var(--muted);
font-size: 9px;
}
.stat b {
display: block;
margin-top: 7px;
color: var(--cyan);
font-size: 19px;
}
#touchControls {
display: none;
position: fixed;
z-index: 10;
left: 18px;
right: 18px;
bottom: 145px;
justify-content: space-between;
pointer-events: none;
}
.touch-cluster {
display: flex;
gap: 8px;
}
#touchControls button {
width: 50px;
height: 50px;
padding: 0;
background: rgba(8, 14, 27, 0.75);
pointer-events: auto;
touch-action: none;
user-select: none;
}
@media (max-width: 950px) {
.route, .controls { display: none; }
.phase-dock { bottom: 14px; }
.phase-card { padding: 10px; }
.phase-detail { font-size: 7px; }
}
@media (max-width: 620px) {
.topbar { top: 10px; left: 10px; right: 10px; }
.brand { padding: 10px 12px; }
h1 { font-size: 18px; }
.subtitle { display: none; }
.clock { min-width: 78px; font-size: 13px; padding: 9px; }
.top-actions button { padding: 9px; }
#resetButton { display: none; }
.phase-dock {
grid-template-columns: 1fr;
width: 250px;
bottom: 10px;
}
.phase-card { min-height: 53px; }
.phase-card:nth-child(2), .phase-card:nth-child(3) { display: none; }
#toast { top: 80px; width: 80%; text-align: center; }
.modal { padding: 22px; }
.modal-grid { grid-template-columns: 1fr; }
}
@media (pointer: coarse) {
#touchControls { display: flex; }
.controls { display: none; }
.phase-dock { bottom: 10px; }
}
</style>
</head>
<body>
<canvas id="scene"></canvas>
<div id="hud">
<div class="topbar">
<div class="brand">
<div class="eyebrow">CLOCKWORK ROOM / SECTOR 07</div>
<h1>PHASE SHIFT</h1>
<div class="subtitle">THREE PERIODIC CARRIAGES · ONE MASTER CLOCK</div>
</div>
<div class="top-actions">
<div class="clock">
<span id="clockValue">00.00</span>
<small>MASTER CLOCK</small>
</div>
<button id="pauseButton" title="Pause or resume">PAUSE</button>
<button id="resetButton" title="Restart the master clock">RESET</button>
</div>
</div>
<div class="route">
<div class="panel-title">TRANSFER SEQUENCE</div>
<div class="step active" data-step="0">
<span class="step-dot">0</span><span>RESTING LEDGE / START</span>
</div>
<div class="step" data-step="1">
<span class="step-dot">1</span><span>AMBER SLIDER</span>
</div>
<div class="step" data-step="2">
<span class="step-dot">2</span><span>CYAN CARRIAGE</span>
</div>
<div class="step" data-step="3">
<span class="step-dot">3</span><span>PINK ROCKER</span>
</div>
<div class="step" data-step="4">
<span class="step-dot">4</span><span>EXIT BEACON</span>
</div>
<div class="safe-note"><b>SAFE:</b> resting ledges never move.<br>Fall into the lower works to recover.</div>
</div>
<div id="toast"></div>
<div id="pauseBadge">CLOCK PAUSED</div>
<div class="phase-dock">
<div class="phase-card" style="--device-color: var(--amber)">
<div class="phase-top">
<span class="phase-number">01</span>
<span class="phase-name">SLIDER</span>
<span class="phase-state" id="p1State">BOARDING</span>
</div>
<div class="meter"><i id="p1Meter"></i></div>
<div class="phase-detail" id="p1Detail">6.4 s cycle · west rail</div>
</div>
<div class="phase-card" style="--device-color: var(--cyan)">
<div class="phase-top">
<span class="phase-number">02</span>
<span class="phase-name">CARRIAGE</span>
<span class="phase-state" id="p2State">BOARDING</span>
</div>
<div class="meter"><i id="p2Meter"></i></div>
<div class="phase-detail" id="p2Detail">7.2 s cycle · near rail</div>
</div>
<div class="phase-card" style="--device-color: var(--pink)">
<div class="phase-top">
<span class="phase-number">03</span>
<span class="phase-name">ROCKER</span>
<span class="phase-state" id="p3State">BOARDING</span>
</div>
<div class="meter"><i id="p3Meter"></i></div>
<div class="phase-detail" id="p3Detail">10.0 s cycle · entry arc</div>
</div>
</div>
<div class="controls">
<b>WASD / ARROWS</b> move relative to camera<br>
<b>SPACE</b> short hop · <b>DRAG</b> orbit · <b>WHEEL</b> zoom<br>
<b>P</b> pause · <b>R</b> reset master clock
</div>
</div>
<div id="touchControls">
<div class="touch-cluster">
<button data-key="KeyA">◀</button>
<button data-key="KeyW">▲</button>
<button data-key="KeyS">▼</button>
<button data-key="KeyD">▶</button>
</div>
<div class="touch-cluster">
<button data-key="Space">HOP</button>
</div>
</div>
<div id="intro" class="screen">
<div class="modal">
<div class="eyebrow">CLOCKWORK TRANSFER PROTOCOL</div>
<h2>RIDE THE<br>PHASES.</h2>
<p>
The room has one deterministic master clock. Each mechanical platform follows
a fixed cycle, while the brass resting ledges remain safe and stationary.
<strong>Board during a green phase window, ride the carriage, and leave at the next ledge.</strong>
</p>
<div class="modal-grid">
<div><b>01</b>AMBER<br>linear slider</div>
<div><b>02</b>CYAN<br>linear carriage</div>
<div><b>03</b>PINK<br>curved rocker</div>
</div>
<p>Short hops can cover a small gap, but they cannot replace phase planning.</p>
<div class="modal-actions">
<button class="primary" id="startButton">ENGAGE CLOCK</button>
<small>WASD to move · SPACE to hop<br>All timings repeat from phase zero.</small>
</div>
</div>
</div>
<div id="win" class="screen hidden">
<div class="modal">
<div class="eyebrow">TRANSFER COMPLETE</div>
<h2>CLOCK<br>MASTERED.</h2>
<p>
You crossed all three periodic machines and reached the exit beacon.
The next room is already counting down.
</p>
<div class="stat-row">
<div class="stat">MASTER TIME<b id="winTime">0.00s</b></div>
<div class="stat">RECOVERIES<b id="winFalls">0</b></div>
<div class="stat">CYCLE<b>PERFECT</b></div>
</div>
<div class="modal-actions">
<button class="primary" id="againButton">RUN AGAIN</button>
<small>Resetting restores phase zero and every machine's initial position.</small>
</div>
</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// Constants and state
// -------------------------------------------------------------------------
const SURFACE_Y = 0.35;
const FIXED_STEP = 1 / 120;
const PLAYER_SPEED = 4.35;
const GRAVITY = 19.5;
const JUMP_SPEED = 7.1;
const canvas = document.getElementById("scene");
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.15;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x080d19);
scene.fog = new THREE.Fog(0x080d19, 24, 49);
const camera = new THREE.PerspectiveCamera(46, window.innerWidth / window.innerHeight, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, -0.2, -1.4);
const cameraState = {
yaw: 0.28,
phi: 0.82,
radius: 28
};
function updateCamera() {
const s = Math.sin(cameraState.phi);
camera.position.set(
cameraTarget.x + cameraState.radius * s * Math.sin(cameraState.yaw),
cameraTarget.y + cameraState.radius * Math.cos(cameraState.phi),
cameraTarget.z + cameraState.radius * s * Math.cos(cameraState.yaw)
);
camera.lookAt(cameraTarget);
}
updateCamera();
const hemi = new THREE.HemisphereLight(0x9bc8e2, 0x151322, 1.5);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffefd2, 2.7);
sun.position.set(-9, 18, 11);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -19;
sun.shadow.camera.right = 19;
sun.shadow.camera.top = 17;
sun.shadow.camera.bottom = -17;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 48;
sun.shadow.bias = -0.0004;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0x527cff, 1.1);
rimLight.position.set(13, 8, -14);
scene.add(rimLight);
const cubeGeometry = new THREE.BoxGeometry(1, 1, 1);
function material(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: options.roughness ?? 0.72,
metalness: options.metalness ?? 0.08,
flatShading: true,
emissive: options.emissive ?? 0x000000,
emissiveIntensity: options.emissiveIntensity ?? 0
});
}
const mats = {
floor: material(0xffffff, { roughness: 0.92, metalness: 0.04 }),
wall: material(0x202c3d, { roughness: 0.9 }),
wallAlt: material(0x28374a, { roughness: 0.85 }),
dark: material(0x111925, { roughness: 0.78, metalness: 0.22 }),
steel: material(0x627383, { roughness: 0.38, metalness: 0.72 }),
steelDark: material(0x283542, { roughness: 0.45, metalness: 0.68 }),
brass: material(0xb8873c, { roughness: 0.34, metalness: 0.68 }),
amber: material(0xd78b32, { roughness: 0.62, metalness: 0.18 }),
amberLight: material(0xffbd55, {
roughness: 0.35,
metalness: 0.15,
emissive: 0xff9f27,
emissiveIntensity: 0.8
}),
cyan: material(0x278c92, { roughness: 0.6, metalness: 0.2 }),
cyanLight: material(0x62f1e7, {
roughness: 0.35,
metalness: 0.12,
emissive: 0x28bfc0,
emissiveIntensity: 0.8
}),
pink: material(0x9f477d, { roughness: 0.62, metalness: 0.18 }),
pinkLight: material(0xff83c5, {
roughness: 0.35,
metalness: 0.12,
emissive: 0xdb3f99,
emissiveIntensity: 0.85
}),
player: material(0xe6e0cd, { roughness: 0.7 }),
playerDark: material(0x243547, { roughness: 0.72 }),
visor: material(0x6ff4e8, {
roughness: 0.25,
metalness: 0.25,
emissive: 0x35e4dc,
emissiveIntensity: 1.4
})
};
function block(parent, sx, sy, sz, mat, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(cubeGeometry, mat);
mesh.scale.set(sx, sy, sz);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
// -------------------------------------------------------------------------
// Voxel room
// -------------------------------------------------------------------------
const floorGeometry = new THREE.BoxGeometry(0.96, 0.35, 0.96);
const floorMesh = new THREE.InstancedMesh(floorGeometry, mats.floor, 30 * 24);
const dummy = new THREE.Object3D();
const colorA = new THREE.Color(0x182332);
const colorB = new THREE.Color(0x202d3c);
const colorC = new THREE.Color(0x111b29);
let floorIndex = 0;
for (let iz = 0; iz < 24; iz++) {
for (let ix = 0; ix < 30; ix++) {
dummy.position.set(-14.5 + ix, -3.05, -11.5 + iz);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
floorMesh.setMatrixAt(floorIndex, dummy.matrix);
const checker = (ix + iz) % 2;
floorMesh.setColorAt(floorIndex, checker ? colorA : colorB);
if ((ix === 14 || iz === 11) && (ix + iz) % 3 === 0) {
floorMesh.setColorAt(floorIndex, colorC);
}
floorIndex++;
}
}
floorMesh.instanceMatrix.needsUpdate = true;
floorMesh.instanceColor.needsUpdate = true;
floorMesh.receiveShadow = true;
scene.add(floorMesh);
// Rear wall, made from individually visible blocks.
for (let x = -15; x <= 15; x++) {
for (let row = 0; row < 4; row++) {
block(
scene, 0.96, 0.96, 0.96,
(x + row) % 3 === 0 ? mats.wallAlt : mats.wall,
x, -2.5 + row, -12
);
}
}
// Left wall and a short right wall leave the route open to the camera.
for (let z = -11; z <= 11; z++) {
for (let row = 0; row < 4; row++) {
block(
scene, 0.96, 0.96, 0.96,
(z + row) % 4 === 0 ? mats.wallAlt : mats.wall,
-15, -2.5 + row, z
);
}
}
for (let z = -11; z <= -5; z++) {
for (let row = 0; row < 4; row++) {
block(
scene, 0.96, 0.96, 0.96,
(z + row) % 3 === 0 ? mats.wallAlt : mats.wall,
15, -2.5 + row, z
);
}
}
// Large clockwork gear mounted on the rear wall.
function makeGear(radius, mainMat, toothMat, teeth = 12) {
const group = new THREE.Group();
block(group, radius * 0.82, 0.42, radius * 0.82, mainMat);
block(group, radius * 1.9, 0.27, 0.32, mainMat);
block(group, 0.32, 0.27, radius * 1.9, mainMat);
for (let i = 0; i < teeth; i++) {
const a = (i / teeth) * Math.PI * 2;
const tooth = block(
group, 0.58, 0.46, 0.68, toothMat,
Math.cos(a) * radius, 0, Math.sin(a) * radius
);
tooth.rotation.y = -a;
}
return group;
}
const wallGearMount = new THREE.Group();
wallGearMount.position.set(0, 2.8, -11.45);
wallGearMount.rotation.x = Math.PI / 2;
scene.add(wallGearMount);
const wallGear = makeGear(1.85, mats.brass, mats.amber);
wallGearMount.add(wallGear);
block(scene, 1.1, 4.2, 1.1, mats.steelDark, 0, -0.6, -11.5);
block(scene, 2.4, 0.45, 1.0, mats.steel, 0, 0.65, -11.5);
// -------------------------------------------------------------------------
// Resting ledges
// -------------------------------------------------------------------------
const fixedSurfaces = [];
const movingSurfaces = [];
function createLedge(id, label, x, z, width, depth, accentMat, checkpoint) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
const nx = Math.max(5, Math.round(width / 0.56));
const nz = Math.max(5, Math.round(depth / 0.56));
const sx = width / nx;
const sz = depth / nz;
for (let ix = 0; ix < nx; ix++) {
for (let iz = 0; iz < nz; iz++) {
const px = -width / 2 + sx * (ix + 0.5);
const pz = -depth / 2 + sz * (iz + 0.5);
const edge = ix === 0 || ix === nx - 1 || iz === 0 || iz === nz - 1;
block(
group, sx * 0.91, 0.42, sz * 0.91,
edge ? accentMat : (ix + iz) % 2 ? mats.steel : mats.steelDark,
px, SURFACE_Y - 0.21, pz
);
}
}
// Central pedestal, assembled from stacked cubes.
for (let i = 0; i < 4; i++) {
block(
group, 1.18 - i * 0.08, 0.52, 1.18 - i * 0.08,
i % 2 ? mats.steelDark : mats.steel,
0, -0.48 - i * 0.55, 0
);
}
// Four bright corner lamps make safe ledges readable from a distance.
for (const dx of [-1, 1]) {
for (const dz of [-1, 1]) {
block(
group, 0.19, 0.23, 0.19, accentMat,
dx * (width / 2 - 0.17), SURFACE_Y + 0.10, dz * (depth / 2 - 0.17)
);
}
}
const surface = {
id,
type: "fixed",
x, z,
hx: width / 2,
hz: depth / 2,
top: SURFACE_Y,
checkpoint,
label
};
fixedSurfaces.push(surface);
return surface;
}
const startSurface = createLedge(
"rest-0", "REST 0", -10, 7, 3.4, 3.4, mats.amberLight, 0
);
const ledgeOne = createLedge(
"rest-1", "REST 1", 1, 7, 3.4, 3.4, mats.cyanLight, 1
);
const ledgeTwo = createLedge(
"rest-2", "REST 2", 1, -6.5, 3.4, 3.4, mats.pinkLight, 2
);
const exitSurface = createLedge(
"exit", "EXIT", 11, -6.5, 3.6, 3.6, mats.cyanLight, 3
);
function makeSpriteLabel(text, color, x, y, z) {
const c = document.createElement("canvas");
c.width = 512;
c.height = 128;
const ctx = c.getContext("2d");
ctx.fillStyle = "rgba(7, 13, 24, 0.9)";
ctx.fillRect(0, 0, c.width, c.height);
ctx.strokeStyle = color;
ctx.lineWidth = 8;
ctx.strokeRect(4, 4, c.width - 8, c.height - 8);
ctx.fillStyle = color;
ctx.font = "bold 44px monospace";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillText(text, c.width / 2, c.height / 2 + 2);
const texture = new THREE.CanvasTexture(c);
texture.colorSpace = THREE.SRGBColorSpace;
texture.minFilter = THREE.LinearFilter;
const sprite = new THREE.Sprite(new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthWrite: false
}));
sprite.position.set(x, y, z);
sprite.scale.set(3.1, 0.78, 1);
scene.add(sprite);
return sprite;
}
makeSpriteLabel("REST 0 / START", "#ffbf55", -10, 2.15, 8.8);
makeSpriteLabel("REST 1", "#62f1e7", 1, 2.15, 8.8);
makeSpriteLabel("REST 2", "#ff83c5", 1, 2.15, -8.25);
makeSpriteLabel("EXIT BEACON", "#62f1e7", 11, 2.15, -8.25);
// -------------------------------------------------------------------------
// Moving platforms and their visible mechanical supports
// -------------------------------------------------------------------------
function createMovingPlatform(id, accentMat, lampMat) {
const group = new THREE.Group();
scene.add(group);
const n = 5;
const cell = 0.56;
for (let ix = 0; ix < n; ix++) {
for (let iz = 0; iz < n; iz++) {
const edge = ix === 0 || ix === n - 1 || iz === 0 || iz === n - 1;
block(
group, cell * 0.9, 0.38, cell * 0.9,
edge ? accentMat : ((ix + iz) % 2 ? mats.steel : mats.steelDark),
(ix - 2) * cell, SURFACE_Y - 0.19, (iz - 2) * cell
);
}
}
block(group, 2.35, 0.35, 2.35, mats.dark, 0, -0.35, 0);
block(group, 0.46, 0.48, 2.65, mats.steelDark, 0, -0.55, 0);
block(group, 2.65, 0.48, 0.46, mats.steelDark, 0, -0.55, 0);
for (const dx of [-1, 1]) {
for (const dz of [-1, 1]) {
block(group, 0.18, 0.22, 0.18, lampMat, dx * 1.1, SURFACE_Y + 0.10, dz * 1.1);
}
}
const surface = {
id,
type: "moving",
x: 0, z: 0,
hx: 1.37,
hz: 1.37,
top: SURFACE_Y,
dx: 0,
dz: 0,
group,
lampMat
};
movingSurfaces.push(surface);
return surface;
}
const p1 = createMovingPlatform("slider", mats.amber, mats.amberLight);
const p2 = createMovingPlatform("carriage", mats.cyan, mats.cyanLight);
const p3 = createMovingPlatform("rocker", mats.pink, mats.pinkLight);
// Amber slider rails.
for (const railZ of [5.45, 8.55]) {
for (let x = -8.25; x <= 0.4; x += 0.58) {
block(scene, 0.53, 0.24, 0.38, mats.steelDark, x, -0.28, railZ);
}
for (const supportX of [-7.9, -4.2, -0.3]) {
for (let y = -2.55; y < -0.5; y += 0.55) {
block(scene, 0.48, 0.5, 0.48, mats.steel, supportX, y, railZ);
}
}
}
const p1Gear = makeGear(1.05, mats.brass, mats.amber, 10);
p1Gear.position.set(-7, -0.5, 7);
scene.add(p1Gear);
// Cyan carriage rails.
for (const railX of [-0.55, 2.55]) {
for (let z = -5.45; z <= 5.45; z += 0.58) {
block(scene, 0.38, 0.24, 0.53, mats.steelDark, railX, -0.28, z);
}
for (const supportZ of [-4.9, -1.2, 2.5, 5]) {
for (let y = -2.55; y < -0.5; y += 0.55) {
block(scene, 0.48, 0.5, 0.48, mats.steel, railX, y, supportZ);
}
}
}
const p2Gear = makeGear(1.05, mats.steel, mats.cyanLight, 10);
p2Gear.position.set(1, -0.5, 4.4);
scene.add(p2Gear);
// Pink rocker: a visible curved rail, central pivot and rotating arm.
const p3Center = new THREE.Vector3(6, 0, -6.5);
const p3Radius = 3.5;
for (let i = 0; i <= 28; i++) {
const a = Math.PI + (i / 28) * Math.PI;
const x = p3Center.x + Math.cos(a) * p3Radius;
const z = p3Center.z + Math.sin(a) * p3Radius;
const tie = block(scene, 0.5, 0.24, 0.5, mats.steelDark, x, -0.42, z);
tie.rotation.y = -a;
}
const p3Gear = makeGear(1.4, mats.brass, mats.pinkLight, 14);
p3Gear.position.set(p3Center.x, -0.55, p3Center.z);
scene.add(p3Gear);
const armPivot = new THREE.Group();
armPivot.position.copy(p3Center);
scene.add(armPivot);
block(armPivot, p3Radius, 0.28, 0.42, mats.steel, p3Radius / 2, -0.56, 0);
block(armPivot, 0.52, 0.42, 0.85, mats.brass, p3Radius, -0.56, 0);
// Small phase beacons at the boarding positions.
function makeBeacon(x, z, mat) {
for (let i = 0; i < 3; i++) {
block(scene, 0.28, 0.52, 0.28, mats.steelDark, x, -1.8 + i * 0.55, z);
}
block(scene, 0.46, 0.42, 0.46, mat, x, 0.2, z);
}
makeBeacon(-8.6, 8.65, mats.amberLight);
makeBeacon(2.7, 5.55, mats.cyanLight);
makeBeacon(1.0, -6.5, mats.pinkLight);
// Exit beacon tower.
const goalCubes = [];
for (let i = 0; i < 5; i++) {
const cube = block(
scene, 0.5 - i * 0.035, 0.42, 0.5 - i * 0.035,
mats.cyanLight, 12.35, 0.55 + i * 0.45, -7.45
);
goalCubes.push(cube);
}
const goalLight = new THREE.PointLight(0x50eee3, 2.4, 7, 2);
goalLight.position.set(12.3, 2.2, -7.4);
scene.add(goalLight);
// -------------------------------------------------------------------------
// Deterministic phase functions
// -------------------------------------------------------------------------
const clamp01 = x => Math.max(0, Math.min(1, x));
const smooth = x => {
x = clamp01(x);
return x * x * (3 - 2 * x);
};
const lerp = (a, b, t) => a + (b - a) * t;
function sliderMotion(time) {
const period = 6.4;
const c = time % period;
let value, state, detail;
if (c < 1.1) {
value = -7;
state = "BOARDING";
detail = "west hold · 1.1 s";
} else if (c < 3.0) {
value = lerp(-7, -1, smooth((c - 1.1) / 1.9));
state = "IN TRANSIT";
detail = "moving east";
} else if (c < 4.2) {
value = -1;
state = "EXIT READY";
detail = "east hold · 1.2 s";
} else if (c < 6.0) {
value = lerp(-1, -7, smooth((c - 4.2) / 1.8));
state = "RETURNING";
detail = "moving west";
} else {
value = -7;
state = "BOARDING";
detail = "west hold · 0.4 s";
}
return { value, state, detail, progress: c / period, period, cycleTime: c };
}
function carriageMotion(time) {
const period = 7.2;
const c = time % period;
let value, state, detail;
if (c < 0.9) {
value = 4.4;
state = "BOARDING";
detail = "near hold · 0.9 s";
} else if (c < 3.1) {
value = lerp(4.4, -4.4, smooth((c - 0.9) / 2.2));
state = "IN TRANSIT";
detail = "moving north";
} else if (c < 4.4) {
value = -4.4;
state = "EXIT READY";
detail = "far hold · 1.3 s";
} else if (c < 6.6) {
value = lerp(-4.4, 4.4, smooth((c - 4.4) / 2.2));
state = "RETURNING";
detail = "moving south";
} else {
value = 4.4;
state = "BOARDING";
detail = "near hold · 0.6 s";
}
return { value, state, detail, progress: c / period, period, cycleTime: c };
}
function rockerMotion(time) {
const period = 10;
const c = time % period;
let angle, state, detail;
if (c < 1.2) {
angle = Math.PI;
state = "BOARDING";
detail = "entry hold · 1.2 s";
} else if (c < 4.2) {
angle = Math.PI + Math.PI * smooth((c - 1.2) / 3.0);
state = "IN TRANSIT";
detail = "arc toward exit";
} else if (c < 5.4) {
angle = Math.PI * 2;
state = "EXIT READY";
detail = "exit hold · 1.2 s";
} else if (c < 8.4) {
angle = Math.PI * 2 + Math.PI * smooth((c - 5.4) / 3.0);
state = "RETURNING";
detail = "arc toward entry";
} else {
angle = Math.PI * 3;
state = "BOARDING";
detail = "entry hold · 1.6 s";
}
return {
angle,
state,
detail,
progress: c / period,
period,
cycleTime: c
};
}
let currentP1 = sliderMotion(0);
let currentP2 = carriageMotion(0);
let currentP3 = rockerMotion(0);
function updatePlatforms(time) {
currentP1 = sliderMotion(time);
currentP2 = carriageMotion(time);
currentP3 = rockerMotion(time);
const p1X = currentP1.value;
p1.dx = p1X - p1.x;
p1.x = p1X;
p1.group.position.set(p1.x, 0, 7);
const p2Z = currentP2.value;
p2.dz = p2Z - p2.z;
p2.z = p2Z;
p2.group.position.set(1, 0, p2.z);
const a = currentP3.angle;
const p3X = p3Center.x + Math.cos(a) * p3Radius;
const p3Z = p3Center.z + Math.sin(a) * p3Radius;
p3.dx = p3X - p3.x;
p3.dz = p3Z - p3.z;
p3.x = p3X;
p3.z = p3Z;
p3.group.position.set(p3.x, 0, p3.z);
p1Gear.rotation.y = -time * 1.4;
p2Gear.rotation.y = time * 1.25;
p3Gear.rotation.y = -a * 1.8;
armPivot.rotation.y = -a;
wallGear.rotation.y = time * 0.24;
}
updatePlatforms(0);
// -------------------------------------------------------------------------
// Voxel player
// -------------------------------------------------------------------------
const playerGroup = new THREE.Group();
scene.add(playerGroup);
const playerVisual = new THREE.Group();
playerGroup.add(playerVisual);
const playerTorso = block(playerVisual, 0.66, 0.70, 0.43, mats.player, 0, 0.88, 0);
const playerHead = block(playerVisual, 0.56, 0.52, 0.52, mats.player, 0, 1.49, 0);
block(playerVisual, 0.48, 0.11, 0.56, mats.playerDark, 0, 1.73, 0);
block(playerVisual, 0.12, 0.13, 0.08, mats.visor, -0.14, 1.51, 0.285);
block(playerVisual, 0.12, 0.13, 0.08, mats.visor, 0.14, 1.51, 0.285);
block(playerVisual, 0.28, 0.18, 0.10, mats.amberLight, 0, 0.97, 0.245);
const leftArm = block(playerVisual, 0.19, 0.60, 0.22, mats.playerDark, -0.44, 0.88, 0);
const rightArm = block(playerVisual, 0.19, 0.60, 0.22, mats.playerDark, 0.44, 0.88, 0);
const leftLeg = block(playerVisual, 0.23, 0.48, 0.25, mats.playerDark, -0.19, 0.26, 0);
const rightLeg = block(playerVisual, 0.23, 0.48, 0.25, mats.playerDark, 0.19, 0.26, 0);
const player = {
position: new THREE.Vector3(-10, SURFACE_Y, 7),
velocity: new THREE.Vector3(),
grounded: startSurface,
facing: Math.PI
};
// -------------------------------------------------------------------------
// Input and direct camera controls
// -------------------------------------------------------------------------
const keys = new Set();
let jumpQueued = false;
let started = false;
let paused = false;
let won = false;
let simTime = 0;
let accumulator = 0;
let checkpointIndex = 0;
let checkpointSurface = startSurface;
let recoveries = 0;
const movementCodes = new Set([
"KeyW", "KeyA", "KeyS", "KeyD",
"ArrowUp", "ArrowLeft", "ArrowDown", "ArrowRight"
]);
window.addEventListener("keydown", event => {
if (movementCodes.has(event.code) || event.code === "Space") {
event.preventDefault();
}
keys.add(event.code);
if (!event.repeat && event.code === "Space" && started && !paused && !won) {
jumpQueued = true;
}
if (!event.repeat && (event.code === "KeyP" || event.code === "Escape")) {
togglePause();
}
if (!event.repeat && event.code === "KeyR") {
resetGame(true);
}
});
window.addEventListener("keyup", event => keys.delete(event.code));
window.addEventListener("blur", () => {
keys.clear();
jumpQueued = false;
});
document.querySelectorAll("#touchControls button").forEach(button => {
const code = button.dataset.key;
button.addEventListener("pointerdown", event => {
event.preventDefault();
button.setPointerCapture(event.pointerId);
keys.add(code);
if (code === "Space") jumpQueued = true;
});
const release = event => {
event.preventDefault();
keys.delete(code);
};
button.addEventListener("pointerup", release);
button.addEventListener("pointercancel", release);
});
let dragging = false;
let lastPointerX = 0;
let lastPointerY = 0;
canvas.addEventListener("pointerdown", event => {
dragging = true;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", event => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
cameraState.yaw -= dx * 0.005;
cameraState.phi = Math.max(0.48, Math.min(1.22, cameraState.phi + dy * 0.004));
updateCamera();
});
const stopDragging = () => { dragging = false; };
canvas.addEventListener("pointerup", stopDragging);
canvas.addEventListener("pointercancel", stopDragging);
canvas.addEventListener("contextmenu", event => event.preventDefault());
canvas.addEventListener("wheel", event => {
event.preventDefault();
cameraState.radius = Math.max(19, Math.min(39, cameraState.radius + event.deltaY * 0.012));
updateCamera();
}, { passive: false });
// -------------------------------------------------------------------------
// HUD, game flow and reset
// -------------------------------------------------------------------------
const intro = document.getElementById("intro");
const winScreen = document.getElementById("win");
const toast = document.getElementById("toast");
const pauseBadge = document.getElementById("pauseBadge");
const pauseButton = document.getElementById("pauseButton");
const clockValue = document.getElementById("clockValue");
const stepElements = [...document.querySelectorAll("[data-step]")];
let toastTimer = 0;
function showToast(message) {
toast.textContent = message;
toast.classList.add("show");
clearTimeout(toastTimer);
toastTimer = setTimeout(() => toast.classList.remove("show"), 2200);
}
function updateSteps() {
stepElements.forEach((element, index) => {
element.classList.toggle("done", index < checkpointIndex);
element.classList.toggle("active", index === checkpointIndex);
});
}
function togglePause() {
if (!started || won) return;
paused = !paused;
pauseBadge.style.display = paused ? "block" : "none";
pauseButton.textContent = paused ? "RESUME" : "PAUSE";
keys.clear();
}
function resetGame(playImmediately) {
simTime = 0;
accumulator = 0;
paused = false;
won = false;
recoveries = 0;
checkpointIndex = 0;
checkpointSurface = startSurface;
updatePlatforms(0);
player.position.set(checkpointSurface.x, SURFACE_Y, checkpointSurface.z);
player.velocity.set(0, 0, 0);
player.grounded = checkpointSurface;
player.facing = Math.PI;
keys.clear();
jumpQueued = false;
pauseBadge.style.display = "none";
pauseButton.textContent = "PAUSE";
winScreen.classList.add("hidden");
updateSteps();
if (playImmediately) {
started = true;
intro.classList.add("hidden");
showToast("MASTER CLOCK ENGAGED · PHASE ZERO");
}
}
document.getElementById("startButton").addEventListener("click", () => resetGame(true));
document.getElementById("againButton").addEventListener("click", () => resetGame(true));
document.getElementById("resetButton").addEventListener("click", () => resetGame(true));
pauseButton.addEventListener("click", togglePause);
function recoverPlayer() {
recoveries++;
player.position.set(checkpointSurface.x, SURFACE_Y, checkpointSurface.z);
player.velocity.set(0, 0, 0);
player.grounded = checkpointSurface;
jumpQueued = false;
showToast(`RECOVERED TO ${checkpointSurface.label} · MASTER CLOCK CONTINUES`);
}
function completeGame() {
if (won) return;
won = true;
document.getElementById("winTime").textContent = `${simTime.toFixed(2)}s`;
document.getElementById("winFalls").textContent = String(recoveries);
winScreen.classList.remove("hidden");
keys.clear();
}
// -------------------------------------------------------------------------
// Fixed-step simulation
// -------------------------------------------------------------------------
const forwardVector = new THREE.Vector3();
const rightVector = new THREE.Vector3();
const desiredDirection = new THREE.Vector3();
const worldUp = new THREE.Vector3(0, 1, 0);
function surfaceContains(surface, x, z) {
return Math.abs(x - surface.x) <= surface.hx &&
Math.abs(z - surface.z) <= surface.hz;
}
function handleLanding(surface) {
if (surface.type === "fixed") {
if (surface.checkpoint > checkpointIndex) {
checkpointIndex = surface.checkpoint;
checkpointSurface = surface;
updateSteps();
if (surface === exitSurface) {
showToast("EXIT BEACON REACHED");
completeGame();
} else {
showToast(`${surface.label} SECURED · CHECKPOINT SAVED`);
}
}
}
}
function fixedUpdate(dt) {
simTime += dt;
updatePlatforms(simTime);
// Moving surfaces carry a standing player by their exact frame delta.
if (player.grounded && player.grounded.type === "moving") {
player.position.x += player.grounded.dx;
player.position.z += player.grounded.dz;
}
camera.getWorldDirection(forwardVector);
forwardVector.y = 0;
forwardVector.normalize();
rightVector.crossVectors(forwardVector, worldUp).normalize();
let forwardInput = 0;
let rightInput = 0;
if (keys.has("KeyW") || keys.has("ArrowUp")) forwardInput += 1;
if (keys.has("KeyS") || keys.has("ArrowDown")) forwardInput -= 1;
if (keys.has("KeyD") || keys.has("ArrowRight")) rightInput += 1;
if (keys.has("KeyA") || keys.has("ArrowLeft")) rightInput -= 1;
desiredDirection.set(0, 0, 0);
desiredDirection.addScaledVector(forwardVector, forwardInput);
desiredDirection.addScaledVector(rightVector, rightInput);
const inputLength = desiredDirection.length();
if (inputLength > 1) desiredDirection.multiplyScalar(1 / inputLength);
if (jumpQueued) {
if (player.grounded) {
player.velocity.y = JUMP_SPEED;
player.grounded = null;
}
jumpQueued = false;
}
const acceleration = player.grounded ? 13 : 7;
const blend = 1 - Math.exp(-acceleration * dt);
player.velocity.x = lerp(
player.velocity.x,
desiredDirection.x * PLAYER_SPEED,
blend
);
player.velocity.z = lerp(
player.velocity.z,
desiredDirection.z * PLAYER_SPEED,
blend
);
player.position.x += player.velocity.x * dt;
player.position.z += player.velocity.z * dt;
// Keep the player within the visible room.
player.position.x = Math.max(-14.25, Math.min(14.25, player.position.x));
player.position.z = Math.max(-11.25, Math.min(11.25, player.position.z));
if (inputLength > 0.05) {
const targetFacing = Math.atan2(desiredDirection.x, desiredDirection.z);
let difference = targetFacing - player.facing;
while (difference > Math.PI) difference -= Math.PI * 2;
while (difference < -Math.PI) difference += Math.PI * 2;
player.facing += difference * Math.min(1, dt * 13);
}
// A grounded player remains grounded only while still over that surface.
if (player.grounded) {
if (surfaceContains(player.grounded, player.position.x, player.position.z)) {
player.position.y = player.grounded.top;
player.velocity.y = 0;
} else {
player.grounded = null;
player.velocity.y = 0;
}
}
const previousY = player.position.y;
if (!player.grounded) {
player.velocity.y -= GRAVITY * dt;
player.position.y += player.velocity.y * dt;
let landing = null;
if (player.velocity.y <= 0) {
const allSurfaces = [...fixedSurfaces, ...movingSurfaces];
for (const surface of allSurfaces) {
if (!surfaceContains(surface, player.position.x, player.position.z)) continue;
const crossedTop =
previousY >= surface.top - 0.065 &&
player.position.y <= surface.top + 0.018;
if (crossedTop && (!landing || surface.top > landing.top)) {
landing = surface;
}
}
}
if (landing) {
player.position.y = landing.top;
player.velocity.y = 0;
player.grounded = landing;
handleLanding(landing);
}
}
if (player.position.y < -1.72) {
recoverPlayer();
}
}
// -------------------------------------------------------------------------
// Player animation and phase display
// -------------------------------------------------------------------------
function updatePlayerVisual() {
playerGroup.position.copy(player.position);
playerGroup.rotation.y = player.facing;
const horizontalSpeed = Math.hypot(player.velocity.x, player.velocity.z);
const walkAmount = Math.min(1, horizontalSpeed / PLAYER_SPEED);
const stride = Math.sin(simTime * 12) * 0.55 * walkAmount;
leftLeg.rotation.x = stride;
rightLeg.rotation.x = -stride;
leftArm.rotation.x = -stride * 0.8;
rightArm.rotation.x = stride * 0.8;
playerVisual.position.y = player.grounded
? Math.abs(Math.sin(simTime * 12)) * 0.035 * walkAmount
: 0;
const tilt = Math.min(0.1, horizontalSpeed * 0.018);
playerVisual.rotation.z = -player.velocity.x * 0.018;
playerVisual.rotation.x = tilt;
}
const p1State = document.getElementById("p1State");
const p2State = document.getElementById("p2State");
const p3State = document.getElementById("p3State");
const p1Meter = document.getElementById("p1Meter");
const p2Meter = document.getElementById("p2Meter");
const p3Meter = document.getElementById("p3Meter");
const p1Detail = document.getElementById("p1Detail");
const p2Detail = document.getElementById("p2Detail");
const p3Detail = document.getElementById("p3Detail");
function updateHUD() {
clockValue.textContent = simTime.toFixed(2).padStart(5, "0");
p1State.textContent = currentP1.state;
p2State.textContent = currentP2.state;
p3State.textContent = currentP3.state;
p1Meter.style.width = `${currentP1.progress * 100}%`;
p2Meter.style.width = `${currentP2.progress * 100}%`;
p3Meter.style.width = `${currentP3.progress * 100}%`;
p1Detail.textContent = `6.4 s cycle · ${currentP1.detail}`;
p2Detail.textContent = `7.2 s cycle · ${currentP2.detail}`;
p3Detail.textContent = `10.0 s cycle · ${currentP3.detail}`;
p1.lampMat.emissiveIntensity = currentP1.state.includes("READY") ||
currentP1.state === "BOARDING" ? 1.5 : 0.55;
p2.lampMat.emissiveIntensity = currentP2.state.includes("READY") ||
currentP2.state === "BOARDING" ? 1.5 : 0.55;
p3.lampMat.emissiveIntensity = currentP3.state.includes("READY") ||
currentP3.state === "BOARDING" ? 1.5 : 0.55;
for (let i = 0; i < goalCubes.length; i++) {
goalCubes[i].rotation.y = simTime * (0.6 + i * 0.08);
goalCubes[i].position.y = 0.55 + i * 0.45 + Math.sin(simTime * 2 + i) * 0.05;
}
goalLight.intensity = 2.1 + Math.sin(simTime * 3.1) * 0.5;
}
// -------------------------------------------------------------------------
// Render loop
// -------------------------------------------------------------------------
let previousFrameTime = performance.now();
function frame(now) {
requestAnimationFrame(frame);
const frameDelta = Math.min((now - previousFrameTime) / 1000, 0.1);
previousFrameTime = now;
if (started && !paused && !won) {
accumulator += frameDelta;
while (accumulator >= FIXED_STEP) {
fixedUpdate(FIXED_STEP);
accumulator -= FIXED_STEP;
}
}
updatePlayerVisual();
updateHUD();
renderer.render(scene, camera);
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
updateSteps();
requestAnimationFrame(frame);
</script>
</body>
</html>
```