Prompt specification
Build or customize the Three.js 3D scene "Temple Storage Sliding Courtyard" 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: Temple Storage Sliding Courtyard
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/temple-storage-sliding-courtyard-x3503
Scene Description Prompt:
Build a self-contained HTML scene with Three.js from cdnjs featuring sliding blocks, empty spaces, and move dependencies. Build an original fictional courtyard where stone crates slide on marked channels. Use a small authored solvable arrangement and show the exit becoming physically accessible. Voxel style.
Working Three.js Starter (temple-storage-sliding-courtyard-x3503):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Ashglass Courtyard — Voxel Courier Puzzle</title>
<style>
:root {
color-scheme: dark;
--ink: #101820;
--panel: rgba(16, 24, 32, 0.84);
--line: rgba(230, 214, 180, 0.18);
--gold: #e6bd72;
--teal: #72c8b4;
--muted: #aeb8b9;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: #151c24;
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
color: #f5edda;
}
canvas {
position: fixed;
inset: 0;
width: 100%;
height: 100%;
display: block;
touch-action: none;
cursor: grab;
}
canvas:active {
cursor: grabbing;
}
#vignette {
position: fixed;
inset: 0;
pointer-events: none;
background:
radial-gradient(circle at 50% 45%, transparent 42%, rgba(4, 8, 13, 0.36) 100%),
linear-gradient(to bottom, rgba(5, 9, 14, 0.16), transparent 28%);
z-index: 2;
}
#hud {
position: fixed;
inset: 0;
z-index: 3;
pointer-events: none;
}
.panel {
background: var(--panel);
border: 1px solid var(--line);
border-radius: 14px;
box-shadow:
0 16px 40px rgba(0, 0, 0, 0.28),
inset 0 1px rgba(255, 255, 255, 0.04);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
pointer-events: auto;
}
.brand {
position: absolute;
top: 22px;
left: 22px;
width: min(390px, calc(100vw - 44px));
padding: 19px 20px 17px;
}
.eyebrow {
color: var(--gold);
font-size: 10px;
font-weight: 800;
letter-spacing: 0.22em;
text-transform: uppercase;
}
h1 {
margin: 6px 0 4px;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(25px, 3vw, 34px);
font-weight: 600;
line-height: 1.05;
letter-spacing: -0.025em;
}
.subtitle {
margin: 8px 0 14px;
color: #c1c8c5;
font-size: 13px;
line-height: 1.45;
}
.route {
display: flex;
align-items: center;
gap: 9px;
padding-top: 12px;
border-top: 1px solid var(--line);
color: #d5b778;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 10px;
font-weight: 800;
letter-spacing: 0.11em;
}
.route-dot {
width: 8px;
height: 8px;
border-radius: 50%;
background: #b86b4f;
box-shadow: 0 0 12px rgba(219, 111, 75, 0.6);
}
.route.open {
color: var(--teal);
}
.route.open .route-dot {
background: var(--teal);
box-shadow: 0 0 14px rgba(114, 200, 180, 0.8);
}
.dependency {
display: flex;
align-items: center;
gap: 6px;
margin-top: 13px;
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
font-size: 9px;
letter-spacing: 0.08em;
}
.dependency span {
padding: 5px 7px;
border: 1px solid rgba(255, 255, 255, 0.11);
border-radius: 5px;
color: #778386;
transition: 180ms ease;
}
.dependency span.current {
color: #151d22;
border-color: var(--gold);
background: var(--gold);
}
.dependency span.done {
color: #9dd8c8;
border-color: rgba(114, 200, 180, 0.35);
background: rgba(114, 200, 180, 0.1);
}
.dependency i {
color: #5f6d71;
font-style: normal;
}
.controls {
position: absolute;
top: 22px;
right: 22px;
display: flex;
gap: 7px;
padding: 8px;
}
button {
appearance: none;
border: 1px solid rgba(255, 255, 255, 0.13);
border-radius: 8px;
padding: 10px 12px;
background: rgba(255, 255, 255, 0.055);
color: #e8e1cf;
font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
cursor: pointer;
transition: 150ms ease;
}
button:hover {
color: white;
border-color: rgba(230, 189, 114, 0.6);
background: rgba(230, 189, 114, 0.12);
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
button:disabled {
opacity: 0.42;
cursor: default;
transform: none;
}
#solveBtn {
color: #10201d;
border-color: #72c8b4;
background: #72c8b4;
}
#solveBtn:hover {
color: #071512;
background: #91ddcb;
}
.status {
position: absolute;
left: 22px;
bottom: 23px;
width: min(440px, calc(100vw - 44px));
padding: 14px 16px;
}
.status small {
color: var(--gold);
font-size: 9px;
font-weight: 800;
letter-spacing: 0.18em;
}
.status p {
margin: 6px 0 0;
color: #d4d9d4;
font-size: 12px;
line-height: 1.5;
}
.legend {
position: absolute;
right: 22px;
bottom: 25px;
max-width: 340px;
color: rgba(231, 230, 218, 0.7);
font: 500 10px/1.7 ui-monospace, SFMono-Regular, Menlo, monospace;
text-align: right;
text-shadow: 0 2px 8px #000;
}
@media (max-width: 720px) {
.brand {
top: 12px;
left: 12px;
width: calc(100vw - 24px);
padding: 14px;
}
.subtitle {
margin-bottom: 8px;
}
.controls {
top: auto;
right: 12px;
bottom: 12px;
flex-wrap: wrap;
justify-content: flex-end;
max-width: calc(100vw - 24px);
}
.status {
left: 12px;
bottom: 78px;
width: calc(100vw - 24px);
}
.legend {
display: none;
}
.dependency {
display: none;
}
}
</style>
</head>
<body>
<canvas id="scene" aria-label="Interactive voxel courtyard puzzle"></canvas>
<div id="vignette"></div>
<div id="hud">
<section class="brand panel">
<div class="eyebrow">Voxel Courier Puzzle</div>
<h1>Ashglass Courtyard</h1>
<p class="subtitle">
Slide the old seal-stones. Clear the eastern lane and wake the sunken wicket.
</p>
<div class="route" id="routeStatus">
<span class="route-dot"></span>
<span id="routeLabel">EAST ROUTE · SEALED</span>
</div>
<div class="dependency" aria-label="Move dependency chain">
<span id="depSlate">SLATE</span><i>→</i>
<span id="depTeal">TEAL</span><i>→</i>
<span id="depRust">RUST</span><i>→</i>
<span id="depGate">GATE</span>
</div>
</section>
<nav class="controls panel" aria-label="Puzzle controls">
<button id="hintBtn">Hint</button>
<button id="solveBtn">Play Solution</button>
<button id="resetBtn">Reset</button>
<button id="viewBtn">Reset View</button>
</nav>
<section class="status panel">
<small>Warden's Log</small>
<p id="statusText">
Select a seal-stone, then click an empty neighboring bay. The warden braces on the opposite side.
</p>
</section>
<div class="legend">
CLICK FLOOR · WALK SELECT STONE · SLIDE<br />
DRAG · ORBIT CAMERA WHEEL · ZOOM
</div>
</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// ---------------------------------------------------------------------
// Core scene
// ---------------------------------------------------------------------
const canvas = document.querySelector("#scene");
const statusText = document.querySelector("#statusText");
const routeStatus = document.querySelector("#routeStatus");
const routeLabel = document.querySelector("#routeLabel");
const solveButton = document.querySelector("#solveBtn");
const WIDTH = 6;
const HEIGHT = 5;
const CELL = 1.18;
const BOARD_WIDTH = WIDTH * CELL;
const BOARD_DEPTH = HEIGHT * CELL;
const BOARD_RIGHT = BOARD_WIDTH / 2;
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x17212a);
scene.fog = new THREE.Fog(0x17212a, 18, 38);
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.12;
const camera = new THREE.PerspectiveCamera(
39,
window.innerWidth / window.innerHeight,
0.1,
80
);
let cameraYaw = 0.69;
let cameraPitch = 0.72;
let cameraDistance = 14.8;
const cameraTarget = new THREE.Vector3(0.25, 0.2, 0);
function updateCamera() {
const horizontal = Math.cos(cameraPitch) * cameraDistance;
camera.position.set(
cameraTarget.x + Math.sin(cameraYaw) * horizontal,
cameraTarget.y + Math.sin(cameraPitch) * cameraDistance,
cameraTarget.z + Math.cos(cameraYaw) * horizontal
);
camera.lookAt(cameraTarget);
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xaec7d7, 0x403124, 1.65);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xffd8a0, 3.8);
sun.position.set(-7, 12, 8);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -11;
sun.shadow.camera.right = 11;
sun.shadow.camera.top = 11;
sun.shadow.camera.bottom = -11;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 32;
sun.shadow.bias = -0.00035;
scene.add(sun);
const coolFill = new THREE.DirectionalLight(0x76a9c8, 1.15);
coolFill.position.set(8, 6, -8);
scene.add(coolFill);
function standard(color, options = {}) {
return new THREE.MeshStandardMaterial({
color,
roughness: 0.84,
metalness: 0.02,
...options
});
}
const stoneDark = standard(0x30383a);
const stoneMid = standard(0x555a55);
const stoneLight = standard(0x777567);
const iron = standard(0x293136, { metalness: 0.5, roughness: 0.48 });
const gold = standard(0xc99c54, { metalness: 0.18, roughness: 0.55 });
const groundMaterial = standard(0x30383b);
function addBox(parent, sx, sy, sz, x, y, z, material) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(sx, sy, sz),
material
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function noise(seed) {
const value = Math.sin(seed * 91.733) * 43758.5453;
return value - Math.floor(value);
}
function cellPosition(c, r, y = 0) {
return new THREE.Vector3(
(c - (WIDTH - 1) / 2) * CELL,
y,
(r - (HEIGHT - 1) / 2) * CELL
);
}
// ---------------------------------------------------------------------
// Courtyard platform and marked channels
// ---------------------------------------------------------------------
addBox(
scene,
27,
0.32,
23,
0,
-0.59,
0,
groundMaterial
);
addBox(
scene,
BOARD_WIDTH + 0.55,
0.42,
BOARD_DEPTH + 0.55,
0,
-0.25,
0,
stoneDark
);
const tilePalette = [
standard(0x787669),
standard(0x706e62),
standard(0x817b6c),
standard(0x6d7068),
standard(0x777364)
];
const tileMaterials = [];
for (let r = 0; r < HEIGHT; r++) {
for (let c = 0; c < WIDTH; c++) {
const p = cellPosition(c, r);
const material = tilePalette[
Math.floor(noise(r * WIDTH + c + 1) * tilePalette.length)
];
tileMaterials.push(material);
addBox(
scene,
CELL - 0.075,
0.13,
CELL - 0.075,
p.x,
0.015,
p.z,
material
);
// Tiny inset corner pins make the board read as constructed stone.
const pinMaterial = standard(0x596364, {
metalness: 0.15,
roughness: 0.65
});
for (const sx of [-1, 1]) {
for (const sz of [-1, 1]) {
addBox(
scene,
0.075,
0.035,
0.075,
p.x + sx * (CELL * 0.5 - 0.15),
0.097,
p.z + sz * (CELL * 0.5 - 0.15),
pinMaterial
);
}
}
}
}
const channelMaterial = standard(0x34474a, {
roughness: 0.66,
metalness: 0.12
});
for (let r = 0; r < HEIGHT; r++) {
const p = cellPosition(0, r);
addBox(
scene,
BOARD_WIDTH - 0.18,
0.028,
0.035,
p.x,
0.097,
p.z,
channelMaterial
);
}
for (let c = 0; c < WIDTH; c++) {
const p = cellPosition(c, 0);
addBox(
scene,
0.035,
0.028,
BOARD_DEPTH - 0.18,
p.x,
0.099,
p.z,
channelMaterial
);
}
// Raised perimeter blocks.
for (let c = 0; c < WIDTH; c++) {
const p = cellPosition(c, 0);
addBox(
scene,
CELL - 0.05,
0.23,
0.24,
p.x,
0.02,
-BOARD_DEPTH / 2 - 0.19,
stoneMid
);
addBox(
scene,
CELL - 0.05,
0.23,
0.24,
p.x,
0.02,
BOARD_DEPTH / 2 + 0.19,
stoneMid
);
}
for (let r = 0; r < HEIGHT; r++) {
const p = cellPosition(0, r);
addBox(
scene,
0.24,
0.23,
CELL - 0.05,
-BOARD_WIDTH / 2 - 0.19,
0.02,
p.z,
stoneMid
);
addBox(
scene,
0.24,
0.23,
CELL - 0.05,
BOARD_RIGHT + 0.19,
0.02,
p.z,
stoneMid
);
}
// ---------------------------------------------------------------------
// Ruined walls, columns, banners and braziers
// ---------------------------------------------------------------------
const wallMaterials = [
standard(0x4e5350),
standard(0x57564d),
standard(0x454c4b),
standard(0x626056)
];
const northZ = -BOARD_DEPTH / 2 - 1.15;
for (let i = 0; i < 9; i++) {
const x = -BOARD_WIDTH / 2 - 0.5 + i * 0.87;
const levels = i === 0 || i === 8 ? 2 : 3;
for (let level = 0; level < levels; level++) {
addBox(
scene,
0.78,
0.53,
0.68,
x,
-0.05 + level * 0.54,
northZ + (noise(i * 7 + level) - 0.5) * 0.08,
wallMaterials[(i + level) % wallMaterials.length]
);
}
}
const westX = -BOARD_WIDTH / 2 - 1.12;
for (let i = 0; i < 6; i++) {
const z = -BOARD_DEPTH / 2 + i * 0.86;
const levels = i === 0 || i === 5 ? 2 : 1;
for (let level = 0; level < levels; level++) {
addBox(
scene,
0.65,
0.5,
0.77,
westX + (noise(i * 11 + level) - 0.5) * 0.07,
-0.07 + level * 0.51,
z,
wallMaterials[(i + level + 2) % wallMaterials.length]
);
}
}
function column(x, z, height = 2.65) {
addBox(scene, 0.8, 0.28, 0.8, x, -0.1, z, stoneDark);
addBox(scene, 0.62, 0.58, 0.62, x, 0.33, z, stoneLight);
addBox(scene, 0.55, height, 0.55, x, 0.62 + height / 2, z, stoneMid);
addBox(scene, 0.76, 0.28, 0.76, x, 0.75 + height, z, stoneLight);
}
column(-BOARD_WIDTH / 2 - 0.7, northZ + 0.05, 2.25);
column(BOARD_WIDTH / 2 + 0.25, northZ + 0.05, 2.45);
const bannerMaterial = standard(0x8c3f3b, {
roughness: 0.96,
side: THREE.DoubleSide
});
addBox(
scene,
0.68,
1.25,
0.12,
0.15,
1.15,
northZ + 0.4,
bannerMaterial
);
addBox(
scene,
0.12,
0.72,
0.14,
0.15,
1.2,
northZ + 0.48,
gold
);
const flames = [];
function brazier(x, z) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
addBox(group, 0.54, 0.18, 0.54, 0, 0.02, 0, stoneDark);
addBox(group, 0.38, 0.48, 0.38, 0, 0.32, 0, iron);
addBox(group, 0.62, 0.12, 0.62, 0, 0.58, 0, stoneMid);
const flameMaterial = new THREE.MeshBasicMaterial({
color: 0xffa34a,
transparent: true,
opacity: 0.94
});
const flame = new THREE.Mesh(
new THREE.BoxGeometry(0.22, 0.5, 0.22),
flameMaterial
);
flame.position.y = 0.92;
flame.rotation.z = 0.12;
group.add(flame);
flames.push(flame);
const light = new THREE.PointLight(0xff8c3d, 12, 5, 2);
light.position.set(0, 1.1, 0);
group.add(light);
}
brazier(-BOARD_WIDTH / 2 - 0.3, BOARD_DEPTH / 2 + 0.55);
brazier(BOARD_WIDTH / 2 + 0.9, BOARD_DEPTH / 2 + 0.65);
// ---------------------------------------------------------------------
// Eastern wicket and exit passage
// ---------------------------------------------------------------------
const gateX = BOARD_RIGHT + 0.66;
const exitRowZ = cellPosition(0, 2).z;
for (const zOffset of [-0.88, 0.88]) {
for (let level = 0; level < 4; level++) {
addBox(
scene,
0.48,
0.43,
0.47,
gateX,
0.14 + level * 0.44,
exitRowZ + zOffset,
level % 2 ? stoneMid : stoneLight
);
}
}
for (let i = -2; i <= 2; i++) {
addBox(
scene,
0.52,
0.3,
0.42,
gateX,
1.82,
exitRowZ + i * 0.4,
stoneLight
);
}
for (let i = -1; i <= 1; i++) {
addBox(
scene,
0.52,
0.28,
0.4,
gateX,
2.13,
exitRowZ + i * 0.4,
stoneMid
);
}
const gate = new THREE.Group();
gate.position.set(gateX, 0, exitRowZ);
scene.add(gate);
for (let i = -2; i <= 2; i++) {
addBox(
gate,
0.14,
1.42,
0.11,
0,
0.78,
i * 0.38,
iron
);
}
addBox(gate, 0.17, 0.13, 1.85, 0, 0.38, 0, iron);
addBox(gate, 0.17, 0.13, 1.85, 0, 1.16, 0, iron);
const gateRuneMaterial = new THREE.MeshStandardMaterial({
color: 0x5c5140,
emissive: 0x392613,
emissiveIntensity: 0.6,
roughness: 0.6
});
addBox(
gate,
0.2,
0.35,
0.35,
0,
0.77,
0,
gateRuneMaterial
);
const pathMaterial = standard(0x65706d, {
emissive: 0x182a28,
emissiveIntensity: 0.4,
roughness: 0.75
});
for (let i = 0; i < 4; i++) {
addBox(
scene,
0.72,
0.12,
1.32,
BOARD_RIGHT + 0.75 + i * 0.72,
0.01,
exitRowZ,
pathMaterial
);
}
const gateLight = new THREE.PointLight(0xffc477, 0.4, 8, 2);
gateLight.position.set(gateX + 0.8, 1.45, exitRowZ);
scene.add(gateLight);
let gateGlowTarget = 0.4;
// ---------------------------------------------------------------------
// Crates and the courier
// ---------------------------------------------------------------------
const crateDefinitions = [
{
id: "rust",
name: "Rust seal",
c: 1,
r: 2,
color: 0xa95339,
accent: 0xe3a85b
},
{
id: "teal",
name: "Teal stop",
c: 3,
r: 2,
color: 0x347e79,
accent: 0x7bd4bd
},
{
id: "slate",
name: "Slate sill",
c: 3,
r: 3,
color: 0x506681,
accent: 0x94b2cf
},
{
id: "ochre",
name: "Ochre ballast",
c: 4,
r: 4,
color: 0x9d793d,
accent: 0xe0bd70
}
];
const crates = new Map();
const crateGroups = [];
function createCrate(definition) {
const group = new THREE.Group();
const p = cellPosition(definition.c, definition.r, 0.085);
group.position.copy(p);
scene.add(group);
const bodyMaterial = standard(definition.color, {
emissive: 0x000000,
roughness: 0.9
});
const accentMaterial = standard(definition.accent, {
roughness: 0.65,
metalness: 0.12
});
const darkMaterial = standard(0x343536, {
roughness: 0.8
});
addBox(group, 0.82, 0.7, 0.82, 0, 0.39, 0, bodyMaterial);
addBox(group, 0.91, 0.12, 0.91, 0, 0.79, 0, accentMaterial);
for (const x of [-0.34, 0.34]) {
for (const z of [-0.34, 0.34]) {
addBox(
group,
0.18,
0.2,
0.18,
x,
0.13,
z,
darkMaterial
);
}
}
addBox(group, 0.13, 0.62, 0.055, 0, 0.42, 0.435, accentMaterial);
addBox(group, 0.055, 0.62, 0.13, 0, 0.42, 0.435, accentMaterial);
const rune = addBox(
group,
0.18,
0.12,
0.18,
0,
0.91,
0,
accentMaterial
);
rune.rotation.y = Math.PI / 4;
const edges = new THREE.LineSegments(
new THREE.EdgesGeometry(new THREE.BoxGeometry(0.83, 0.71, 0.83)),
new THREE.LineBasicMaterial({
color: 0x2c2926,
transparent: true,
opacity: 0.55
})
);
edges.position.y = 0.39;
group.add(edges);
group.traverse((child) => {
child.userData.crateId = definition.id;
});
const crate = {
...definition,
group,
bodyMaterial
};
crates.set(definition.id, crate);
crateGroups.push(group);
return crate;
}
for (const definition of crateDefinitions) {
createCrate(definition);
}
const playerRoot = new THREE.Group();
const playerRig = new THREE.Group();
playerRoot.add(playerRig);
scene.add(playerRoot);
const player = {
c: 0,
r: 1,
root: playerRoot
};
const coatMaterial = standard(0x315f68);
const scarfMaterial = standard(0xc76b45);
const skinMaterial = standard(0xd6aa78);
const bootMaterial = standard(0x293238);
const playerDark = standard(0x202b30);
const leftLeg = addBox(
playerRig,
0.17,
0.32,
0.19,
-0.12,
0.17,
0,
bootMaterial
);
const rightLeg = addBox(
playerRig,
0.17,
0.32,
0.19,
0.12,
0.17,
0,
bootMaterial
);
addBox(playerRig, 0.39, 0.43, 0.29, 0, 0.5, 0, coatMaterial);
addBox(playerRig, 0.44, 0.12, 0.34, 0, 0.66, 0, scarfMaterial);
addBox(playerRig, 0.3, 0.29, 0.28, 0, 0.86, 0, skinMaterial);
addBox(playerRig, 0.36, 0.15, 0.33, 0, 1.02, -0.01, playerDark);
addBox(playerRig, 0.08, 0.07, 0.06, 0, 0.86, 0.16, playerDark);
const lanternMaterial = new THREE.MeshBasicMaterial({
color: 0xffc777
});
addBox(
playerRig,
0.13,
0.18,
0.13,
0.3,
0.45,
0.04,
lanternMaterial
);
addBox(
playerRig,
0.04,
0.25,
0.04,
0.3,
0.56,
0.04,
iron
);
player.root.position.copy(cellPosition(player.c, player.r, 0.085));
// Selection pads: clicking one pushes the selected crate into that bay.
const selectionMarkers = [];
const markerMaterial = new THREE.MeshBasicMaterial({
color: 0x74d8bb,
transparent: true,
opacity: 0.72,
depthWrite: false
});
for (let i = 0; i < 4; i++) {
const marker = new THREE.Mesh(
new THREE.BoxGeometry(0.25, 0.025, 0.25),
markerMaterial
);
marker.visible = false;
scene.add(marker);
selectionMarkers.push(marker);
}
// Invisible plane used to convert clicks into grid coordinates.
const pickPlane = new THREE.Mesh(
new THREE.PlaneGeometry(BOARD_WIDTH, BOARD_DEPTH),
new THREE.MeshBasicMaterial({
transparent: true,
opacity: 0,
depthWrite: false,
side: THREE.DoubleSide
})
);
pickPlane.rotation.x = -Math.PI / 2;
pickPlane.position.y = 0.13;
scene.add(pickPlane);
// ---------------------------------------------------------------------
// Animation and game state
// ---------------------------------------------------------------------
const tweens = [];
let gameEpoch = 0;
let busy = false;
let solving = false;
let routeOpen = false;
let gateOpened = false;
let gateOpening = false;
let gateOpenPromise = null;
let selectedCrate = null;
let exiting = false;
let solved = false;
function setStatus(message) {
statusText.textContent = message;
}
function setBusy(value) {
busy = value;
solveButton.disabled = value;
}
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
function easeInOutCubic(t) {
return t < 0.5
? 4 * t * t * t
: 1 - Math.pow(-2 * t + 2, 3) / 2;
}
function tweenPosition(object, target, duration = 280) {
return new Promise((resolve) => {
tweens.push({
object,
from: object.position.clone(),
to: target.clone(),
start: performance.now(),
duration,
resolve
});
});
}
function clearTweens() {
for (const tween of tweens) {
tween.resolve();
}
tweens.length = 0;
}
function crateAt(c, r) {
for (const crate of crates.values()) {
if (crate.c === c && crate.r === r) {
return crate;
}
}
return null;
}
function isInside(c, r) {
return c >= 0 && c < WIDTH && r >= 0 && r < HEIGHT;
}
function findPath(startC, startR, endC, endR) {
if (!isInside(endC, endR) || crateAt(endC, endR)) {
return null;
}
const queue = [[startC, startR]];
const visited = new Set([`${startC},${startR}`]);
const parents = new Map();
const directions = [
[1, 0],
[0, 1],
[-1, 0],
[0, -1]
];
while (queue.length) {
const [c, r] = queue.shift();
if (c === endC && r === endR) {
const path = [];
let key = `${c},${r}`;
while (key !== `${startC},${startR}`) {
const [pc, pr] = key.split(",").map(Number);
path.push({ c: pc, r: pr });
key = parents.get(key);
}
return path.reverse();
}
for (const [dc, dr] of directions) {
const nc = c + dc;
const nr = r + dr;
const key = `${nc},${nr}`;
if (
!isInside(nc, nr) ||
visited.has(key) ||
crateAt(nc, nr)
) {
continue;
}
visited.add(key);
parents.set(key, `${c},${r}`);
queue.push([nc, nr]);
}
}
return null;
}
function clearSelection() {
selectedCrate = null;
for (const marker of selectionMarkers) {
marker.visible = false;
}
for (const crate of crates.values()) {
crate.bodyMaterial.emissive.setHex(0x000000);
}
}
function selectCrate(id) {
clearSelection();
selectedCrate = id;
const crate = crates.get(id);
crate.bodyMaterial.emissive.setHex(0x412617);
const directions = [
[1, 0],
[-1, 0],
[0, 1],
[0, -1]
];
selectionMarkers.forEach((marker, index) => {
const [dc, dr] = directions[index];
const c = crate.c + dc;
const r = crate.r + dr;
marker.visible = isInside(c, r) && !crateAt(c, r);
if (marker.visible) {
marker.position.copy(cellPosition(c, r, 0.145));
}
});
setStatus(
`${crate.name} selected. Click a glowing neighboring bay; the warden will brace on the opposite side.`
);
}
function updateDependencyChain() {
const slateDone = !(crates.get("slate").c === 3 && crates.get("slate").r === 3);
const tealDone = !(crates.get("teal").c === 3 && crates.get("teal").r === 2);
const rustDone = !(crates.get("rust").c === 1 && crates.get("rust").r === 2);
const elements = {
depSlate: document.querySelector("#depSlate"),
depTeal: document.querySelector("#depTeal"),
depRust: document.querySelector("#depRust"),
depGate: document.querySelector("#depGate")
};
for (const element of Object.values(elements)) {
element.className = "";
}
if (routeOpen) {
elements.depSlate.className = "done";
elements.depTeal.className = "done";
elements.depRust.className = "done";
elements.depGate.className = "done";
} else if (!slateDone) {
elements.depSlate.className = "current";
} else if (!tealDone) {
elements.depSlate.className = "done";
elements.depTeal.className = "current";
} else {
elements.depSlate.className = "done";
elements.depTeal.className = "done";
elements.depRust.className = "current";
}
}
async function openGate() {
if (gateOpenPromise) {
return gateOpenPromise;
}
const epoch = gameEpoch;
gateOpening = true;
routeOpen = true;
routeStatus.classList.add("open");
routeLabel.textContent = "EAST ROUTE · OPEN";
updateDependencyChain();
setStatus(
"The eastern lane is clear. The wicket is lifting, and the outer passage is opening."
);
gateOpenPromise = (async () => {
const target = new THREE.Vector3(
gate.position.x,
1.95,
gate.position.z
);
await tweenPosition(gate, target, 850);
if (epoch !== gameEpoch) {
return;
}
gateOpened = true;
gateOpening = false;
gateGlowTarget = 34;
gateRuneMaterial.emissive.setHex(0xb36f25);
gateRuneMaterial.emissiveIntensity = 1.8;
pathMaterial.emissive.setHex(0x4b7e67);
pathMaterial.emissiveIntensity = 0.85;
})();
return gateOpenPromise;
}
function checkRoute() {
let clear = true;
for (let c = 0; c < WIDTH; c++) {
if (crateAt(c, 2)) {
clear = false;
break;
}
}
if (clear && !routeOpen) {
void openGate();
}
updateDependencyChain();
}
async function stepPlayerTo(c, r) {
if (!isInside(c, r) || crateAt(c, r)) {
return false;
}
const epoch = gameEpoch;
const dc = c - player.c;
const dr = r - player.r;
player.root.rotation.y = Math.atan2(dc, dr);
await tweenPosition(
player.root,
cellPosition(c, r, 0.085),
245
);
if (epoch !== gameEpoch) {
return false;
}
player.c = c;
player.r = r;
return true;
}
async function pushCrate(crate, dc, dr) {
const destinationC = crate.c + dc;
const destinationR = crate.r + dr;
if (
!isInside(destinationC, destinationR) ||
crateAt(destinationC, destinationR)
) {
return false;
}
const epoch = gameEpoch;
const oldCrateC = crate.c;
const oldCrateR = crate.r;
player.root.rotation.y = Math.atan2(dc, dr);
await Promise.all([
tweenPosition(
crate.group,
cellPosition(destinationC, destinationR, 0.085),
285
),
tweenPosition(
player.root,
cellPosition(oldCrateC, oldCrateR, 0.085),
285
)
]);
if (epoch !== gameEpoch) {
return false;
}
crate.c = destinationC;
crate.r = destinationR;
player.c = oldCrateC;
player.r = oldCrateR;
checkRoute();
return true;
}
async function exitCourtyard() {
if (exiting || solved) {
return;
}
exiting = true;
if (gateOpenPromise) {
await gateOpenPromise;
}
setStatus(
"The wicket stands open. The courier crosses into the amber-lit passage."
);
await sleep(180);
const target = new THREE.Vector3(
BOARD_RIGHT + 1.95,
0.085,
exitRowZ
);
await tweenPosition(player.root, target, 950);
solved = true;
routeLabel.textContent = "EAST ROUTE · CROSSED";
setStatus(
"Exit reached. Ashglass Courtyard is solved — the outer court remembers its name."
);
}
async function walkPlayerTo(c, r) {
const path = findPath(player.c, player.r, c, r);
if (!path) {
setStatus(
"That lane is sealed by a stone. Move the blocking seal first."
);
return;
}
setBusy(true);
for (const step of path) {
const moved = await stepPlayerTo(step.c, step.r);
if (!moved) {
break;
}
if (step.c === WIDTH - 1 && step.r === 2 && routeOpen) {
await exitCourtyard();
break;
}
}
setBusy(false);
}
async function attemptSelectedPush(c, r) {
if (!selectedCrate) {
return false;
}
const crate = crates.get(selectedCrate);
const dc = c - crate.c;
const dr = r - crate.r;
if (Math.abs(dc) + Math.abs(dr) !== 1) {
return false;
}
if (crateAt(c, r)) {
setStatus("That bay is occupied. Choose a glowing empty bay.");
return true;
}
const braceC = crate.c - dc;
const braceR = crate.r - dr;
if (!isInside(braceC, braceR) || crateAt(braceC, braceR)) {
setStatus("There is no room for the warden to brace against that stone.");
return true;
}
setBusy(true);
if (player.c !== braceC || player.r !== braceR) {
const path = findPath(player.c, player.r, braceC, braceR);
if (!path) {
setStatus(
"The warden cannot reach the opposite bay. Another stone blocks the approach."
);
setBusy(false);
return true;
}
for (const step of path) {
const moved = await stepPlayerTo(step.c, step.r);
if (!moved) break;
}
}
await pushCrate(crate, dc, dr);
clearSelection();
setBusy(false);
return true;
}
// ---------------------------------------------------------------------
// Custom camera controls and grid picking
// ---------------------------------------------------------------------
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
let pointerDown = false;
let pointerDragged = false;
let pointerStartX = 0;
let pointerStartY = 0;
let lastPointerX = 0;
let lastPointerY = 0;
function updatePointer(event) {
const rect = canvas.getBoundingClientRect();
pointer.x =
((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y =
-((event.clientY - rect.top) / rect.height) * 2 + 1;
}
function getHit(event) {
updatePointer(event);
raycaster.setFromCamera(pointer, camera);
const crateHits = raycaster.intersectObjects(crateGroups, true);
const planeHits = raycaster.intersectObject(pickPlane, false);
let closest = null;
let closestDistance = Infinity;
for (const hit of crateHits) {
if (hit.distance < closestDistance) {
closest = hit;
closestDistance = hit.distance;
}
}
for (const hit of planeHits) {
if (hit.distance < closestDistance) {
closest = hit;
closestDistance = hit.distance;
}
}
if (!closest) {
return null;
}
if (closest.object.userData.crateId) {
return {
type: "crate",
id: closest.object.userData.crateId
};
}
const c = Math.round(
closest.point.x / CELL + (WIDTH - 1) / 2
);
const r = Math.round(
closest.point.z / CELL + (HEIGHT - 1) / 2
);
if (!isInside(c, r)) {
return null;
}
return { type: "cell", c, r };
}
canvas.addEventListener("pointerdown", (event) => {
if (event.button !== 0 && event.button !== 2) return;
pointerDown = true;
pointerDragged = false;
pointerStartX = event.clientX;
pointerStartY = event.clientY;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
canvas.setPointerCapture(event.pointerId);
});
canvas.addEventListener("pointermove", (event) => {
if (pointerDown) {
const totalDistance = Math.hypot(
event.clientX - pointerStartX,
event.clientY - pointerStartY
);
if (totalDistance > 5) {
pointerDragged = true;
}
if (pointerDragged) {
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
cameraYaw -= dx * 0.006;
cameraPitch = THREE.MathUtils.clamp(
cameraPitch + dy * 0.0045,
0.32,
1.16
);
updateCamera();
}
lastPointerX = event.clientX;
lastPointerY = event.clientY;
canvas.style.cursor = "grabbing";
} else {
const hit = getHit(event);
canvas.style.cursor = hit ? "pointer" : "grab";
}
});
canvas.addEventListener("pointerup", async (event) => {
pointerDown = false;
canvas.style.cursor = "grab";
if (pointerDragged || busy) {
return;
}
const hit = getHit(event);
if (!hit) return;
if (hit.type === "crate") {
selectCrate(hit.id);
return;
}
if (await attemptSelectedPush(hit.c, hit.r)) {
return;
}
await walkPlayerTo(hit.c, hit.r);
});
canvas.addEventListener("pointercancel", () => {
pointerDown = false;
pointerDragged = false;
canvas.style.cursor = "grab";
});
canvas.addEventListener("contextmenu", (event) => {
event.preventDefault();
clearSelection();
});
canvas.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraDistance = THREE.MathUtils.clamp(
cameraDistance + event.deltaY * 0.009,
9.5,
21
);
updateCamera();
},
{ passive: false }
);
// ---------------------------------------------------------------------
// Hints, authored solution and reset
// ---------------------------------------------------------------------
document.querySelector("#hintBtn").addEventListener("click", () => {
if (busy) return;
const slate = crates.get("slate");
const teal = crates.get("teal");
const rust = crates.get("rust");
if (routeOpen) {
setStatus(
"The gate is already open. Click the lit threshold bay, then the courier will leave."
);
return;
}
if (slate.c === 3 && slate.r === 3 && teal.r === 2) {
selectCrate("slate");
setStatus(
"Dependency 1: the slate sill guards the teal stop. Stand west of slate and push it east twice."
);
} else if (teal.r === 2) {
selectCrate("teal");
setStatus(
"Dependency 2: the teal stop blocks rust. Stand south of teal and push it north twice."
);
} else if (rust.c === 2 && rust.r === 2) {
selectCrate("rust");
setStatus(
"Dependency 3: brace west of rust, push it east twice, then stand south and push it north."
);
} else {
setStatus(
"Move rust clear of the eastern lane. Its final bay must be directly north of it."
);
}
});
const solution = [
{ type: "move", c: 0, r: 2 },
{ type: "push", id: "rust", dc: 1, dr: 0 },
{ type: "move", c: 1, r: 3 },
{ type: "move", c: 2, r: 3 },
{ type: "push", id: "slate", dc: 1, dr: 0 },
{ type: "push", id: "slate", dc: 1, dr: 0 },
{ type: "move", c: 3, r: 3 },
{ type: "push", id: "teal", dc: 0, dr: -1 },
{ type: "push", id: "teal", dc: 0, dr: -1 },
{ type: "move", c: 2, r: 1 },
{ type: "move", c: 1, r: 1 },
{ type: "move", c: 1, r: 2 },
{ type: "push", id: "rust", dc: 1, dr: 0 },
{ type: "push", id: "rust", dc: 1, dr: 0 },
{ type: "move", c: 3, r: 3 },
{ type: "move", c: 4, r: 3 },
{ type: "push", id: "rust", dc: 0, dr: -1 },
{ type: "move", c: 5, r: 2 }
];
async function playSolution() {
if (busy) return;
const epoch = gameEpoch;
clearSelection();
solving = true;
setBusy(true);
setStatus(
"The courier repeats the old warden's route: slate, teal, rust, then the wicket."
);
for (const action of solution) {
if (epoch !== gameEpoch) return;
await sleep(135);
if (epoch !== gameEpoch) return;
if (action.type === "move") {
const moved = await stepPlayerTo(action.c, action.r);
if (!moved) return;
} else {
const crate = crates.get(action.id);
const pushed = await pushCrate(crate, action.dc, action.dr);
if (!pushed) return;
}
}
if (epoch !== gameEpoch) return;
await exitCourtyard();
solving = false;
setBusy(false);
}
solveButton.addEventListener("click", playSolution);
function resetGame() {
gameEpoch++;
clearTweens();
clearSelection();
setBusy(false);
solving = false;
routeOpen = false;
gateOpened = false;
gateOpening = false;
gateOpenPromise = null;
exiting = false;
solved = false;
gate.position.set(gateX, 0, exitRowZ);
gateGlowTarget = 0.4;
gateRuneMaterial.emissive.setHex(0x392613);
gateRuneMaterial.emissiveIntensity = 0.6;
pathMaterial.emissive.setHex(0x182a28);
pathMaterial.emissiveIntensity = 0.4;
player.c = 0;
player.r = 1;
player.root.position.copy(cellPosition(0, 1, 0.085));
player.root.rotation.y = 0;
for (const definition of crateDefinitions) {
const crate = crates.get(definition.id);
crate.c = definition.c;
crate.r = definition.r;
crate.group.position.copy(
cellPosition(definition.c, definition.r, 0.085)
);
}
routeStatus.classList.remove("open");
routeLabel.textContent = "EAST ROUTE · SEALED";
updateDependencyChain();
setStatus(
"Select a seal-stone, then click an empty neighboring bay. The warden braces on the opposite side."
);
}
document.querySelector("#resetBtn").addEventListener("click", resetGame);
document.querySelector("#viewBtn").addEventListener("click", () => {
cameraYaw = 0.69;
cameraPitch = 0.72;
cameraDistance = 14.8;
cameraTarget.set(0.25, 0.2, 0);
updateCamera();
});
// ---------------------------------------------------------------------
// Resize and render loop
// ---------------------------------------------------------------------
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
});
function frame(now) {
for (let i = tweens.length - 1; i >= 0; i--) {
const tween = tweens[i];
const progress = THREE.MathUtils.clamp(
(now - tween.start) / tween.duration,
0,
1
);
tween.object.position.lerpVectors(
tween.from,
tween.to,
easeInOutCubic(progress)
);
if (progress >= 1) {
tween.object.position.copy(tween.to);
tweens.splice(i, 1);
tween.resolve();
}
}
const moving = tweens.some((tween) => tween.object === player.root);
if (moving) {
const stride = Math.sin(now * 0.017);
leftLeg.rotation.x = stride * 0.48;
rightLeg.rotation.x = -stride * 0.48;
playerRig.position.y = Math.abs(stride) * 0.035;
} else {
leftLeg.rotation.x *= 0.88;
rightLeg.rotation.x *= 0.88;
playerRig.position.y = Math.sin(now * 0.0025) * 0.008;
}
flames.forEach((flame, index) => {
const pulse = 1 + Math.sin(now * 0.008 + index * 1.7) * 0.13;
flame.scale.y = pulse;
flame.rotation.y = now * 0.001 * (index % 2 ? 1 : -1);
});
gateLight.intensity = THREE.MathUtils.lerp(
gateLight.intensity,
gateGlowTarget,
0.055
);
gateRuneMaterial.emissiveIntensity = THREE.MathUtils.lerp(
gateRuneMaterial.emissiveIntensity,
routeOpen ? 1.8 : 0.6,
0.05
);
renderer.render(scene, camera);
requestAnimationFrame(frame);
}
updateDependencyChain();
requestAnimationFrame(frame);
</script>
</body>
</html>
```