Prompt specification
Build or customize the Three.js 3D scene "Cooperative Bridge Tile Game" 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: Cooperative Bridge Tile Game
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/cooperative-bridge-tile-game-x3220
Scene Description Prompt:
Create a single self-contained HTML file using Three.js from cdnjs that shows coordinated movement of a shared load. Create a small puzzle where two characters must hold separate supports before a crossing tile stays level. Release either support and demonstrate the rule consistently. Low-poly.
Working Three.js Starter (cooperative-bridge-tile-game-x3220):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="theme-color" content="#dce8e2" />
<title>Bridgekeepers — A Shared Load Puzzle</title>
<style>
:root {
--ink: #18323b;
--muted: #64777b;
--panel: rgba(250, 249, 242, 0.86);
--line: rgba(24, 50, 59, 0.12);
--teal: #24a995;
--teal-dark: #147565;
--coral: #ee725d;
--gold: #e5ad42;
--danger: #c94d48;
--shadow: 0 16px 45px rgba(35, 59, 64, 0.16);
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #dce8e2;
color: var(--ink);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
#scene {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
#scene:active {
cursor: grabbing;
}
.vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 46%, transparent 45%, rgba(21, 44, 51, 0.09) 100%),
linear-gradient(to bottom, rgba(255, 255, 255, 0.12), transparent 25%);
}
.panel {
background: var(--panel);
border: 1px solid rgba(255, 255, 255, 0.64);
box-shadow: var(--shadow);
backdrop-filter: blur(14px) saturate(1.15);
-webkit-backdrop-filter: blur(14px) saturate(1.15);
}
.brief {
position: fixed;
top: 24px;
left: 24px;
width: min(370px, calc(100vw - 48px));
padding: 20px 22px 18px;
border-radius: 22px;
pointer-events: none;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
color: var(--teal-dark);
font-size: 10px;
font-weight: 850;
letter-spacing: 0.18em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 20px;
height: 2px;
border-radius: 2px;
background: var(--teal);
}
h1 {
margin: 0;
font-size: clamp(27px, 3vw, 39px);
line-height: 0.98;
letter-spacing: -0.055em;
}
.brief p {
margin: 12px 0 14px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.rule {
display: flex;
align-items: center;
gap: 9px;
padding: 10px 12px;
border: 1px solid rgba(36, 169, 149, 0.16);
border-radius: 12px;
background: rgba(36, 169, 149, 0.075);
color: #37605d;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.rule span {
flex: 0 0 auto;
width: 8px;
height: 8px;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 0 4px rgba(36, 169, 149, 0.12);
}
.status-card {
position: fixed;
top: 24px;
right: 24px;
width: 255px;
padding: 15px 17px;
border-radius: 18px;
pointer-events: none;
}
.status-row {
display: flex;
align-items: center;
gap: 10px;
}
.status-dot {
width: 11px;
height: 11px;
flex: 0 0 auto;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 0 5px rgba(36, 169, 149, 0.12);
transition: 180ms ease;
}
.status-card[data-state="warning"] .status-dot {
background: var(--gold);
box-shadow: 0 0 0 5px rgba(229, 173, 66, 0.14);
}
.status-card[data-state="danger"] .status-dot {
background: var(--danger);
box-shadow: 0 0 0 5px rgba(201, 77, 72, 0.14);
animation: pulse 700ms infinite alternate;
}
@keyframes pulse {
to {
transform: scale(1.25);
}
}
#statusTitle {
font-size: 11px;
font-weight: 850;
letter-spacing: 0.1em;
text-transform: uppercase;
}
#statusDetail {
margin: 7px 0 0 21px;
color: var(--muted);
font-size: 11px;
line-height: 1.35;
}
.objective {
position: fixed;
left: 50%;
bottom: 118px;
width: min(430px, calc(100vw - 32px));
padding: 13px 16px;
border-radius: 16px;
transform: translateX(-50%);
pointer-events: none;
}
.objective-top {
display: flex;
justify-content: space-between;
gap: 16px;
align-items: center;
font-size: 11px;
font-weight: 750;
}
#progressText {
color: var(--muted);
font-variant-numeric: tabular-nums;
}
.progress-track {
height: 6px;
margin-top: 9px;
overflow: hidden;
border-radius: 99px;
background: rgba(24, 50, 59, 0.09);
}
#progressFill {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--teal), #6bcf9d);
transition: width 90ms linear;
}
.controls {
position: fixed;
left: 50%;
bottom: 22px;
display: flex;
align-items: stretch;
gap: 8px;
padding: 8px;
border-radius: 20px;
transform: translateX(-50%);
}
.control-button {
min-width: 88px;
min-height: 66px;
padding: 9px 12px;
border: 1px solid var(--line);
border-radius: 14px;
background: rgba(255, 255, 255, 0.63);
color: var(--ink);
cursor: pointer;
user-select: none;
-webkit-user-select: none;
-webkit-tap-highlight-color: transparent;
transition:
transform 120ms ease,
background 160ms ease,
border-color 160ms ease,
color 160ms ease;
}
.control-button:hover {
transform: translateY(-2px);
border-color: rgba(24, 50, 59, 0.22);
}
.control-button:active,
.control-button.held {
transform: translateY(1px) scale(0.98);
}
.control-button.support {
display: flex;
align-items: center;
gap: 10px;
min-width: 184px;
text-align: left;
}
.control-button.support.released {
color: var(--danger);
background: rgba(201, 77, 72, 0.08);
border-color: rgba(201, 77, 72, 0.24);
}
.keycap {
display: grid;
width: 32px;
height: 32px;
flex: 0 0 auto;
place-items: center;
border: 1px solid rgba(24, 50, 59, 0.16);
border-bottom-width: 3px;
border-radius: 9px;
background: rgba(255, 255, 255, 0.78);
color: var(--ink);
font-size: 12px;
font-weight: 850;
}
.support-copy {
display: flex;
flex-direction: column;
gap: 3px;
}
.support-copy strong {
font-size: 10px;
letter-spacing: 0.075em;
text-transform: uppercase;
}
.support-copy small {
color: var(--muted);
font-size: 10px;
}
.support.released .support-copy small {
color: var(--danger);
}
.lamp {
width: 9px;
height: 9px;
margin-left: auto;
flex: 0 0 auto;
border-radius: 50%;
background: var(--teal);
box-shadow: 0 0 0 4px rgba(36, 169, 149, 0.11);
}
.support.released .lamp {
background: var(--danger);
box-shadow: 0 0 0 4px rgba(201, 77, 72, 0.11);
}
.move-button {
min-width: 58px;
font-size: 23px;
font-weight: 500;
}
.move-button.held {
color: white;
background: var(--teal);
border-color: var(--teal);
}
.reset-button {
width: 48px;
padding: 0;
font-size: 20px;
}
.camera-hint {
position: fixed;
right: 24px;
bottom: 23px;
padding: 8px 11px;
border-radius: 10px;
color: rgba(24, 50, 59, 0.58);
background: rgba(250, 249, 242, 0.55);
font-size: 10px;
font-weight: 700;
pointer-events: none;
}
#toast {
position: fixed;
top: 26px;
left: 50%;
max-width: min(470px, calc(100vw - 40px));
padding: 10px 15px;
border-radius: 99px;
color: white;
background: rgba(24, 50, 59, 0.88);
box-shadow: 0 10px 30px rgba(24, 50, 59, 0.18);
font-size: 11px;
font-weight: 750;
text-align: center;
opacity: 0;
transform: translate(-50%, -12px);
transition: 180ms ease;
pointer-events: none;
}
#toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
.overlay {
position: fixed;
inset: 0;
z-index: 10;
display: grid;
place-items: center;
padding: 24px;
background: rgba(22, 43, 48, 0.26);
backdrop-filter: blur(5px);
-webkit-backdrop-filter: blur(5px);
opacity: 1;
transition: opacity 220ms ease;
}
.overlay.hidden {
opacity: 0;
pointer-events: none;
}
.result-card {
width: min(390px, 100%);
padding: 30px;
border-radius: 26px;
background: #faf9f2;
box-shadow: 0 25px 80px rgba(16, 38, 43, 0.28);
text-align: center;
}
.result-icon {
display: grid;
width: 62px;
height: 62px;
margin: 0 auto 16px;
place-items: center;
border-radius: 20px;
color: var(--teal-dark);
background: rgba(36, 169, 149, 0.12);
font-size: 28px;
}
.result-card h2 {
margin: 0;
font-size: 29px;
letter-spacing: -0.04em;
}
.result-card p {
margin: 12px 0 22px;
color: var(--muted);
font-size: 13px;
line-height: 1.55;
}
.result-card button {
width: 100%;
padding: 13px 18px;
border: 0;
border-radius: 13px;
color: white;
background: var(--teal-dark);
font-weight: 800;
cursor: pointer;
}
.result-card button:hover {
background: #0e6657;
}
@media (max-width: 760px) {
.brief {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 15px 17px;
border-radius: 18px;
}
.brief p {
display: none;
}
.rule {
margin-top: 12px;
padding: 8px 10px;
font-size: 9px;
}
.status-card {
top: 142px;
right: 12px;
width: 215px;
padding: 11px 13px;
}
.objective {
bottom: 104px;
}
.controls {
bottom: 12px;
width: calc(100vw - 24px);
gap: 5px;
padding: 6px;
border-radius: 17px;
}
.control-button {
min-width: 43px;
min-height: 58px;
padding: 7px;
}
.control-button.support {
min-width: 0;
flex: 1;
gap: 7px;
}
.support-copy strong {
font-size: 8px;
}
.support-copy small {
display: none;
}
.keycap {
width: 28px;
height: 28px;
}
.lamp {
display: none;
}
.move-button {
min-width: 43px;
font-size: 20px;
}
.reset-button {
width: 40px;
min-width: 40px;
}
.camera-hint {
display: none;
}
}
@media (max-height: 600px) {
.brief p,
.rule {
display: none;
}
.status-card {
top: 12px;
}
.objective {
bottom: 94px;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive low-poly bridge balancing puzzle"></canvas>
<div class="vignette"></div>
<section class="brief panel">
<div class="eyebrow">A shared-load puzzle</div>
<h1>Bridgekeepers</h1>
<p>
Two keepers, one lantern-cart. Each keeper must hold a separate support
while both turn their winches and haul the shared load across the ravine.
</p>
<div class="rule">
<span></span>
Left grip + right grip = level crossing tile
</div>
</section>
<section id="statusCard" class="status-card panel" data-state="level" aria-live="polite">
<div class="status-row">
<div class="status-dot"></div>
<div id="statusTitle">Both supports locked</div>
</div>
<div id="statusDetail">The tile is level. Haul the load to the beacon.</div>
</section>
<section class="objective panel">
<div class="objective-top">
<span>Deliver the shared load</span>
<span id="progressText">0%</span>
</div>
<div class="progress-track">
<div id="progressFill"></div>
</div>
</section>
<nav class="controls panel" aria-label="Puzzle controls">
<button id="leftSupport" class="control-button support" type="button">
<span class="keycap">A</span>
<span class="support-copy">
<strong>Left support</strong>
<small>Release grip</small>
</span>
<span class="lamp"></span>
</button>
<button id="moveLeft" class="control-button move-button" type="button" aria-label="Haul load left">
◀
</button>
<button id="moveRight" class="control-button move-button" type="button" aria-label="Haul load right">
▶
</button>
<button id="rightSupport" class="control-button support" type="button">
<span class="keycap">D</span>
<span class="support-copy">
<strong>Right support</strong>
<small>Release grip</small>
</span>
<span class="lamp"></span>
</button>
<button id="reset" class="control-button reset-button" type="button" aria-label="Reset puzzle">
↺
</button>
</nav>
<div class="camera-hint">Drag to orbit · scroll to zoom</div>
<div id="toast" role="status"></div>
<div id="overlay" class="overlay hidden">
<div class="result-card">
<div id="resultIcon" class="result-icon">✦</div>
<h2 id="resultTitle">Load delivered</h2>
<p id="resultText">
Both keepers kept the crossing tile level and brought the shared load safely home.
</p>
<button id="resultAction" type="button">Play again</button>
</div>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const canvas = document.querySelector("#scene");
const statusCard = document.querySelector("#statusCard");
const statusTitle = document.querySelector("#statusTitle");
const statusDetail = document.querySelector("#statusDetail");
const progressFill = document.querySelector("#progressFill");
const progressText = document.querySelector("#progressText");
const leftSupportButton = document.querySelector("#leftSupport");
const rightSupportButton = document.querySelector("#rightSupport");
const moveLeftButton = document.querySelector("#moveLeft");
const moveRightButton = document.querySelector("#moveRight");
const resetButton = document.querySelector("#reset");
const toast = document.querySelector("#toast");
const overlay = document.querySelector("#overlay");
const resultIcon = document.querySelector("#resultIcon");
const resultTitle = document.querySelector("#resultTitle");
const resultText = document.querySelector("#resultText");
const resultAction = document.querySelector("#resultAction");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xdce8e2);
scene.fog = new THREE.Fog(0xdce8e2, 19, 36);
const camera = new THREE.PerspectiveCamera(42, innerWidth / innerHeight, 0.1, 100);
const renderer = new THREE.WebGLRenderer({
canvas,
antialias: true,
alpha: false
});
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
renderer.setSize(innerWidth, innerHeight);
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.05;
const cameraState = {
theta: 0.43,
phi: 1.02,
radius: 15.7,
target: new THREE.Vector3(0, 0.2, 0)
};
function updateCamera() {
const { theta, phi, radius, target } = cameraState;
camera.position.set(
target.x + radius * Math.sin(phi) * Math.sin(theta),
target.y + radius * Math.cos(phi),
target.z + radius * Math.sin(phi) * Math.cos(theta)
);
camera.lookAt(target);
}
updateCamera();
const hemi = new THREE.HemisphereLight(0xfff3d8, 0x385666, 2.25);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xffe7b8, 3.25);
sun.position.set(-7, 12, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -12;
sun.shadow.camera.right = 12;
sun.shadow.camera.top = 12;
sun.shadow.camera.bottom = -12;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 35;
sun.shadow.bias = -0.0008;
scene.add(sun);
const fillLight = new THREE.DirectionalLight(0x8ddbd1, 0.7);
fillLight.position.set(8, 5, -7);
scene.add(fillLight);
const state = {
leftSupport: true,
rightSupport: true,
moveDirection: 0,
cargoX: -3.75,
cargoGoalX: -3.75,
cargoY: 0.72,
game: "playing",
fallVelocity: 0,
winchAngle: 0
};
const constants = {
halfBridge: 3.15,
bridgeY: 0.59,
islandY: 0.58,
startX: -3.75,
goalX: 3.95,
wheelRadius: 0.13
};
const standard = (color, options = {}) =>
new THREE.MeshStandardMaterial({
color,
roughness: 0.82,
metalness: 0.02,
flatShading: true,
...options
});
const materials = {
woodA: standard(0xc98b53),
woodB: standard(0xe0aa6a),
woodEdge: standard(0x8a5638),
cream: standard(0xf4e4bd),
teal: standard(0x35b9a4),
tealDark: standard(0x176d64),
coral: standard(0xef745e),
coralDark: standard(0xa8473c),
navy: standard(0x203d49),
gold: standard(0xe5ad42),
grass: standard(0x8eb47e),
grassDark: standard(0x567d63),
rock: standard(0x766d69),
rockLight: standard(0x9c8a78),
rope: standard(0x3d4a46),
white: standard(0xf8f1dd)
};
function addMesh(parent, geometry, material, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(geometry, material);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function makeTree(parent, x, z, scale = 1) {
const group = new THREE.Group();
group.position.set(x, constants.islandY, z);
group.scale.setScalar(scale);
addMesh(
group,
new THREE.CylinderGeometry(0.07, 0.1, 0.75, 5),
materials.woodEdge,
0,
0.37,
0
);
addMesh(
group,
new THREE.IcosahedronGeometry(0.47, 0),
materials.grassDark,
0,
0.95,
0
);
addMesh(
group,
new THREE.IcosahedronGeometry(0.33, 0),
materials.grass,
-0.13,
1.2,
0.08
);
parent.add(group);
}
function makeIsland(x, accentMaterial) {
const island = new THREE.Group();
island.position.x = x;
addMesh(
island,
new THREE.CylinderGeometry(2.78, 2.62, 0.52, 7),
materials.rockLight,
0,
0.31,
0
);
addMesh(
island,
new THREE.CylinderGeometry(2.73, 1.2, 3.8, 7),
materials.rock,
0,
-1.66,
0
);
addMesh(
island,
new THREE.CylinderGeometry(2.76, 2.76, 0.09, 7),
materials.grass,
0,
0.575,
0
);
const pebbleMaterial = accentMaterial;
const pebbleData = [
[-1.4, 1.0, 0.22],
[1.6, -0.7, 0.17],
[0.5, 1.7, 0.14],
[-1.9, -1.2, 0.2]
];
for (const [px, pz, scale] of pebbleData) {
const pebble = addMesh(
island,
new THREE.DodecahedronGeometry(scale, 0),
pebbleMaterial,
px,
0.7,
pz
);
pebble.rotation.set(0.3, px, 0.2);
}
makeTree(island, -1.5, -1.05, 0.95);
makeTree(island, 1.6, 1.05, 0.72);
scene.add(island);
return island;
}
const floor = addMesh(
scene,
new THREE.PlaneGeometry(44, 44),
standard(0x193744),
0,
-4.3,
0
);
floor.rotation.x = -Math.PI / 2;
floor.castShadow = false;
const leftIsland = makeIsland(-5.1, materials.rockLight);
const rightIsland = makeIsland(5.1, materials.rock);
// Low-poly ravine crystals.
const crystalMaterial = standard(0x59c9bd, {
emissive: 0x174d52,
emissiveIntensity: 0.65
});
const crystalData = [
[-1.7, -3.4, -0.7, 0.5],
[0.3, -3.8, 0.8, 0.38],
[1.8, -3.35, -0.1, 0.62],
[-0.5, -3.95, -1.1, 0.28]
];
for (const [x, y, z, scale] of crystalData) {
const crystal = addMesh(
scene,
new THREE.ConeGeometry(scale, scale * 2.8, 5),
crystalMaterial,
x,
y,
z
);
crystal.rotation.z = (x + z) * 0.12;
}
// The crossing tile is a pivot group. Its content is counter-positioned so
// that a released side falls around the still-held support.
const bridge = new THREE.Group();
bridge.position.y = constants.bridgeY;
scene.add(bridge);
const bridgeContent = new THREE.Group();
bridge.add(bridgeContent);
const plankCount = 15;
const plankWidth = 0.39;
const plankGap = 0.025;
const totalPlankLength = plankCount * plankWidth + (plankCount - 1) * plankGap;
for (let i = 0; i < plankCount; i++) {
const x = -totalPlankLength / 2 + plankWidth / 2 + i * (plankWidth + plankGap);
const plank = addMesh(
bridgeContent,
new THREE.BoxGeometry(plankWidth, 0.18, 1.55),
i % 2 ? materials.woodA : materials.woodB,
x,
0,
0
);
plank.rotation.y = (i % 3 - 1) * 0.006;
}
for (const z of [-0.82, 0.82]) {
addMesh(
bridgeContent,
new THREE.BoxGeometry(6.38, 0.14, 0.13),
materials.woodEdge,
0,
-0.025,
z
);
}
for (const x of [-2.25, -0.75, 0.75, 2.25]) {
addMesh(
bridgeContent,
new THREE.BoxGeometry(0.16, 0.24, 1.66),
materials.woodEdge,
x,
-0.12,
0
);
}
for (const x of [-2.9, 0, 2.9]) {
const marker = addMesh(
bridgeContent,
new THREE.BoxGeometry(0.22, 0.025, 0.52),
materials.cream,
x,
0.102,
0
);
marker.castShadow = false;
}
const supportBrackets = {};
for (const side of ["left", "right"]) {
const sign = side === "left" ? -1 : 1;
const material = standard(
side === "left" ? 0xee725d : 0x35b9a4,
{ emissive: side === "left" ? 0x5c1711 : 0x0d554b, emissiveIntensity: 0.18 }
);
const bracket = addMesh(
bridgeContent,
new THREE.CylinderGeometry(0.19, 0.19, 0.18, 8),
material,
sign * constants.halfBridge,
-0.04,
0.68
);
bracket.rotation.x = Math.PI / 2;
supportBrackets[side] = { mesh: bracket, material };
}
// Winch and character construction.
const unitUp = new THREE.Vector3(0, 1, 0);
function makeSegment(radius, material) {
const mesh = addMesh(
scene,
new THREE.CylinderGeometry(radius, radius, 1, 6),
material
);
mesh.castShadow = false;
return mesh;
}
function setSegment(mesh, a, b) {
const direction = new THREE.Vector3().subVectors(b, a);
const length = direction.length();
if (length < 0.0001) {
mesh.visible = false;
return;
}
mesh.visible = true;
mesh.position.copy(a).add(b).multiplyScalar(0.5);
mesh.scale.set(1, length, 1);
mesh.quaternion.setFromUnitVectors(unitUp, direction.normalize());
}
function makeLabel(text, color) {
const labelCanvas = document.createElement("canvas");
labelCanvas.width = 128;
labelCanvas.height = 128;
const context = labelCanvas.getContext("2d");
context.clearRect(0, 0, 128, 128);
context.fillStyle = color;
context.beginPath();
context.arc(64, 64, 52, 0, Math.PI * 2);
context.fill();
context.strokeStyle = "rgba(255,255,255,.8)";
context.lineWidth = 7;
context.stroke();
context.fillStyle = "#ffffff";
context.font = "800 68px system-ui, sans-serif";
context.textAlign = "center";
context.textBaseline = "middle";
context.fillText(text, 64, 67);
const texture = new THREE.CanvasTexture(labelCanvas);
texture.colorSpace = THREE.SRGBColorSpace;
const sprite = new THREE.Sprite(
new THREE.SpriteMaterial({
map: texture,
transparent: true,
depthTest: false
})
);
sprite.scale.set(0.55, 0.55, 0.55);
return sprite;
}
const characters = {};
const supportRods = {};
for (const side of ["left", "right"]) {
const sign = side === "left" ? -1 : 1;
const bodyMaterial = side === "left" ? materials.coral : materials.teal;
const darkMaterial = side === "left" ? materials.coralDark : materials.tealDark;
const root = new THREE.Group();
root.position.set(sign * 3.85, constants.islandY, 1.03);
root.userData.support = side;
scene.add(root);
const legLeft = addMesh(
root,
new THREE.BoxGeometry(0.14, 0.29, 0.17),
darkMaterial,
-0.13,
0.145,
0
);
const legRight = addMesh(
root,
new THREE.BoxGeometry(0.14, 0.29, 0.17),
darkMaterial,
0.13,
0.145,
0
);
addMesh(
root,
new THREE.CylinderGeometry(0.22, 0.3, 0.52, 6),
bodyMaterial,
0,
0.55,
0
);
addMesh(
root,
new THREE.DodecahedronGeometry(0.235, 0),
materials.white,
0,
1.03,
0
);
addMesh(
root,
new THREE.ConeGeometry(0.28, 0.22, 6),
darkMaterial,
0,
1.22,
0
);
addMesh(
root,
new THREE.BoxGeometry(0.43, 0.09, 0.39),
materials.gold,
0,
0.76,
0
);
// Inward-facing arm and grip.
const arm = addMesh(
root,
new THREE.BoxGeometry(0.43, 0.12, 0.13),
bodyMaterial,
-sign * 0.25,
0.81,
0.02
);
arm.rotation.z = sign * -0.18;
const handAnchor = new THREE.Object3D();
handAnchor.position.set(-sign * 0.44, 1.0, 0.04);
root.add(handAnchor);
const hand = addMesh(
root,
new THREE.DodecahedronGeometry(0.1, 0),
materials.white,
-sign * 0.44,
1.0,
0.04
);
const gripMaterial = standard(side === "left" ? 0xee725d : 0x35b9a4, {
emissive: side === "left" ? 0x5c1711 : 0x0d554b,
emissiveIntensity: 0.25
});
const gripRing = addMesh(
root,
new THREE.TorusGeometry(0.13, 0.025, 5, 12),
gripMaterial,
-sign * 0.44,
1.0,
0.04
);
gripRing.rotation.y = Math.PI / 2;
// Small windlass.
const wheel = new THREE.Group();
wheel.position.set(-sign * 0.53, 0.83, 0.14);
root.add(wheel);
addMesh(
wheel,
new THREE.TorusGeometry(0.24, 0.038, 6, 14),
materials.gold
);
for (let i = 0; i < 3; i++) {
const spoke = addMesh(
wheel,
new THREE.BoxGeometry(0.43, 0.035, 0.035),
materials.cream
);
spoke.rotation.z = (i * Math.PI) / 3;
}
const crank = addMesh(
wheel,
new THREE.BoxGeometry(0.08, 0.17, 0.08),
darkMaterial,
0.19,
0.03,
0.05
);
const winchAnchor = new THREE.Object3D();
winchAnchor.position.set(-sign * 0.53, 0.83, 0.08);
root.add(winchAnchor);
const label = makeLabel(side === "left" ? "A" : "D", side === "left" ? "#e76855" : "#249d8d");
label.position.set(0, 1.72, 0);
root.add(label);
root.traverse((child) => {
if (child.isMesh) child.userData.support = side;
});
characters[side] = {
root,
legLeft,
legRight,
hand,
gripRing,
gripMaterial,
wheel,
crank,
handAnchor,
winchAnchor,
baseY: constants.islandY
};
supportRods[side] = makeSegment(
0.047,
standard(side === "left" ? 0xe76855 : 0x249d8d)
);
}
// Shared load: a four-wheel lantern cart.
const cart = new THREE.Group();
scene.add(cart);
addMesh(
cart,
new THREE.BoxGeometry(0.94, 0.16, 0.76),
materials.woodEdge,
0,
0.14,
0
);
addMesh(
cart,
new THREE.BoxGeometry(0.61, 0.53, 0.56),
materials.woodB,
0,
0.49,
0
);
for (const x of [-0.2, 0.2]) {
addMesh(
cart,
new THREE.BoxGeometry(0.055, 0.58, 0.59),
materials.navy,
x,
0.49,
0
);
}
const lanternMaterial = standard(0xffc85c, {
emissive: 0xff9d26,
emissiveIntensity: 1.4
});
addMesh(
cart,
new THREE.OctahedronGeometry(0.16, 0),
lanternMaterial,
0,
0.96,
0
);
const lanternLight = new THREE.PointLight(0xffbd58, 1.35, 3.3);
lanternLight.position.set(0, 1.02, 0);
cart.add(lanternLight);
const wheelPivots = [];
for (const x of [-0.32, 0.32]) {
for (const z of [-0.42, 0.42]) {
const pivot = new THREE.Group();
pivot.position.set(x, 0, z);
cart.add(pivot);
const wheel = addMesh(
pivot,
new THREE.CylinderGeometry(0.13, 0.13, 0.1, 8),
materials.navy
);
wheel.rotation.x = Math.PI / 2;
wheelPivots.push(pivot);
}
}
const ropeLeft = makeSegment(0.022, standard(0xc95c4d));
const ropeRight = makeSegment(0.022, standard(0x238f81));
const ropeAttachLeft = new THREE.Object3D();
ropeAttachLeft.position.set(-0.31, 0.38, -0.13);
cart.add(ropeAttachLeft);
const ropeAttachRight = new THREE.Object3D();
ropeAttachRight.position.set(0.31, 0.38, 0.13);
cart.add(ropeAttachRight);
// Destination beacon.
const beacon = new THREE.Group();
beacon.position.set(4.12, constants.islandY, -0.25);
scene.add(beacon);
addMesh(
beacon,
new THREE.CylinderGeometry(0.06, 0.08, 1.35, 6),
materials.cream,
0,
0.67,
0
);
const beaconCrystalMaterial = standard(0xf6b94f, {
emissive: 0xd67a13,
emissiveIntensity: 1.0
});
const beaconCrystal = addMesh(
beacon,
new THREE.OctahedronGeometry(0.24, 0),
beaconCrystalMaterial,
0,
1.56,
0
);
const beaconRing = addMesh(
beacon,
new THREE.TorusGeometry(0.47, 0.04, 5, 18),
materials.gold,
0,
0.035,
0
);
beaconRing.rotation.x = Math.PI / 2;
// Small decorative clouds.
const cloudMaterial = standard(0xf6f4e8, { roughness: 1 });
const clouds = [];
for (const data of [
[-8, 6.5, -9],
[7, 7.3, -11],
[1, 8.2, -14]
]) {
const cloud = new THREE.Group();
cloud.position.set(...data);
for (const [x, y, z, s] of [
[-0.7, 0, 0, 0.8],
[0, 0.18, 0, 1.05],
[0.75, 0, 0.05, 0.72]
]) {
addMesh(
cloud,
new THREE.IcosahedronGeometry(s, 0),
cloudMaterial,
x,
y,
z
);
}
scene.add(cloud);
clouds.push(cloud);
}
// Physical target values for the bridge.
const bridgeTarget = {
pivotX: 0,
angle: 0,
y: constants.bridgeY
};
function updateBridgeTarget() {
if (state.leftSupport && state.rightSupport) {
bridgeTarget.pivotX = 0;
bridgeTarget.angle = 0;
bridgeTarget.y = constants.bridgeY;
} else if (state.rightSupport) {
bridgeTarget.pivotX = constants.halfBridge;
bridgeTarget.angle = 0.19;
bridgeTarget.y = constants.bridgeY;
} else if (state.leftSupport) {
bridgeTarget.pivotX = -constants.halfBridge;
bridgeTarget.angle = -0.19;
bridgeTarget.y = constants.bridgeY;
} else {
bridgeTarget.pivotX = 0;
bridgeTarget.angle = -0.55;
bridgeTarget.y = -0.55;
}
}
function announce(message) {
toast.textContent = message;
toast.classList.add("show");
clearTimeout(announce.timeout);
announce.timeout = setTimeout(() => toast.classList.remove("show"), 1900);
}
function syncSupportUI() {
leftSupportButton.classList.toggle("released", !state.leftSupport);
rightSupportButton.classList.toggle("released", !state.rightSupport);
leftSupportButton.querySelector("small").textContent = state.leftSupport
? "Release grip"
: "Re-grip support";
rightSupportButton.querySelector("small").textContent = state.rightSupport
? "Release grip"
: "Re-grip support";
characters.left.gripMaterial.color.setHex(state.leftSupport ? 0xee725d : 0xc94d48);
characters.right.gripMaterial.color.setHex(state.rightSupport ? 0x35b9a4 : 0xc94d48);
characters.left.gripMaterial.emissive.setHex(state.leftSupport ? 0x5c1711 : 0x641d1a);
characters.right.gripMaterial.emissive.setHex(state.rightSupport ? 0x0d554b : 0x641d1a);
supportBrackets.left.material.color.setHex(state.leftSupport ? 0xee725d : 0xc94d48);
supportBrackets.right.material.color.setHex(state.rightSupport ? 0x35b9a4 : 0xc94d48);
}
function toggleSupport(side) {
if (state.game !== "playing") return;
if (side === "left") {
state.leftSupport = !state.leftSupport;
} else {
state.rightSupport = !state.rightSupport;
}
if (state.leftSupport && state.rightSupport) {
state.cargoGoalX = state.cargoX;
state.fallVelocity = 0;
}
updateBridgeTarget();
syncSupportUI();
if (!state.leftSupport && !state.rightSupport) {
announce("Both supports released — the crossing tile is falling.");
} else if (!state.leftSupport) {
announce("Left grip released — the tile tips toward the left.");
} else if (!state.rightSupport) {
announce("Right grip released — the tile tips toward the right.");
} else {
announce("Both grips locked again. The tile can return to level.");
}
}
function setMoveDirection(direction, active) {
if (active) {
state.moveDirection = direction;
} else if (state.moveDirection === direction) {
state.moveDirection = 0;
}
moveLeftButton.classList.toggle("held", state.moveDirection === -1);
moveRightButton.classList.toggle("held", state.moveDirection === 1);
}
function resetGame() {
state.leftSupport = true;
state.rightSupport = true;
state.moveDirection = 0;
state.cargoX = constants.startX;
state.cargoGoalX = constants.startX;
state.game = "playing";
state.fallVelocity = 0;
state.winchAngle = 0;
bridge.position.set(0, constants.bridgeY, 0);
bridge.rotation.z = 0;
bridgeContent.position.x = 0;
cart.position.set(state.cargoX, constants.islandY + constants.wheelRadius, 0);
cart.rotation.z = 0;
updateBridgeTarget();
syncSupportUI();
moveLeftButton.classList.remove("held");
moveRightButton.classList.remove("held");
overlay.classList.add("hidden");
for (const item of confetti) {
scene.remove(item.mesh);
item.mesh.geometry.dispose();
item.mesh.material.dispose();
}
confetti.length = 0;
announce("Puzzle reset. Both keepers have their supports.");
}
const confetti = [];
function celebrate() {
const palette = [0x35b9a4, 0xee725d, 0xe5ad42, 0xf8f1dd];
for (let i = 0; i < 28; i++) {
const material = standard(palette[i % palette.length]);
const mesh = addMesh(
scene,
new THREE.OctahedronGeometry(0.065 + Math.random() * 0.045, 0),
material,
constants.goalX + (Math.random() - 0.5) * 0.6,
1.7 + Math.random() * 0.8,
(Math.random() - 0.5) * 0.6
);
confetti.push({
mesh,
velocity: new THREE.Vector3(
(Math.random() - 0.5) * 2.3,
1.6 + Math.random() * 2.5,
(Math.random() - 0.5) * 2.3
),
spin: new THREE.Vector3(
Math.random() * 5,
Math.random() * 5,
Math.random() * 5
),
life: 3.2
});
}
}
function showResult(won) {
state.game = won ? "won" : "failed";
overlay.classList.remove("hidden");
if (won) {
resultIcon.textContent = "✦";
resultTitle.textContent = "Load delivered";
resultText.textContent =
"Both keepers kept the crossing tile level and brought the shared load safely home.";
resultAction.textContent = "Play again";
celebrate();
} else {
resultIcon.textContent = "×";
resultTitle.textContent = "The load was lost";
resultText.textContent =
"With both supports released, the crossing tile has nothing holding it up. Reset and try again.";
resultAction.textContent = "Reset puzzle";
}
}
function updateStatus() {
const nearlyLevel = Math.abs(bridge.rotation.z) < 0.025;
if (state.leftSupport && state.rightSupport) {
statusCard.dataset.state = nearlyLevel ? "level" : "warning";
statusTitle.textContent = nearlyLevel ? "Both supports locked" : "Restoring level";
statusDetail.textContent = nearlyLevel
? "The tile is level. Haul the load to the beacon."
: "The keepers are pulling the crossing tile back to level.";
} else if (!state.leftSupport && !state.rightSupport) {
statusCard.dataset.state = "danger";
statusTitle.textContent = "Both supports released";
statusDetail.textContent = "Nothing holds the crossing tile. Re-grip or reset.";
} else if (!state.leftSupport) {
statusCard.dataset.state = "warning";
statusTitle.textContent = "Left support released";
statusDetail.textContent = "The tile tips left and the load slides downhill.";
} else {
statusCard.dataset.state = "warning";
statusTitle.textContent = "Right support released";
statusDetail.textContent = "The tile tips right and the load slides downhill.";
}
const progress = THREE.MathUtils.clamp(
(state.cargoX - constants.startX) / (constants.goalX - constants.startX),
0,
1
);
progressFill.style.width = `${progress * 100}%`;
progressText.textContent = `${Math.round(progress * 100)}%`;
}
// UI and keyboard controls.
leftSupportButton.addEventListener("click", () => toggleSupport("left"));
rightSupportButton.addEventListener("click", () => toggleSupport("right"));
resetButton.addEventListener("click", resetGame);
resultAction.addEventListener("click", resetGame);
for (const [button, direction] of [
[moveLeftButton, -1],
[moveRightButton, 1]
]) {
button.addEventListener("pointerdown", (event) => {
event.preventDefault();
button.setPointerCapture(event.pointerId);
setMoveDirection(direction, true);
});
const release = () => setMoveDirection(direction, false);
button.addEventListener("pointerup", release);
button.addEventListener("pointercancel", release);
button.addEventListener("lostpointercapture", release);
}
window.addEventListener("keydown", (event) => {
if (event.code === "KeyA" && !event.repeat) toggleSupport("left");
if (event.code === "KeyD" && !event.repeat) toggleSupport("right");
if (event.code === "ArrowLeft") {
event.preventDefault();
setMoveDirection(-1, true);
}
if (event.code === "ArrowRight") {
event.preventDefault();
setMoveDirection(1, true);
}
if (event.code === "KeyR" && !event.repeat) resetGame();
});
window.addEventListener("keyup", (event) => {
if (event.code === "ArrowLeft") setMoveDirection(-1, false);
if (event.code === "ArrowRight") setMoveDirection(1, false);
});
window.addEventListener("blur", () => {
state.moveDirection = 0;
moveLeftButton.classList.remove("held");
moveRightButton.classList.remove("held");
});
// Direct camera controls and optional character clicking.
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerStart = null;
let dragged = false;
canvas.addEventListener("pointerdown", (event) => {
pointerStart = { x: event.clientX, y: event.clientY };
dragged = false;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (!pointerStart) return;
const dx = event.clientX - pointerStart.x;
const dy = event.clientY - pointerStart.y;
if (Math.abs(dx) + Math.abs(dy) > 4) dragged = true;
cameraState.theta -= dx * 0.005;
cameraState.phi = THREE.MathUtils.clamp(
cameraState.phi - dy * 0.004,
0.56,
1.36
);
pointerStart.x = event.clientX;
pointerStart.y = event.clientY;
updateCamera();
});
canvas.addEventListener("pointerup", (event) => {
if (!dragged) {
const rect = canvas.getBoundingClientRect();
pointer.x = ((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y = -((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(
[characters.left.root, characters.right.root],
true
);
if (hits.length) {
const side = hits[0].object.userData.support;
if (side) toggleSupport(side);
}
}
pointerStart = null;
dragged = false;
});
canvas.addEventListener("pointercancel", () => {
pointerStart = null;
dragged = false;
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraState.radius = THREE.MathUtils.clamp(
cameraState.radius + event.deltaY * 0.008,
10.5,
22
);
updateCamera();
},
{ passive: false }
);
window.addEventListener("resize", () => {
camera.aspect = innerWidth / innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(innerWidth, innerHeight);
renderer.setPixelRatio(Math.min(devicePixelRatio, 2));
});
function tileSurfaceAt(worldX) {
const angle = bridge.rotation.z;
const cosine = Math.cos(angle);
const sine = Math.sin(angle);
const localY = 0.09;
const localX =
bridge.position.x +
(worldX - bridge.position.x + localY * sine) / cosine;
const worldY =
bridge.position.y +
(localX - bridge.position.x) * sine +
localY * cosine;
return { localX, worldY };
}
function updateCharacters(dt, moving) {
for (const side of ["left", "right"]) {
const character = characters[side];
const sign = side === "left" ? -1 : 1;
const bob = moving ? Math.abs(Math.sin(state.winchAngle * 2)) * 0.035 : 0;
character.root.position.y = character.baseY + bob;
character.legLeft.rotation.x = moving ? Math.sin(state.winchAngle * 2) * 0.22 : 0;
character.legRight.rotation.x = moving ? -Math.sin(state.winchAngle * 2) * 0.22 : 0;
character.wheel.rotation.z = state.winchAngle;
character.crank.position.y = 0.03 + Math.sin(state.winchAngle) * 0.08;
character.hand.scale.setScalar(
state[side === "left" ? "leftSupport" : "rightSupport"] ? 1 : 0.82
);
const handPosition = new THREE.Vector3();
character.handAnchor.getWorldPosition(handPosition);
const endpoint = bridgeContent.localToWorld(
new THREE.Vector3(sign * constants.halfBridge, 0.08, 0.68)
);
setSegment(supportRods[side], handPosition, endpoint);
const supportActive = state[side === "left" ? "leftSupport" : "rightSupport"];
supportRods[side].visible = supportActive;
}
}
function updateConfetti(dt) {
for (let i = confetti.length - 1; i >= 0; i--) {
const item = confetti[i];
item.life -= dt;
item.velocity.y -= 3.2 * dt;
item.mesh.position.addScaledVector(item.velocity, dt);
item.mesh.rotation.x += item.spin.x * dt;
item.mesh.rotation.y += item.spin.y * dt;
item.mesh.rotation.z += item.spin.z * dt;
if (item.life <= 0 || item.mesh.position.y < -4) {
scene.remove(item.mesh);
item.mesh.geometry.dispose();
item.mesh.material.dispose();
confetti.splice(i, 1);
}
}
}
const clock = new THREE.Clock();
function animate() {
const dt = Math.min(clock.getDelta(), 0.05);
// Smooth the support pivot and its rotation.
const bridgeEase = 1 - Math.exp(-7 * dt);
bridge.position.x += (bridgeTarget.pivotX - bridge.position.x) * bridgeEase;
bridge.position.y += (bridgeTarget.y - bridge.position.y) * bridgeEase;
bridge.rotation.z += (bridgeTarget.angle - bridge.rotation.z) * bridgeEase;
// Keep the tile centered while changing the physical pivot point.
bridgeContent.position.x = -bridge.position.x;
bridge.updateMatrixWorld(true);
const balanced =
state.leftSupport &&
state.rightSupport &&
Math.abs(bridge.rotation.z) < 0.025;
let moving = false;
if (state.game === "playing") {
if (state.leftSupport && state.rightSupport) {
if (balanced && state.moveDirection !== 0) {
moving = true;
state.cargoGoalX += state.moveDirection * 2.25 * dt;
state.cargoGoalX = THREE.MathUtils.clamp(
state.cargoGoalX,
constants.startX,
constants.goalX
);
}
const cargoEase = 1 - Math.exp(-9 * dt);
state.cargoX += (state.cargoGoalX - state.cargoX) * cargoEase;
} else if (state.leftSupport || state.rightSupport) {
// A released side becomes downhill. The shared load slides that way.
const onTile = state.cargoX > -3.08 && state.cargoX < 3.08;
if (onTile) {
if (!state.leftSupport) {
state.cargoX -= dt * 0.82;
state.cargoX = Math.max(state.cargoX, -3.03);
} else {
state.cargoX += dt * 0.82;
state.cargoX = Math.min(state.cargoX, 3.03);
}
}
state.cargoGoalX = state.cargoX;
}
}
const onTile = Math.abs(state.cargoX) <= 3.08;
const surface = tileSurfaceAt(state.cargoX);
const surfaceY = onTile ? surface.worldY : constants.islandY;
cart.position.x = state.cargoX;
if (!state.leftSupport && !state.rightSupport) {
state.fallVelocity += 5.5 * dt;
cart.position.y = Math.min(
surfaceY + constants.wheelRadius,
cart.position.y - state.fallVelocity * dt
);
if (cart.position.y < -2.4 && state.game === "playing") {
showResult(false);
}
} else {
state.fallVelocity = 0;
cart.position.y = surfaceY + constants.wheelRadius;
}
cart.rotation.z = onTile ? bridge.rotation.z : 0;
if (moving) {
state.winchAngle += dt * state.moveDirection * 7.5;
}
for (const wheel of wheelPivots) {
wheel.rotation.z = -state.cargoX / constants.wheelRadius;
}
updateCharacters(dt, moving);
const leftAnchor = new THREE.Vector3();
const rightAnchor = new THREE.Vector3();
const leftRope = new THREE.Vector3();
const rightRope = new THREE.Vector3();
characters.left.winchAnchor.getWorldPosition(leftAnchor);
characters.right.winchAnchor.getWorldPosition(rightAnchor);
ropeAttachLeft.getWorldPosition(leftRope);
ropeAttachRight.getWorldPosition(rightRope);
setSegment(ropeLeft, leftAnchor, leftRope);
setSegment(ropeRight, rightAnchor, rightRope);
beaconCrystal.rotation.y += dt * 0.8;
beaconCrystal.position.y = 1.56 + Math.sin(clock.elapsedTime * 2.1) * 0.05;
for (let i = 0; i < clouds.length; i++) {
clouds[i].position.x += dt * (0.07 + i * 0.018);
if (clouds[i].position.x > 11) clouds[i].position.x = -11;
}
updateConfetti(dt);
updateStatus();
if (
state.game === "playing" &&
state.cargoX >= constants.goalX - 0.07 &&
state.leftSupport &&
state.rightSupport &&
balanced
) {
showResult(true);
}
renderer.render(scene, camera);
}
updateBridgeTarget();
syncSupportUI();
resetGame();
renderer.setAnimationLoop(animate);
</script>
</body>
</html>
```