Prompt specification
Build or customize the Three.js 3D scene "Ambiguous Direction Navigation Puzzle" 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: Ambiguous Direction Navigation Puzzle
Category: Art & Culture · Style: Procedural Solid / Shader 3D
License: MIT · Reference: https://three3d.app/scene/ambiguous-direction-navigation-puzzle-x3416
Scene Description Prompt:
A low-poly maze puzzle switching explicitly between world directions and character-relative turns. Use Three.js from cdnjs in one HTML file.
Working Three.js Starter (ambiguous-direction-navigation-puzzle-x3416):
```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="#0b1215" />
<title>Turning Vault — A Perspective Maze</title>
<style>
:root {
--ink: #111b1e;
--night: #0b1215;
--night-2: #111b1f;
--paper: #ece9dd;
--paper-2: #dedacd;
--muted: #798184;
--line: rgba(255, 255, 255, 0.12);
--orange: #ee7048;
--gold: #e9ba63;
--cyan: #76d5d4;
--green: #8cc9a5;
--radius: 22px;
}
* {
box-sizing: border-box;
}
html,
body {
margin: 0;
min-height: 100%;
background: var(--night);
color: var(--paper);
font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
body {
min-height: 100vh;
overflow-x: hidden;
}
button {
font: inherit;
}
button:focus-visible {
outline: 3px solid var(--cyan);
outline-offset: 3px;
}
[hidden] {
display: none !important;
}
.app {
width: min(1540px, 100%);
min-height: 100vh;
margin: 0 auto;
padding: 0 22px;
display: flex;
flex-direction: column;
}
.topbar {
min-height: 82px;
display: grid;
grid-template-columns: 1fr auto 1fr;
align-items: center;
gap: 24px;
border-bottom: 1px solid var(--line);
}
.brand {
display: flex;
align-items: center;
gap: 12px;
min-width: 0;
}
.brand-mark {
width: 35px;
height: 35px;
position: relative;
flex: 0 0 auto;
transform: rotate(30deg) skewY(-8deg);
border: 2px solid var(--orange);
background: rgba(238, 112, 72, 0.08);
box-shadow: inset 0 0 0 5px rgba(238, 112, 72, 0.07);
}
.brand-mark::after {
content: "";
position: absolute;
width: 7px;
height: 7px;
right: 5px;
top: 5px;
background: var(--orange);
}
.brand-name {
font-size: 13px;
font-weight: 800;
letter-spacing: 0.19em;
text-transform: uppercase;
white-space: nowrap;
}
.brand-sub {
display: block;
margin-top: 4px;
color: var(--muted);
font: 10px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.13em;
text-transform: uppercase;
}
.mode-switch {
display: flex;
align-items: center;
padding: 4px;
gap: 4px;
border: 1px solid var(--line);
border-radius: 12px;
background: rgba(255, 255, 255, 0.025);
}
.mode-switch button {
min-height: 38px;
padding: 0 17px;
border: 0;
border-radius: 8px;
background: transparent;
color: #8e999b;
cursor: pointer;
font-size: 11px;
font-weight: 750;
letter-spacing: 0.08em;
text-transform: uppercase;
transition: color 160ms ease, background 160ms ease, transform 160ms ease;
}
.mode-switch button:hover {
color: var(--paper);
}
.mode-switch button.active {
color: var(--ink);
background: var(--paper);
box-shadow: 0 4px 18px rgba(0, 0, 0, 0.24);
}
.mode-index {
margin-right: 7px;
color: var(--orange);
font: 10px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.mode-switch button.active .mode-index {
color: var(--orange);
}
.top-actions {
display: flex;
justify-content: flex-end;
align-items: center;
gap: 9px;
}
.icon-button {
width: 42px;
height: 42px;
display: grid;
place-items: center;
border: 1px solid var(--line);
border-radius: 11px;
background: rgba(255, 255, 255, 0.03);
color: var(--paper);
cursor: pointer;
transition: background 160ms ease, border-color 160ms ease;
}
.icon-button:hover {
background: rgba(255, 255, 255, 0.08);
border-color: rgba(255, 255, 255, 0.25);
}
.icon-button svg {
width: 18px;
height: 18px;
}
main {
flex: 1;
min-height: 0;
display: grid;
grid-template-columns: minmax(0, 1fr) 360px;
gap: 16px;
padding: 16px 0;
}
.viewport {
min-height: 650px;
position: relative;
isolation: isolate;
overflow: hidden;
border: 1px solid var(--line);
border-radius: var(--radius);
background:
radial-gradient(circle at 50% 35%, rgba(72, 119, 119, 0.14), transparent 46%),
linear-gradient(145deg, #111b1f, #081013 74%);
box-shadow: 0 28px 80px rgba(0, 0, 0, 0.26);
}
.viewport::after {
content: "";
position: absolute;
inset: 0;
z-index: 2;
pointer-events: none;
background:
linear-gradient(90deg, rgba(0, 0, 0, 0.15), transparent 12%, transparent 88%, rgba(0, 0, 0, 0.15)),
linear-gradient(0deg, rgba(0, 0, 0, 0.18), transparent 18%, transparent 85%, rgba(0, 0, 0, 0.12));
}
#canvas-wrap {
position: absolute;
inset: 0;
z-index: 1;
}
#canvas-wrap canvas {
display: block;
width: 100%;
height: 100%;
cursor: grab;
touch-action: none;
}
#canvas-wrap canvas:active {
cursor: grabbing;
}
.viewport-top {
position: absolute;
z-index: 4;
top: 20px;
left: 20px;
right: 20px;
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 16px;
pointer-events: none;
}
.sector-label,
.mode-badge {
display: inline-flex;
align-items: center;
gap: 8px;
min-height: 28px;
padding: 0 10px;
border: 1px solid rgba(255, 255, 255, 0.11);
border-radius: 8px;
background: rgba(7, 13, 15, 0.68);
backdrop-filter: blur(10px);
color: #c4ccca;
font: 10px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.12em;
text-transform: uppercase;
}
.sector-label::before {
content: "";
width: 6px;
height: 6px;
border-radius: 50%;
background: var(--orange);
box-shadow: 0 0 12px var(--orange);
}
.mode-badge {
margin-top: 8px;
color: var(--cyan);
border-color: rgba(118, 213, 212, 0.2);
}
.stats {
display: flex;
gap: 7px;
}
.stat {
min-width: 82px;
padding: 9px 12px 8px;
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 10px;
background: rgba(7, 13, 15, 0.68);
backdrop-filter: blur(10px);
}
.stat-label {
display: block;
color: #748083;
font: 9px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.14em;
text-transform: uppercase;
}
.stat-value {
display: block;
margin-top: 3px;
color: #f1efe7;
font: 17px/1.15 ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.03em;
}
.compass-wrap {
position: absolute;
z-index: 4;
left: 20px;
bottom: 21px;
width: 88px;
height: 88px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 50%;
background: rgba(7, 13, 15, 0.62);
backdrop-filter: blur(9px);
pointer-events: none;
}
.compass-wrap::before,
.compass-wrap::after {
content: "";
position: absolute;
background: rgba(255, 255, 255, 0.08);
}
.compass-wrap::before {
width: 1px;
height: 66px;
left: 43px;
top: 10px;
}
.compass-wrap::after {
height: 1px;
width: 66px;
left: 10px;
top: 43px;
}
.compass-n,
.compass-e,
.compass-s,
.compass-w {
position: absolute;
z-index: 2;
color: #7b8889;
font: 9px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.compass-n {
top: 6px;
left: 41px;
color: var(--gold);
}
.compass-e {
right: 7px;
top: 39px;
}
.compass-s {
bottom: 5px;
left: 41px;
}
.compass-w {
left: 6px;
top: 39px;
}
.heading-arrow {
position: absolute;
z-index: 3;
left: 34px;
top: 25px;
width: 19px;
height: 38px;
transform-origin: 50% 50%;
transition: transform 180ms ease;
}
.heading-arrow::before {
content: "";
position: absolute;
inset: 0;
clip-path: polygon(50% 0, 100% 34%, 64% 34%, 64% 100%, 36% 100%, 36% 34%, 0 34%);
background: var(--orange);
filter: drop-shadow(0 0 6px rgba(238, 112, 72, 0.5));
}
.viewport-hint {
position: absolute;
z-index: 4;
left: 50%;
bottom: 21px;
transform: translateX(-50%);
display: flex;
align-items: center;
gap: 9px;
padding: 9px 13px;
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 9px;
background: rgba(7, 13, 15, 0.66);
backdrop-filter: blur(10px);
color: #869294;
font: 10px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.07em;
text-transform: uppercase;
white-space: nowrap;
pointer-events: none;
}
.viewport-hint kbd {
color: #d9ddda;
}
.camera-reset {
position: absolute;
z-index: 5;
right: 20px;
bottom: 20px;
}
.toast {
position: absolute;
z-index: 8;
top: 112px;
left: 50%;
max-width: min(420px, calc(100% - 40px));
padding: 10px 15px;
transform: translate(-50%, -12px);
border: 1px solid rgba(255, 255, 255, 0.13);
border-radius: 9px;
background: rgba(10, 16, 18, 0.92);
color: #dce2df;
box-shadow: 0 15px 40px rgba(0, 0, 0, 0.32);
font-size: 12px;
line-height: 1.4;
text-align: center;
opacity: 0;
pointer-events: none;
transition: opacity 180ms ease, transform 180ms ease;
}
.toast.show {
opacity: 1;
transform: translate(-50%, 0);
}
.toast.alert {
border-color: rgba(238, 112, 72, 0.55);
color: #ffd2c2;
}
.sidebar {
min-width: 0;
padding: 27px 25px 22px;
display: flex;
flex-direction: column;
border-radius: var(--radius);
background:
radial-gradient(circle at 90% 4%, rgba(255, 255, 255, 0.58), transparent 24%),
var(--paper);
color: var(--ink);
box-shadow: 0 28px 80px rgba(0, 0, 0, 0.24);
overflow: auto;
}
.eyebrow {
display: flex;
align-items: center;
gap: 8px;
margin: 0 0 15px;
color: #7d827e;
font: 10px ui-monospace, SFMono-Regular, Menlo, monospace;
font-weight: 700;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.eyebrow::before {
content: "";
width: 24px;
height: 1px;
background: var(--orange);
}
h1 {
margin: 0;
max-width: 290px;
font-family: Georgia, "Times New Roman", serif;
font-size: clamp(37px, 4vw, 51px);
font-weight: 400;
line-height: 0.98;
letter-spacing: -0.045em;
}
h1 em {
color: var(--orange);
font-weight: 400;
}
.intro {
margin: 17px 0 20px;
color: #646c6c;
font-size: 13px;
line-height: 1.65;
}
.objective {
padding: 16px;
border-radius: 14px;
background: var(--night-2);
color: var(--paper);
box-shadow: 0 12px 30px rgba(22, 30, 31, 0.12);
}
.objective-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
}
.objective-label {
color: #899596;
font: 9px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.objective-count {
color: var(--gold);
font: 10px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.objective-title {
margin: 8px 0 5px;
font-family: Georgia, "Times New Roman", serif;
font-size: 21px;
font-weight: 400;
line-height: 1.15;
}
.objective-copy {
min-height: 35px;
margin: 0;
color: #9da8a8;
font-size: 11px;
line-height: 1.55;
}
.sigil-row {
display: flex;
align-items: center;
gap: 10px;
margin-top: 14px;
}
.sigil {
width: 18px;
height: 18px;
position: relative;
transform: rotate(45deg);
border: 1px solid #4d595b;
border-radius: 3px;
transition: background 220ms ease, border-color 220ms ease, box-shadow 220ms ease;
}
.sigil.collected {
border-color: var(--gold);
background: var(--gold);
box-shadow: 0 0 18px rgba(233, 186, 99, 0.44);
}
.progress-track {
height: 3px;
flex: 1;
overflow: hidden;
border-radius: 5px;
background: #344043;
}
.progress-fill {
width: 0;
height: 100%;
border-radius: inherit;
background: var(--gold);
transition: width 250ms ease;
}
.mode-note {
margin: 13px 0 18px;
padding: 12px 13px;
border: 1px solid rgba(17, 27, 30, 0.12);
border-radius: 11px;
background: rgba(255, 255, 255, 0.35);
}
.mode-note strong {
display: block;
margin-bottom: 4px;
color: var(--orange);
font: 10px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.1em;
text-transform: uppercase;
}
.mode-note span {
color: #656d6c;
font-size: 11px;
line-height: 1.45;
}
.section-title {
margin: 0 0 10px;
color: #737a79;
font: 9px ui-monospace, SFMono-Regular, Menlo, monospace;
font-weight: 700;
letter-spacing: 0.15em;
text-transform: uppercase;
}
.controls-card {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
}
.control-line {
min-width: 0;
display: grid;
grid-template-columns: 34px 1fr;
align-items: center;
gap: 8px;
padding: 9px;
border: 1px solid rgba(17, 27, 30, 0.1);
border-radius: 10px;
background: rgba(255, 255, 255, 0.28);
}
.control-line kbd,
.viewport-hint kbd {
display: inline-grid;
place-items: center;
min-width: 29px;
height: 29px;
padding: 0 5px;
border: 1px solid rgba(17, 27, 30, 0.18);
border-bottom-width: 3px;
border-radius: 6px;
background: #f6f3e9;
color: #293436;
font: 11px ui-monospace, SFMono-Regular, Menlo, monospace;
box-shadow: 0 2px 0 rgba(17, 27, 30, 0.05);
}
.control-line b {
display: block;
overflow: hidden;
color: #293436;
font-size: 11px;
font-weight: 750;
text-overflow: ellipsis;
white-space: nowrap;
}
.control-line small {
display: block;
margin-top: 2px;
overflow: hidden;
color: #8a908d;
font-size: 9px;
text-overflow: ellipsis;
white-space: nowrap;
}
.control-footnote {
margin: 8px 2px 18px;
color: #929693;
font-size: 10px;
line-height: 1.45;
}
.actions {
display: grid;
grid-template-columns: 1fr 43px;
gap: 8px;
margin-top: auto;
}
.primary-button,
.hint-button {
min-height: 46px;
border-radius: 11px;
cursor: pointer;
transition: transform 150ms ease, box-shadow 150ms ease, background 150ms ease;
}
.primary-button {
border: 0;
background: var(--orange);
color: #161e20;
font-size: 11px;
font-weight: 850;
letter-spacing: 0.1em;
text-transform: uppercase;
box-shadow: 0 10px 24px rgba(238, 112, 72, 0.22);
}
.primary-button:hover {
transform: translateY(-1px);
box-shadow: 0 13px 28px rgba(238, 112, 72, 0.29);
}
.hint-button {
border: 1px solid rgba(17, 27, 30, 0.13);
background: transparent;
color: #5e6766;
font-size: 16px;
}
.hint-button:hover {
background: rgba(17, 27, 30, 0.05);
}
.sidebar-footer {
display: flex;
justify-content: space-between;
gap: 12px;
margin-top: 13px;
color: #9a9d97;
font: 9px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.touch-controls {
display: none;
position: absolute;
z-index: 9;
right: 18px;
bottom: 72px;
grid-template-columns: repeat(3, 46px);
grid-template-rows: repeat(2, 46px);
gap: 5px;
}
.touch-controls button {
border: 1px solid rgba(255, 255, 255, 0.15);
border-radius: 10px;
background: rgba(7, 13, 15, 0.82);
color: var(--paper);
backdrop-filter: blur(8px);
font-size: 16px;
touch-action: manipulation;
}
.touch-controls button:nth-child(1) {
grid-column: 2;
}
.touch-controls button:nth-child(2) {
grid-column: 1;
grid-row: 2;
}
.touch-controls button:nth-child(3) {
grid-column: 2;
grid-row: 2;
}
.touch-controls button:nth-child(4) {
grid-column: 3;
grid-row: 2;
}
.completion {
position: absolute;
z-index: 10;
inset: 0;
display: grid;
place-items: center;
padding: 20px;
background: rgba(7, 13, 15, 0.76);
backdrop-filter: blur(10px);
}
.completion-card {
width: min(390px, 100%);
padding: 30px;
border: 1px solid rgba(255, 255, 255, 0.16);
border-radius: 20px;
background: #111b1e;
text-align: center;
box-shadow: 0 30px 80px rgba(0, 0, 0, 0.42);
}
.completion-glyph {
width: 48px;
height: 48px;
margin: 0 auto 17px;
transform: rotate(45deg);
border: 2px solid var(--gold);
border-radius: 9px;
box-shadow: 0 0 30px rgba(233, 186, 99, 0.2);
}
.completion-card h2 {
margin: 0;
font-family: Georgia, "Times New Roman", serif;
font-size: 35px;
font-weight: 400;
}
.completion-card p {
margin: 10px 0 22px;
color: #97a2a2;
font-size: 13px;
line-height: 1.6;
}
.completion-card button {
width: 100%;
min-height: 46px;
border: 0;
border-radius: 10px;
background: var(--gold);
color: #172022;
cursor: pointer;
font-weight: 850;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.loading {
position: absolute;
z-index: 20;
inset: 0;
display: grid;
place-items: center;
background: #0b1215;
color: #8f9a9b;
font: 10px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.16em;
text-transform: uppercase;
}
footer {
min-height: 34px;
display: flex;
justify-content: space-between;
align-items: center;
gap: 20px;
color: #5f696b;
font: 9px ui-monospace, SFMono-Regular, Menlo, monospace;
letter-spacing: 0.09em;
text-transform: uppercase;
}
@media (max-width: 1100px) {
main {
grid-template-columns: minmax(0, 1fr) 320px;
}
.sidebar {
padding: 23px 20px 19px;
}
.mode-switch button {
padding: 0 11px;
}
.viewport {
min-height: 600px;
}
}
@media (max-width: 880px) {
.app {
padding: 0 12px;
}
.topbar {
grid-template-columns: 1fr auto;
padding: 12px 0;
}
.mode-switch {
grid-column: 1 / -1;
grid-row: 2;
justify-content: stretch;
}
.mode-switch button {
flex: 1;
}
main {
grid-template-columns: 1fr;
}
.viewport {
min-height: 66vh;
}
.sidebar {
min-height: auto;
}
h1 {
max-width: 560px;
}
.actions {
margin-top: 5px;
}
}
@media (max-width: 580px) {
.app {
padding: 0 8px;
}
.topbar {
gap: 9px;
}
.brand-sub,
.sector-label,
.compass-wrap {
display: none;
}
.mode-switch button {
padding: 0 7px;
font-size: 9px;
}
.mode-index {
display: none;
}
main {
padding-top: 9px;
}
.viewport {
min-height: 570px;
border-radius: 17px;
}
.viewport-top {
top: 12px;
left: 12px;
right: 12px;
}
.stats {
gap: 4px;
}
.stat {
min-width: 64px;
padding: 7px 8px;
}
.stat-value {
font-size: 14px;
}
.mode-badge {
margin-top: 6px;
font-size: 8px;
}
.viewport-hint {
bottom: 12px;
max-width: calc(100% - 84px);
overflow: hidden;
font-size: 8px;
}
.camera-reset {
right: 12px;
bottom: 12px;
}
.sidebar {
border-radius: 17px;
padding: 23px 18px 18px;
}
h1 {
font-size: 40px;
}
.controls-card {
grid-template-columns: 1fr;
}
footer {
justify-content: center;
text-align: center;
}
footer span:last-child {
display: none;
}
}
@media (pointer: coarse) {
.touch-controls {
display: grid;
}
.viewport-hint {
display: none;
}
}
@media (prefers-reduced-motion: reduce) {
*,
*::before,
*::after {
scroll-behavior: auto !important;
transition-duration: 0.01ms !important;
animation-duration: 0.01ms !important;
}
}
</style>
</head>
<body>
<div class="app">
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true"></div>
<div>
<div class="brand-name">Turning Vault</div>
<span class="brand-sub">Perspective puzzle / Run 07</span>
</div>
</div>
<div class="mode-switch" role="group" aria-label="Control perspective">
<button id="world-mode" class="active" aria-pressed="true">
<span class="mode-index">01</span>World directions
</button>
<button id="relative-mode" aria-pressed="false">
<span class="mode-index">02</span>Relative turns
</button>
</div>
<div class="top-actions">
<button id="reset-button" class="icon-button" aria-label="Restart puzzle" title="Restart puzzle (R)">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<path d="M20 11a8 8 0 1 0-2.34 5.66"></path>
<path d="M20 4v7h-7"></path>
</svg>
</button>
</div>
</header>
<main>
<section class="viewport" id="viewport" aria-label="Interactive three-dimensional maze">
<div id="canvas-wrap"></div>
<div class="viewport-top">
<div>
<div class="sector-label">Obsidian sector / 07</div>
<div class="mode-badge" id="mode-badge">World · North is fixed</div>
</div>
<div class="stats" aria-label="Run statistics">
<div class="stat">
<span class="stat-label">Time</span>
<span class="stat-value" id="timer">00:00</span>
</div>
<div class="stat">
<span class="stat-label">Moves</span>
<span class="stat-value" id="steps">000</span>
</div>
</div>
</div>
<div class="compass-wrap" aria-label="Character heading compass">
<span class="compass-n">N</span>
<span class="compass-e">E</span>
<span class="compass-s">S</span>
<span class="compass-w">W</span>
<div class="heading-arrow" id="heading-arrow"></div>
</div>
<div class="viewport-hint">
<kbd>WASD</kbd><span id="viewport-mode-hint">Absolute map directions</span>
<span>·</span><span>Drag to orbit · Scroll to zoom</span>
</div>
<button id="camera-reset" class="icon-button camera-reset" aria-label="Reset camera" title="Reset camera">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<path d="M4 9V4h5"></path>
<path d="M20 15v5h-5"></path>
<path d="M5.5 5.5 9 9"></path>
<path d="M15 15l3.5 3.5"></path>
<circle cx="12" cy="12" r="3"></circle>
</svg>
</button>
<div class="touch-controls" aria-label="Touch movement controls">
<button data-control="north" aria-label="Move north">↑</button>
<button data-control="west" aria-label="Move west">←</button>
<button data-control="south" aria-label="Move south">↓</button>
<button data-control="east" aria-label="Move east">→</button>
</div>
<div class="toast" id="toast" role="status" aria-live="polite"></div>
<div class="completion" id="completion" hidden>
<div class="completion-card">
<div class="completion-glyph" aria-hidden="true"></div>
<div class="eyebrow" style="justify-content:center">Passage open</div>
<h2>Vault cleared.</h2>
<p id="completion-summary">You found another way through.</p>
<button id="play-again">Run it again</button>
</div>
</div>
<div class="loading" id="loading">Constructing the vault…</div>
</section>
<aside class="sidebar">
<div class="eyebrow">Perspective protocol</div>
<h1>Same maze.<br />Two ways to <em>see it.</em></h1>
<p class="intro">
Switch between the map and your explorer. Collect the three sun sigils,
then reach the gate in the north-east.
</p>
<section class="objective">
<div class="objective-head">
<span class="objective-label">Current objective</span>
<span class="objective-count" id="objective-count">0 / 3 sigils</span>
</div>
<h2 class="objective-title" id="objective-title">Wake the gate</h2>
<p class="objective-copy" id="objective-copy">
The golden sigils are scattered along the vault. Collect all three to unlock the exit.
</p>
<div class="sigil-row" aria-label="Sigils collected">
<span class="sigil" id="sigil-0"></span>
<span class="sigil" id="sigil-1"></span>
<span class="sigil" id="sigil-2"></span>
<div class="progress-track"><div class="progress-fill" id="progress-fill"></div></div>
</div>
</section>
<div class="mode-note">
<strong id="mode-note-title">Absolute perspective</strong>
<span id="mode-note-copy">
W always moves north, even when your explorer faces another direction.
</span>
</div>
<h2 class="section-title">Controls / <span id="controls-mode">World</span></h2>
<div class="controls-card" id="controls-card"></div>
<p class="control-footnote" id="control-footnote">
Switching perspectives keeps your position. Turns in relative mode do not count as moves.
</p>
<div class="actions">
<button id="primary-button" class="primary-button">Begin expedition</button>
<button id="hint-button" class="hint-button" aria-label="Reveal a route" title="Reveal a route">✦</button>
</div>
<div class="sidebar-footer">
<span id="footer-status">Awaiting explorer</span>
<span>Press M to switch mode</span>
</div>
</aside>
</main>
<footer>
<span>Procedural vault / Low-poly study No. 07</span>
<span>Keyboard or touch · Camera can be orbited manually</span>
</footer>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
// -------------------------------------------------------------------------
// DOM and shared state
// -------------------------------------------------------------------------
const $ = (selector) => document.querySelector(selector);
const viewport = $("#viewport");
const canvasWrap = $("#canvas-wrap");
const timerEl = $("#timer");
const stepsEl = $("#steps");
const toastEl = $("#toast");
const headingArrow = $("#heading-arrow");
const primaryButton = $("#primary-button");
const hintButton = $("#hint-button");
const completion = $("#completion");
const completionSummary = $("#completion-summary");
const controlsCard = $("#controls-card");
const modeBadge = $("#mode-badge");
const viewportModeHint = $("#viewport-mode-hint");
const modeNoteTitle = $("#mode-note-title");
const modeNoteCopy = $("#mode-note-copy");
const controlsMode = $("#controls-mode");
const controlFootnote = $("#control-footnote");
const footerStatus = $("#footer-status");
const DIRS = [
{ name: "north", dr: -1, dc: 0, angle: 0 },
{ name: "east", dr: 0, dc: 1, angle: -Math.PI / 2 },
{ name: "south", dr: 1, dc: 0, angle: Math.PI },
{ name: "west", dr: 0, dc: -1, angle: Math.PI / 2 }
];
const state = {
mode: "world",
started: false,
paused: false,
completed: false,
runStartedAt: 0,
elapsedBefore: 0,
steps: 0,
facing: 0,
moving: false,
playerCell: { r: 13, c: 1 },
actionQueue: [],
collected: new Set()
};
let toastTimer;
let hintMesh = null;
let hintActive = false;
function toast(message, alert = false) {
clearTimeout(toastTimer);
toastEl.textContent = message;
toastEl.classList.toggle("alert", alert);
toastEl.classList.add("show");
toastTimer = setTimeout(() => toastEl.classList.remove("show"), 2600);
}
// -------------------------------------------------------------------------
// Deterministic maze generation
// -------------------------------------------------------------------------
const GRID = 15;
const START = { r: 13, c: 1 };
const GOAL = { r: 1, c: 13 };
const maze = Array.from({ length: GRID }, () => Array(GRID).fill(1));
let randomState = 90417;
function random() {
randomState = (randomState * 1664525 + 1013904223) >>> 0;
return randomState / 4294967296;
}
function shuffledDirections() {
const dirs = [
[-2, 0],
[2, 0],
[0, -2],
[0, 2]
];
for (let i = dirs.length - 1; i > 0; i--) {
const j = Math.floor(random() * (i + 1));
[dirs[i], dirs[j]] = [dirs[j], dirs[i]];
}
return dirs;
}
function carve(r, c) {
maze[r][c] = 0;
for (const [dr, dc] of shuffledDirections()) {
const nr = r + dr;
const nc = c + dc;
if (
nr > 0 && nr < GRID - 1 &&
nc > 0 && nc < GRID - 1 &&
maze[nr][nc] === 1
) {
maze[r + dr / 2][c + dc / 2] = 0;
carve(nr, nc);
}
}
}
carve(START.r, START.c);
function cellKey(r, c) {
return `${r},${c}`;
}
function findPath(from, to) {
const queue = [{ ...from }];
const previous = new Map([[cellKey(from.r, from.c), null]]);
while (queue.length) {
const current = queue.shift();
if (current.r === to.r && current.c === to.c) break;
for (const dir of DIRS) {
const nr = current.r + dir.dr;
const nc = current.c + dir.dc;
if (
nr < 0 || nr >= GRID ||
nc < 0 || nc >= GRID ||
maze[nr][nc] === 1 ||
previous.has(cellKey(nr, nc))
) continue;
previous.set(cellKey(nr, nc), current);
queue.push({ r: nr, c: nc });
}
}
if (!previous.has(cellKey(to.r, to.c))) return [];
const path = [];
let current = to;
while (current) {
path.push(current);
current = previous.get(cellKey(current.r, current.c));
}
return path.reverse();
}
const solution = findPath(START, GOAL);
const keyIndices = [
Math.max(2, Math.floor(solution.length * 0.24)),
Math.max(3, Math.floor(solution.length * 0.51)),
Math.max(4, Math.floor(solution.length * 0.76))
];
const keyCells = keyIndices.map((index) => ({ ...solution[index] }));
function worldPosition(cell) {
const half = (GRID - 1) / 2;
return {
x: cell.c - half,
z: cell.r - half
};
}
// -------------------------------------------------------------------------
// Three.js scene
// -------------------------------------------------------------------------
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x0b1418);
scene.fog = new THREE.Fog(0x0b1418, 24, 48);
const renderer = new THREE.WebGLRenderer({
antialias: true,
alpha: false,
powerPreference: "high-performance"
});
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.16;
canvasWrap.appendChild(renderer.domElement);
const camera = new THREE.OrthographicCamera(-10, 10, 10, -10, 0.1, 100);
const cameraTarget = new THREE.Vector3(0, 0.25, 0);
let cameraAzimuth = 0.66;
let cameraElevation = 0.91;
let cameraZoom = 1;
function updateCamera() {
const radius = 28;
const horizontal = Math.cos(cameraElevation) * radius;
camera.position.set(
cameraTarget.x + Math.sin(cameraAzimuth) * horizontal,
cameraTarget.y + Math.sin(cameraElevation) * radius,
cameraTarget.z + Math.cos(cameraAzimuth) * horizontal
);
camera.lookAt(cameraTarget);
camera.zoom = cameraZoom;
camera.updateProjectionMatrix();
}
updateCamera();
const hemisphere = new THREE.HemisphereLight(0xc5e4e2, 0x111719, 1.85);
scene.add(hemisphere);
const keyLight = new THREE.DirectionalLight(0xffd9a3, 3.3);
keyLight.position.set(-9, 15, 10);
keyLight.castShadow = true;
keyLight.shadow.mapSize.set(1024, 1024);
keyLight.shadow.camera.left = -12;
keyLight.shadow.camera.right = 12;
keyLight.shadow.camera.top = 12;
keyLight.shadow.camera.bottom = -12;
keyLight.shadow.camera.near = 1;
keyLight.shadow.camera.far = 40;
keyLight.shadow.bias = -0.0012;
scene.add(keyLight);
const rimLight = new THREE.DirectionalLight(0x74d8dc, 1.2);
rimLight.position.set(10, 7, -12);
scene.add(rimLight);
const orangeLight = new THREE.DirectionalLight(0xee7048, 0.7);
orangeLight.position.set(12, 4, 8);
scene.add(orangeLight);
const ground = new THREE.Mesh(
new THREE.PlaneGeometry(80, 80),
new THREE.MeshStandardMaterial({
color: 0x081013,
roughness: 1,
metalness: 0
})
);
ground.rotation.x = -Math.PI / 2;
ground.position.y = -0.25;
ground.receiveShadow = true;
scene.add(ground);
const base = new THREE.Mesh(
new THREE.BoxGeometry(GRID + 0.5, 0.2, GRID + 0.5),
new THREE.MeshStandardMaterial({
color: 0x121f23,
roughness: 0.78,
metalness: 0.12
})
);
base.position.y = -0.13;
base.receiveShadow = true;
base.castShadow = true;
scene.add(base);
const openCells = [];
const wallCells = [];
for (let r = 0; r < GRID; r++) {
for (let c = 0; c < GRID; c++) {
(maze[r][c] === 0 ? openCells : wallCells).push({ r, c });
}
}
const dummy = new THREE.Object3D();
const color = new THREE.Color();
// Floor tiles
const floorGeometry = new THREE.BoxGeometry(0.94, 0.08, 0.94);
const floorMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.9,
metalness: 0.04
});
const floors = new THREE.InstancedMesh(floorGeometry, floorMaterial, openCells.length);
floors.receiveShadow = true;
openCells.forEach((cell, index) => {
const position = worldPosition(cell);
dummy.position.set(position.x, 0, position.z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
floors.setMatrixAt(index, dummy.matrix);
color.setHSL(0.49 + random() * 0.025, 0.18, 0.115 + random() * 0.025);
floors.setColorAt(index, color);
});
floors.instanceMatrix.needsUpdate = true;
if (floors.instanceColor) floors.instanceColor.needsUpdate = true;
scene.add(floors);
// Wall blocks
const wallGeometry = new THREE.BoxGeometry(0.96, 1.08, 0.96);
const wallMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.77,
metalness: 0.09
});
const walls = new THREE.InstancedMesh(wallGeometry, wallMaterial, wallCells.length);
walls.castShadow = true;
walls.receiveShadow = true;
wallCells.forEach((cell, index) => {
const position = worldPosition(cell);
dummy.position.set(position.x, 0.54, position.z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
walls.setMatrixAt(index, dummy.matrix);
color.setHSL(0.52 + random() * 0.025, 0.16, 0.205 + random() * 0.035);
walls.setColorAt(index, color);
});
walls.instanceMatrix.needsUpdate = true;
if (walls.instanceColor) walls.instanceColor.needsUpdate = true;
scene.add(walls);
// Lighter wall caps create readable low-poly geometry.
const capGeometry = new THREE.BoxGeometry(0.88, 0.065, 0.88);
const capMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.72,
metalness: 0.06
});
const caps = new THREE.InstancedMesh(capGeometry, capMaterial, wallCells.length);
caps.castShadow = true;
caps.receiveShadow = true;
wallCells.forEach((cell, index) => {
const position = worldPosition(cell);
dummy.position.set(position.x, 1.105, position.z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
caps.setMatrixAt(index, dummy.matrix);
color.setHSL(0.50 + random() * 0.035, 0.15, 0.29 + random() * 0.045);
caps.setColorAt(index, color);
});
caps.instanceMatrix.needsUpdate = true;
if (caps.instanceColor) caps.instanceColor.needsUpdate = true;
scene.add(caps);
// Small inset runes on selected wall caps.
const runeMaterial = new THREE.MeshBasicMaterial({
color: 0xc49b59,
transparent: true,
opacity: 0.52
});
const runeGeometry = new THREE.PlaneGeometry(0.12, 0.38);
const runeCells = wallCells.filter((_, index) => index % 13 === 0).slice(0, 13);
runeCells.forEach((cell) => {
const position = worldPosition(cell);
const rune = new THREE.Mesh(runeGeometry, runeMaterial);
rune.rotation.x = -Math.PI / 2;
rune.rotation.z = Math.random() * Math.PI;
rune.position.set(position.x, 1.141, position.z);
scene.add(rune);
});
// Start pad
const startPosition = worldPosition(START);
const startPad = new THREE.Mesh(
new THREE.RingGeometry(0.27, 0.36, 24),
new THREE.MeshBasicMaterial({
color: 0x76d5d4,
transparent: true,
opacity: 0.65,
side: THREE.DoubleSide
})
);
startPad.rotation.x = -Math.PI / 2;
startPad.position.set(startPosition.x, 0.055, startPosition.z);
scene.add(startPad);
// Goal portal
const portal = new THREE.Group();
const goalPosition = worldPosition(GOAL);
portal.position.set(goalPosition.x, 0.73, goalPosition.z);
const portalMaterial = new THREE.MeshStandardMaterial({
color: 0x707b79,
emissive: 0x2b2921,
emissiveIntensity: 0.8,
roughness: 0.4,
metalness: 0.35
});
const portalRing = new THREE.Mesh(
new THREE.TorusGeometry(0.46, 0.095, 7, 24),
portalMaterial
);
portalRing.castShadow = true;
portal.add(portalRing);
const portalInnerMaterial = new THREE.MeshBasicMaterial({
color: 0x111719,
transparent: true,
opacity: 0.88,
side: THREE.DoubleSide
});
const portalInner = new THREE.Mesh(
new THREE.CircleGeometry(0.37, 24),
portalInnerMaterial
);
portalInner.position.z = -0.015;
portal.add(portalInner);
const portalBase = new THREE.Mesh(
new THREE.CylinderGeometry(0.43, 0.54, 0.16, 8),
new THREE.MeshStandardMaterial({
color: 0x263638,
roughness: 0.76,
metalness: 0.18
})
);
portalBase.position.y = -0.65;
portalBase.castShadow = true;
portal.add(portalBase);
const lockDots = [];
for (let i = 0; i < 3; i++) {
const angle = -Math.PI / 2 + (i - 1) * 0.48;
const lock = new THREE.Mesh(
new THREE.OctahedronGeometry(0.075, 0),
new THREE.MeshStandardMaterial({
color: 0x596260,
emissive: 0x171a18,
roughness: 0.5
})
);
lock.position.set(Math.cos(angle) * 0.62, Math.sin(angle) * 0.62, 0.04);
portal.add(lock);
lockDots.push(lock);
}
scene.add(portal);
// Collectible sigils
const keyGroups = [];
const keyMaterials = [];
keyCells.forEach((cell, index) => {
const group = new THREE.Group();
const position = worldPosition(cell);
group.position.set(position.x, 0.74, position.z);
const material = new THREE.MeshStandardMaterial({
color: 0xf2c66f,
emissive: 0x8b4f16,
emissiveIntensity: 0.7,
roughness: 0.28,
metalness: 0.48
});
const gem = new THREE.Mesh(
new THREE.OctahedronGeometry(0.24, 0),
material
);
gem.castShadow = true;
group.add(gem);
const halo = new THREE.Mesh(
new THREE.TorusGeometry(0.34, 0.022, 5, 24),
new THREE.MeshBasicMaterial({
color: 0xf2c66f,
transparent: true,
opacity: 0.62
})
);
halo.rotation.x = Math.PI / 2;
group.add(halo);
const shadow = new THREE.Mesh(
new THREE.CircleGeometry(0.22, 16),
new THREE.MeshBasicMaterial({
color: 0xf2c66f,
transparent: true,
opacity: 0.11,
side: THREE.DoubleSide
})
);
shadow.rotation.x = -Math.PI / 2;
shadow.position.y = -0.69;
group.add(shadow);
group.userData = {
gem,
halo,
shadow,
phase: index * 1.7,
collected: false
};
keyGroups.push(group);
keyMaterials.push(material);
scene.add(group);
});
// Explorer
const player = new THREE.Group();
const startWorld = worldPosition(START);
player.position.set(startWorld.x, 0, startWorld.z);
const playerBodyMaterial = new THREE.MeshStandardMaterial({
color: 0xdf744c,
roughness: 0.62,
metalness: 0.08
});
const playerDarkMaterial = new THREE.MeshStandardMaterial({
color: 0x1c292c,
roughness: 0.76,
metalness: 0.15
});
const playerLightMaterial = new THREE.MeshStandardMaterial({
color: 0xe9e5d4,
roughness: 0.65,
metalness: 0.04
});
const body = new THREE.Mesh(
new THREE.CylinderGeometry(0.2, 0.29, 0.46, 6),
playerBodyMaterial
);
body.position.y = 0.42;
body.castShadow = true;
player.add(body);
const head = new THREE.Mesh(
new THREE.DodecahedronGeometry(0.24, 0),
playerLightMaterial
);
head.position.y = 0.82;
head.castShadow = true;
player.add(head);
const visor = new THREE.Mesh(
new THREE.BoxGeometry(0.25, 0.1, 0.055),
new THREE.MeshStandardMaterial({
color: 0x78d7d5,
emissive: 0x286f72,
emissiveIntensity: 0.9,
roughness: 0.25,
metalness: 0.3
})
);
visor.position.set(0, 0.83, -0.205);
player.add(visor);
const backpack = new THREE.Mesh(
new THREE.BoxGeometry(0.25, 0.3, 0.14),
playerDarkMaterial
);
backpack.position.set(0, 0.46, 0.22);
backpack.castShadow = true;
player.add(backpack);
const legGeometry = new THREE.CylinderGeometry(0.075, 0.09, 0.23, 5);
[-0.11, 0.11].forEach((x) => {
const leg = new THREE.Mesh(legGeometry, playerDarkMaterial);
leg.position.set(x, 0.14, 0);
leg.castShadow = true;
player.add(leg);
});
const playerShadow = new THREE.Mesh(
new THREE.CircleGeometry(0.34, 20),
new THREE.MeshBasicMaterial({
color: 0x000000,
transparent: true,
opacity: 0.25,
side: THREE.DoubleSide
})
);
playerShadow.rotation.x = -Math.PI / 2;
playerShadow.position.y = 0.015;
player.add(playerShadow);
scene.add(player);
// Wall-top braziers add warm points of light.
const flameMaterial = new THREE.MeshBasicMaterial({ color: 0xffad5f });
const brazierMaterial = new THREE.MeshStandardMaterial({
color: 0x273538,
roughness: 0.65,
metalness: 0.35
});
const brazierCandidates = wallCells
.filter((cell) => {
const openNeighbor = DIRS.some((dir) => {
const nr = cell.r + dir.dr;
const nc = cell.c + dir.dc;
return maze[nr]?.[nc] === 0;
});
return openNeighbor;
})
.filter((_, index) => index % Math.max(1, Math.floor(wallCells.length / 7)) === 0)
.slice(0, 7);
brazierCandidates.forEach((cell, index) => {
const position = worldPosition(cell);
const brazier = new THREE.Group();
brazier.position.set(position.x, 1.14, position.z);
const stem = new THREE.Mesh(
new THREE.CylinderGeometry(0.055, 0.08, 0.24, 5),
brazierMaterial
);
stem.position.y = 0.12;
brazier.add(stem);
const flame = new THREE.Mesh(
new THREE.ConeGeometry(0.1, 0.27, 5),
flameMaterial
);
flame.position.y = 0.35;
brazier.add(flame);
if (index % 2 === 0) {
const light = new THREE.PointLight(0xff9a4a, 1.8, 4.2, 2);
light.position.y = 0.35;
brazier.add(light);
}
scene.add(brazier);
});
// Floating dust particles.
const dustPositions = [];
for (let i = 0; i < 150; i++) {
dustPositions.push(
(random() - 0.5) * 19,
random() * 7 + 0.4,
(random() - 0.5) * 19
);
}
const dustGeometry = new THREE.BufferGeometry();
dustGeometry.setAttribute(
"position",
new THREE.Float32BufferAttribute(dustPositions, 3)
);
const dust = new THREE.Points(
dustGeometry,
new THREE.PointsMaterial({
color: 0xb8d4d0,
size: 0.025,
transparent: true,
opacity: 0.26,
sizeAttenuation: true
})
);
scene.add(dust);
// -------------------------------------------------------------------------
// Interface rendering and mode switching
// -------------------------------------------------------------------------
function renderControls() {
if (state.mode === "world") {
controlsMode.textContent = "World";
modeBadge.textContent = "World · North is fixed";
viewportModeHint.textContent = "Absolute map directions";
modeNoteTitle.textContent = "Absolute perspective";
modeNoteCopy.textContent =
"W always moves north, even when your explorer faces another direction.";
controlsCard.innerHTML = `
<div class="control-line">
<kbd>W</kbd><span><b>North</b><small>Fixed to the map</small></span>
</div>
<div class="control-line">
<kbd>S</kbd><span><b>South</b><small>Fixed to the map</small></span>
</div>
<div class="control-line">
<kbd>A</kbd><span><b>West</b><small>Fixed to the map</small></span>
</div>
<div class="control-line">
<kbd>D</kbd><span><b>East</b><small>Fixed to the map</small></span>
</div>
`;
} else {
controlsMode.textContent = "Relative";
modeBadge.textContent = "Relative · Body-centric";
viewportModeHint.textContent = "Body-relative movement";
modeNoteTitle.textContent = "Relative perspective";
modeNoteCopy.textContent =
"Your explorer's facing becomes the reference. A and D turn; W moves forward.";
controlsCard.innerHTML = `
<div class="control-line">
<kbd>W</kbd><span><b>Forward</b><small>Current heading</small></span>
</div>
<div class="control-line">
<kbd>S</kbd><span><b>Backward</b><small>Opposite heading</small></span>
</div>
<div class="control-line">
<kbd>A</kbd><span><b>Turn left</b><small>90° rotation</small></span>
</div>
<div class="control-line">
<kbd>D</kbd><span><b>Turn right</b><small>90° rotation</small></span>
</div>
`;
}
controlFootnote.textContent =
state.mode === "relative"
? "Switching perspectives keeps your position. A and D turn without counting as moves."
: "Switching perspectives keeps your position. World directions never depend on your heading.";
}
function setMode(mode) {
if (state.mode === mode) return;
state.mode = mode;
$("#world-mode").classList.toggle("active", mode === "world");
$("#relative-mode").classList.toggle("active", mode === "relative");
$("#world-mode").setAttribute("aria-pressed", String(mode === "world"));
$("#relative-mode").setAttribute("aria-pressed", String(mode === "relative"));
renderControls();
toast(
mode === "world"
? "World perspective: directions are fixed to the map."
: "Relative perspective: move from your explorer's point of view."
);
}
$("#world-mode").addEventListener("click", () => setMode("world"));
$("#relative-mode").addEventListener("click", () => setMode("relative"));
// -------------------------------------------------------------------------
// Run lifecycle and game logic
// -------------------------------------------------------------------------
function beginRun() {
if (state.completed) return resetGame();
if (state.started && !state.paused) return;
state.paused = false;
state.started = true;
state.runStartedAt = performance.now();
primaryButton.textContent = "Pause run";
footerStatus.textContent = "Expedition active";
toast("The vault is open. Find the three sun sigils.");
}
function pauseRun() {
if (!state.started || state.paused || state.completed) return;
state.elapsedBefore += performance.now() - state.runStartedAt;
state.paused = true;
state.actionQueue.length = 0;
primaryButton.textContent = "Resume run";
footerStatus.textContent = "Expedition paused";
toast("Expedition paused.");
}
function currentElapsed(now = performance.now()) {
if (!state.started || state.paused || state.completed) return state.elapsedBefore;
return state.elapsedBefore + (now - state.runStartedAt);
}
function formatTime(milliseconds) {
const totalSeconds = Math.floor(milliseconds / 1000);
const minutes = Math.floor(totalSeconds / 60);
const seconds = totalSeconds % 60;
return `${String(minutes).padStart(2, "0")}:${String(seconds).padStart(2, "0")}`;
}
function updateObjective() {
const count = state.collected.size;
$("#objective-count").textContent = `${count} / 3 sigils`;
$("#progress-fill").style.width = `${(count / 3) * 100}%`;
for (let i = 0; i < 3; i++) {
$(`#sigil-${i}`).classList.toggle("collected", state.collected.has(i));
}
if (count < 3) {
$("#objective-title").textContent = "Wake the gate";
$("#objective-copy").textContent =
"The golden sigils are scattered along the vault. Collect all three to unlock the exit.";
} else {
$("#objective-title").textContent = "Reach the north-east gate";
$("#objective-copy").textContent =
"All three sigils are yours. The gate is awake—navigate to the portal and escape.";
}
}
function resetGame() {
state.started = false;
state.paused = false;
state.completed = false;
state.runStartedAt = 0;
state.elapsedBefore = 0;
state.steps = 0;
state.facing = 0;
state.moving = false;
state.playerCell = { ...START };
state.actionQueue.length = 0;
state.collected.clear();
player.position.set(startWorld.x, 0, startWorld.z);
player.rotation.y = 0;
playerTargetYaw = 0;
keyGroups.forEach((group) => {
group.visible = true;
group.userData.collected = false;
});
portalMaterial.color.set(0x707b79);
portalMaterial.emissive.set(0x2b2921);
portalMaterial.emissiveIntensity = 0.8;
portalInnerMaterial.color.set(0x111719);
lockDots.forEach((dot) => {
dot.material.color.set(0x596260);
dot.material.emissive.set(0x171a18);
});
clearHint();
completion.hidden = true;
primaryButton.textContent = "Begin expedition";
footerStatus.textContent = "Awaiting explorer";
timerEl.textContent = "00:00";
stepsEl.textContent = "000";
updateObjective();
updateHeading();
}
function updateHeading() {
const degrees = (state.facing * 90 + 360) % 360;
headingArrow.style.transform = `rotate(${-degrees}deg)`;
}
function queueAction(action) {
if (state.completed || state.paused) return;
if (!state.started) beginRun();
if (state.actionQueue.length < 3) state.actionQueue.push(action);
processActions();
}
function processActions() {
if (state.moving || state.paused || state.completed) return;
while (state.actionQueue.length) {
const action = state.actionQueue.shift();
if (action.type === "turn") {
state.facing = (state.facing + action.amount + 4) % 4;
playerTargetYaw = DIRS[state.facing].angle;
updateHeading();
continue;
}
const direction = resolveMoveDirection(action);
if (!direction) continue;
const nextRow = state.playerCell.r + direction.dr;
const nextColumn = state.playerCell.c + direction.dc;
if (
nextRow < 0 || nextRow >= GRID ||
nextColumn < 0 || nextColumn >= GRID ||
maze[nextRow][nextColumn] === 1
) {
toast("A stone wall blocks that direction.", true);
continue;
}
state.facing = DIRS.indexOf(direction);
playerTargetYaw = direction.angle;
updateHeading();
const from = player.position.clone();
const target = worldPosition({ r: nextRow, c: nextColumn });
state.playerCell = { r: nextRow, c: nextColumn };
state.steps++;
state.moving = true;
moveAnimation = {
from,
to: new THREE.Vector3(target.x, 0, target.z),
start: performance.now(),
duration: 205
};
stepsEl.textContent = String(state.steps).padStart(3, "0");
break;
}
}
function resolveMoveDirection(action) {
if (state.mode === "world") {
return DIRS[action.direction];
}
if (action.direction === "forward") return DIRS[state.facing];
if (action.direction === "backward") return DIRS[(state.facing + 2) % 4];
return null;
}
function completeMove() {
state.moving = false;
keyGroups.forEach((group, index) => {
if (
!state.collected.has(index) &&
group.userData.gem.position !== undefined &&
group.position.x === worldPosition(state.playerCell).x &&
group.position.z === worldPosition(state.playerCell).z
) {
collectKey(index);
}
});
if (
state.playerCell.r === GOAL.r &&
state.playerCell.c === GOAL.c
) {
if (state.collected.size === 3) {
completeGame();
} else {
toast(`The gate is locked. ${3 - state.collected.size} sigil(s) remain.`, true);
}
}
processActions();
}
function collectKey(index) {
state.collected.add(index);
keyGroups[index].visible = false;
updateObjective();
toast(
state.collected.size === 3
? "The gate is awake. Head north-east!"
: `Sun sigil ${state.collected.size} of 3 collected.`
);
if (state.collected.size === 3) {
portalMaterial.color.set(0xf0bd65);
portalMaterial.emissive.set(0xa56721);
portalMaterial.emissiveIntensity = 1.8;
portalInnerMaterial.color.set(0x5e3a18);
lockDots.forEach((dot) => {
dot.material.color.set(0xf0bd65);
dot.material.emissive.set(0x9a5a18);
});
}
}
function completeGame() {
state.completed = true;
state.elapsedBefore = currentElapsed();
state.actionQueue.length = 0;
primaryButton.textContent = "Run again";
footerStatus.textContent = "Vault cleared";
const minutes = Math.floor(state.elapsedBefore / 60000);
const seconds = Math.floor((state.elapsedBefore % 60000) / 1000);
completionSummary.textContent =
`The gate opened in ${minutes}:${String(seconds).padStart(2, "0")} ` +
`using ${state.steps} moves. You found another way through.`;
completion.hidden = false;
toast("Vault cleared.");
}
primaryButton.addEventListener("click", () => {
if (!state.started) beginRun();
else if (state.paused) beginRun();
else if (state.completed) resetGame();
else pauseRun();
});
$("#reset-button").addEventListener("click", () => {
resetGame();
toast("The vault has been reset.");
});
$("#play-again").addEventListener("click", resetGame);
// -------------------------------------------------------------------------
// Route hint
// -------------------------------------------------------------------------
function clearHint() {
if (hintMesh) {
scene.remove(hintMesh);
hintMesh.geometry.dispose();
hintMesh.material.dispose();
hintMesh = null;
}
hintActive = false;
hintButton.style.color = "#5e6766";
hintButton.title = "Reveal a route";
}
function routeTo(target) {
return findPath(state.playerCell, target);
}
function buildHintRoute() {
clearHint();
let route = [];
let current = state.playerCell;
for (let i = 0; i < keyCells.length; i++) {
if (state.collected.has(i)) continue;
const segment = findPath(current, keyCells[i]);
route.push(...segment.slice(1));
current = keyCells[i];
}
const finalSegment = findPath(current, GOAL);
route.push(...finalSegment.slice(1));
if (!route.length) {
toast("The route is already clear.");
return;
}
const geometry = new THREE.SphereGeometry(0.055, 6, 4);
const material = new THREE.MeshBasicMaterial({
color: 0x78d8d5,
transparent: true,
opacity: 0.68
});
hintMesh = new THREE.InstancedMesh(geometry, material, route.length);
route.forEach((cell, index) => {
const position = worldPosition(cell);
dummy.position.set(position.x, 0.11, position.z);
dummy.rotation.set(0, 0, 0);
dummy.scale.set(1, 1, 1);
dummy.updateMatrix();
hintMesh.setMatrixAt(index, dummy.matrix);
});
hintMesh.instanceMatrix.needsUpdate = true;
scene.add(hintMesh);
hintActive = true;
hintButton.style.color = "#ee7048";
hintButton.title = "Hide route";
toast("A route to the remaining objectives is revealed.");
}
hintButton.addEventListener("click", () => {
if (hintActive) {
clearHint();
toast("Route hidden.");
} else {
buildHintRoute();
}
});
// -------------------------------------------------------------------------
// Keyboard and touch input
// -------------------------------------------------------------------------
window.addEventListener("keydown", (event) => {
if (event.ctrlKey || event.metaKey || event.altKey) return;
const key = event.key.toLowerCase();
if (["arrowup", "arrowdown", "arrowleft", "arrowright", " "].includes(key)) {
event.preventDefault();
}
if (key === "m") {
event.preventDefault();
setMode(state.mode === "world" ? "relative" : "world");
return;
}
if (key === "r") {
event.preventDefault();
resetGame();
toast("The vault has been reset.");
return;
}
if (key === "escape") {
pauseRun();
return;
}
if (state.mode === "world") {
if (key === "w" || key === "arrowup") {
queueAction({ type: "move", direction: 0 });
} else if (key === "s" || key === "arrowdown") {
queueAction({ type: "move", direction: 2 });
} else if (key === "a" || key === "arrowleft") {
queueAction({ type: "move", direction: 3 });
} else if (key === "d" || key === "arrowright") {
queueAction({ type: "move", direction: 1 });
}
} else {
if (key === "w" || key === "arrowup") {
queueAction({ type: "move", direction: "forward" });
} else if (key === "s" || key === "arrowdown") {
queueAction({ type: "move", direction: "backward" });
} else if (key === "a" || key === "arrowleft") {
queueAction({ type: "turn", amount: -1 });
} else if (key === "d" || key === "arrowright") {
queueAction({ type: "turn", amount: 1 });
}
}
});
document.querySelectorAll("[data-control]").forEach((button) => {
button.addEventListener("click", () => {
const control = button.dataset.control;
if (state.mode === "world") {
const direction = { north: 0, east: 1, south: 2, west: 3 }[control];
queueAction({ type: "move", direction });
} else {
if (control === "north") {
queueAction({ type: "move", direction: "forward" });
} else if (control === "south") {
queueAction({ type: "move", direction: "backward" });
} else if (control === "west") {
queueAction({ type: "turn", amount: -1 });
} else if (control === "east") {
queueAction({ type: "turn", amount: 1 });
}
}
});
});
// -------------------------------------------------------------------------
// Direct camera controls: drag to orbit, wheel to zoom
// -------------------------------------------------------------------------
let dragging = false;
let dragX = 0;
let dragY = 0;
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
dragX = event.clientX;
dragY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const deltaX = event.clientX - dragX;
const deltaY = event.clientY - dragY;
cameraAzimuth -= deltaX * 0.005;
cameraElevation = THREE.MathUtils.clamp(
cameraElevation + deltaY * 0.004,
0.46,
1.25
);
dragX = event.clientX;
dragY = event.clientY;
updateCamera();
});
function stopDragging(event) {
dragging = false;
if (event.pointerId !== undefined && renderer.domElement.hasPointerCapture(event.pointerId)) {
renderer.domElement.releasePointerCapture(event.pointerId);
}
}
renderer.domElement.addEventListener("pointerup", stopDragging);
renderer.domElement.addEventListener("pointercancel", stopDragging);
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraZoom = THREE.MathUtils.clamp(
cameraZoom * (event.deltaY > 0 ? 0.92 : 1.08),
0.76,
1.38
);
updateCamera();
},
{ passive: false }
);
$("#camera-reset").addEventListener("click", () => {
cameraAzimuth = 0.66;
cameraElevation = 0.91;
cameraZoom = 1;
updateCamera();
toast("Camera reset.");
});
// -------------------------------------------------------------------------
// Resize and animation loop
// -------------------------------------------------------------------------
function resizeRenderer() {
const width = Math.max(1, canvasWrap.clientWidth);
const height = Math.max(1, canvasWrap.clientHeight);
const aspect = width / height;
renderer.setSize(width, height, false);
const viewHeight = aspect < 1 ? 21 / aspect : 17;
camera.left = (-viewHeight * aspect) / 2;
camera.right = (viewHeight * aspect) / 2;
camera.top = viewHeight / 2;
camera.bottom = -viewHeight / 2;
camera.updateProjectionMatrix();
}
const resizeObserver = new ResizeObserver(resizeRenderer);
resizeObserver.observe(canvasWrap);
resizeRenderer();
let moveAnimation = null;
let playerTargetYaw = 0;
let previousFrame = performance.now();
function lerpAngle(current, target, amount) {
const difference = ((target - current + Math.PI) % (Math.PI * 2) + Math.PI * 2) % (Math.PI * 2) - Math.PI;
return current + difference * amount;
}
function animate(now) {
requestAnimationFrame(animate);
const delta = Math.min(0.05, (now - previousFrame) / 1000);
previousFrame = now;
if (moveAnimation) {
const progress = THREE.MathUtils.clamp(
(now - moveAnimation.start) / moveAnimation.duration,
0,
1
);
const eased = progress < 0.5
? 4 * progress * progress * progress
: 1 - Math.pow(-2 * progress + 2, 3) / 2;
player.position.lerpVectors(moveAnimation.from, moveAnimation.to, eased);
player.position.y = Math.sin(progress * Math.PI) * 0.055;
if (progress >= 1) {
player.position.copy(moveAnimation.to);
moveAnimation = null;
completeMove();
}
}
player.rotation.y = lerpAngle(
player.rotation.y,
playerTargetYaw,
1 - Math.pow(0.0001, delta)
);
keyGroups.forEach((group, index) => {
if (!group.visible) return;
group.position.y = 0.74 + Math.sin(now * 0.0022 + group.userData.phase) * 0.1;
group.userData.gem.rotation.y += delta * 1.3;
group.userData.gem.rotation.x += delta * 0.45;
group.userData.halo.rotation.z += delta * 0.7;
});
portal.rotation.y = Math.sin(now * 0.0005) * 0.13;
portalInnerMaterial.opacity = 0.78 + Math.sin(now * 0.002) * 0.09;
lockDots.forEach((dot, index) => {
dot.material.emissiveIntensity = state.collected.size === 3
? 1.8 + Math.sin(now * 0.004 + index) * 0.5
: 0.25;
});
dust.rotation.y += delta * 0.012;
startPad.material.opacity = 0.5 + Math.sin(now * 0.0024) * 0.16;
if (hintActive && hintMesh) {
hintMesh.material.opacity = 0.52 + Math.sin(now * 0.004) * 0.17;
}
timerEl.textContent = formatTime(currentElapsed(now));
renderer.render(scene, camera);
}
renderControls();
updateObjective();
updateHeading();
requestAnimationFrame(animate);
$("#loading").hidden = true;
</script>
</body>
</html>
```