Prompt specification
Build or customize the Three.js 3D scene "Flooded Toy Village Evacuation Game" inside the active workspace.
Engineering Constraints:
1. Runtime & Orbit: Use Three.js r160 with OrbitControls (damping enabled) and ACESFilmicToneMapping.
2. Frame Timing: Drive all motion strictly with clock.getDelta() so animation speed is FPS-independent.
3. Viewport Hygiene: Handle window resize cleanly, cap DPR at Math.min(window.devicePixelRatio, 2), and dispose geometries/materials/renderer on unmount.
Scene Metadata:
Scene: Flooded Toy Village Evacuation Game
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/flooded-toy-village-evacuation-game-x3563
Scene Description Prompt:
Build a fictional non-graphic evacuation board with safe platforms and limited boats. State all movement and capacity rules and separate it from real emergency guidance. Use Three.js from cdnjs in a single HTML file, with visible voxel blocks.
Working Three.js Starter (flooded-toy-village-evacuation-game-x3563):
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta
name="description"
content="A fictional, non-graphic voxel evacuation logistics puzzle. Not real emergency guidance."
/>
<title>Harbor Rescue — Fictional Voxel Board</title>
<style>
:root {
color-scheme: dark;
--bg: #07151f;
--panel: rgba(9, 25, 36, 0.91);
--panel-strong: rgba(10, 31, 44, 0.97);
--line: rgba(160, 218, 235, 0.18);
--text: #eaf8ff;
--muted: #9bb9c7;
--cyan: #62e8ff;
--blue: #3b8cff;
--yellow: #ffd166;
--green: #61e294;
--orange: #ff9f5b;
--danger: #ff8080;
}
* {
box-sizing: border-box;
}
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
background: var(--bg);
color: var(--text);
font-family:
Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
"Segoe UI", sans-serif;
}
button {
font: inherit;
}
button:focus-visible {
outline: 2px solid var(--cyan);
outline-offset: 2px;
}
#scene {
position: fixed;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
cursor: grab;
}
#scene canvas:active {
cursor: grabbing;
}
.topbar {
position: fixed;
z-index: 20;
top: 14px;
left: 14px;
right: 14px;
min-height: 64px;
display: flex;
align-items: center;
gap: 18px;
padding: 10px 14px;
border: 1px solid var(--line);
border-radius: 16px;
background: rgba(5, 20, 30, 0.86);
box-shadow: 0 16px 50px rgba(0, 0, 0, 0.25);
backdrop-filter: blur(14px);
}
.brand {
display: flex;
align-items: center;
gap: 11px;
min-width: 230px;
}
.brand-mark {
width: 40px;
height: 40px;
display: grid;
place-items: center;
flex: 0 0 auto;
border-radius: 12px;
background: linear-gradient(145deg, var(--cyan), var(--blue));
color: #03111a;
font-weight: 1000;
font-size: 21px;
box-shadow: 0 8px 25px rgba(60, 190, 255, 0.25);
}
.brand h1 {
margin: 0;
font-size: 18px;
line-height: 1.1;
letter-spacing: 0.01em;
}
.brand p {
margin: 4px 0 0;
color: var(--muted);
font-size: 11px;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.objective {
flex: 1;
display: flex;
align-items: center;
justify-content: center;
gap: 12px;
min-width: 0;
}
.objective-copy {
text-align: right;
}
.objective-copy strong {
display: block;
font-size: 14px;
}
.objective-copy span {
color: var(--muted);
font-size: 12px;
}
.progress-shell {
width: min(260px, 28vw);
height: 12px;
overflow: hidden;
border: 1px solid rgba(98, 232, 255, 0.26);
border-radius: 999px;
background: rgba(255, 255, 255, 0.07);
}
#progressBar {
width: 0;
height: 100%;
border-radius: inherit;
background: linear-gradient(90deg, var(--blue), var(--green));
transition: width 300ms ease;
}
.fictional-badge {
flex: 0 0 auto;
padding: 8px 11px;
border: 1px solid rgba(255, 209, 102, 0.36);
border-radius: 999px;
background: rgba(255, 209, 102, 0.1);
color: var(--yellow);
font-size: 11px;
font-weight: 800;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.panel {
position: fixed;
z-index: 10;
top: 94px;
bottom: 16px;
width: 300px;
overflow: auto;
border: 1px solid var(--line);
border-radius: 18px;
background: var(--panel);
box-shadow: 0 22px 65px rgba(0, 0, 0, 0.32);
backdrop-filter: blur(16px);
scrollbar-width: thin;
scrollbar-color: rgba(98, 232, 255, 0.35) transparent;
}
#rules {
left: 14px;
}
#dispatch {
right: 14px;
width: 330px;
}
.panel-section {
padding: 16px;
border-bottom: 1px solid var(--line);
}
.panel-section:last-child {
border-bottom: 0;
}
.eyebrow {
margin: 0 0 5px;
color: var(--cyan);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.14em;
text-transform: uppercase;
}
h2 {
margin: 0 0 10px;
font-size: 16px;
}
h3 {
margin: 0 0 9px;
font-size: 13px;
}
p {
margin: 0;
color: var(--muted);
font-size: 12px;
line-height: 1.5;
}
.disclaimer {
border: 1px solid rgba(255, 209, 102, 0.4);
background:
linear-gradient(
135deg,
rgba(255, 209, 102, 0.13),
rgba(255, 159, 91, 0.07)
);
}
.disclaimer strong {
display: block;
margin-bottom: 6px;
color: var(--yellow);
font-size: 13px;
}
.rules-list {
margin: 0;
padding-left: 19px;
color: #c7dce6;
font-size: 12px;
line-height: 1.5;
}
.rules-list li {
margin: 0 0 9px;
padding-left: 2px;
}
.rules-list li:last-child {
margin-bottom: 0;
}
.capacity-table {
display: grid;
gap: 6px;
}
.capacity-row {
display: flex;
justify-content: space-between;
gap: 12px;
padding: 7px 9px;
border: 1px solid rgba(255, 255, 255, 0.06);
border-radius: 8px;
background: rgba(255, 255, 255, 0.035);
font-size: 11px;
}
.capacity-row span:last-child {
color: var(--muted);
}
.controls-note {
color: #7898a7;
font-size: 11px;
}
.platform-grid,
.boat-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
}
.boat-grid {
grid-template-columns: 1fr 1fr;
}
.choice {
min-height: 51px;
padding: 8px;
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 10px;
background: rgba(255, 255, 255, 0.045);
color: var(--text);
text-align: left;
cursor: pointer;
transition:
border-color 150ms ease,
background 150ms ease,
transform 150ms ease;
}
.choice:hover:not(:disabled) {
border-color: rgba(98, 232, 255, 0.45);
background: rgba(98, 232, 255, 0.08);
transform: translateY(-1px);
}
.choice.active {
border-color: var(--cyan);
background: rgba(98, 232, 255, 0.12);
box-shadow: inset 0 0 0 1px rgba(98, 232, 255, 0.15);
}
.choice:disabled {
opacity: 0.42;
cursor: not-allowed;
}
.choice strong {
display: block;
font-size: 12px;
}
.choice small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 10px;
}
.platform-grid .choice:last-child {
grid-column: 1 / -1;
}
.mini-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
margin-bottom: 8px;
}
.mini-title h3 {
margin: 0;
}
.text-button {
padding: 3px 7px;
border: 1px solid rgba(98, 232, 255, 0.22);
border-radius: 7px;
background: rgba(98, 232, 255, 0.07);
color: var(--cyan);
font-size: 10px;
cursor: pointer;
}
.queue {
display: flex;
flex-wrap: wrap;
gap: 6px;
min-height: 35px;
}
.person {
padding: 6px 8px;
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 8px;
background: rgba(255, 255, 255, 0.05);
color: var(--text);
font-size: 10px;
cursor: pointer;
}
.person.selected {
border-color: var(--yellow);
background: rgba(255, 209, 102, 0.15);
color: #fff2c9;
}
.empty {
width: 100%;
padding: 8px;
color: #6f909f;
font-size: 11px;
font-style: italic;
}
.action-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
margin-top: 9px;
}
.action {
min-height: 39px;
padding: 8px;
border: 1px solid rgba(98, 232, 255, 0.2);
border-radius: 9px;
background: rgba(98, 232, 255, 0.08);
color: var(--cyan);
font-size: 11px;
font-weight: 800;
cursor: pointer;
}
.action.secondary {
border-color: rgba(255, 255, 255, 0.12);
background: rgba(255, 255, 255, 0.05);
color: var(--text);
}
.action.warning {
border-color: rgba(255, 159, 91, 0.25);
background: rgba(255, 159, 91, 0.08);
color: var(--orange);
}
.action:disabled {
opacity: 0.36;
cursor: not-allowed;
transform: none;
}
.destination-list {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 6px;
margin-top: 8px;
}
.destination-list .action {
min-height: 47px;
padding: 6px 4px;
font-size: 10px;
}
.status-line {
padding: 10px;
border: 1px solid rgba(97, 226, 148, 0.24);
border-radius: 9px;
background: rgba(97, 226, 148, 0.07);
color: #baf2ce;
font-size: 11px;
line-height: 1.45;
}
.status-line.complete {
border-color: rgba(255, 209, 102, 0.4);
background: rgba(255, 209, 102, 0.1);
color: #ffe7a6;
}
.log {
display: grid;
gap: 6px;
margin: 0;
padding: 0;
list-style: none;
}
.log li {
padding: 7px 8px;
border-left: 2px solid rgba(98, 232, 255, 0.35);
background: rgba(255, 255, 255, 0.035);
color: #afc8d4;
font-size: 10px;
line-height: 1.4;
}
.log li:first-child {
color: var(--text);
}
#labels {
position: fixed;
z-index: 4;
inset: 0;
overflow: hidden;
pointer-events: none;
}
.scene-label {
position: absolute;
min-width: 112px;
padding: 7px 9px;
border: 1px solid rgba(255, 255, 255, 0.16);
border-radius: 9px;
background: rgba(4, 17, 26, 0.84);
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
color: var(--text);
font-size: 10px;
font-weight: 800;
text-align: center;
pointer-events: auto;
cursor: pointer;
transform: translate(-50%, -50%);
backdrop-filter: blur(8px);
white-space: nowrap;
}
.scene-label small {
display: block;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
font-weight: 600;
}
.scene-label.boat {
border-color: rgba(255, 209, 102, 0.35);
color: #ffe4a0;
}
.scene-label.rescue {
border-color: rgba(97, 226, 148, 0.42);
color: #bdf4d1;
}
.bottom-hint {
position: fixed;
z-index: 8;
left: 50%;
bottom: 17px;
padding: 8px 12px;
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 999px;
background: rgba(4, 17, 26, 0.72);
color: #91adba;
font-size: 10px;
pointer-events: none;
transform: translateX(-50%);
backdrop-filter: blur(8px);
}
@media (max-width: 900px) {
.objective-copy {
display: none;
}
.objective {
justify-content: flex-start;
}
.progress-shell {
width: min(260px, 40vw);
}
.panel {
width: 270px;
}
#dispatch {
width: 300px;
}
}
@media (max-width: 680px) {
.topbar {
top: 8px;
left: 8px;
right: 8px;
min-height: 55px;
padding: 8px 10px;
}
.brand {
min-width: 0;
}
.brand-mark {
width: 34px;
height: 34px;
border-radius: 10px;
}
.brand h1 {
font-size: 14px;
}
.brand p {
display: none;
}
.objective {
display: none;
}
.fictional-badge {
margin-left: auto;
font-size: 9px;
}
#rules {
top: auto;
left: 8px;
bottom: 8px;
width: calc(100% - 16px);
max-height: 31vh;
}
#dispatch {
top: 72px;
right: 8px;
width: min(292px, calc(100% - 16px));
max-height: 49vh;
}
.bottom-hint {
display: none;
}
}
</style>
</head>
<body>
<main id="scene" aria-label="Interactive fictional voxel harbor board"></main>
<div id="labels" aria-hidden="false"></div>
<header class="topbar">
<div class="brand">
<div class="brand-mark" aria-hidden="true">H</div>
<div>
<h1>Harbor Rescue</h1>
<p>Fictional voxel logistics board</p>
</div>
</div>
<div class="objective">
<div class="objective-copy">
<strong>Rescue Dock progress</strong>
<span id="progressText">0 of 8 travelers</span>
</div>
<div
class="progress-shell"
role="progressbar"
aria-label="Travelers at Rescue Dock"
aria-valuemin="0"
aria-valuemax="8"
aria-valuenow="0"
id="progressShell"
>
<div id="progressBar"></div>
</div>
</div>
<div class="fictional-badge">Simulation only</div>
</header>
<aside id="rules" class="panel" aria-label="Exercise rules and disclaimer">
<section class="panel-section disclaimer">
<p class="eyebrow">Not emergency guidance</p>
<strong>This is a fictional board game.</strong>
<p>
It does not model fire, smoke, structural failure, currents, weather,
accessibility, medical needs, or official procedures. Never use it for
real-life emergency decisions. In a real emergency, follow local
authorities and qualified vessel operators.
</p>
</section>
<section class="panel-section">
<p class="eyebrow">Objective</p>
<h2>Move all eight travelers to Rescue Dock</h2>
<p>
West Quay begins with five travelers and East Quay with three. Use the
two boats and the marked channels to transfer everyone safely.
</p>
</section>
<section class="panel-section">
<p class="eyebrow">Movement rules</p>
<ol class="rules-list">
<li>
A boat may board only while it is docked at the same platform as
the selected travelers.
</li>
<li>
Each “Sail” command moves one boat to one other berth along the
marked channel. Boats cannot board, unload, or change destination
during a trip.
</li>
<li>
A boat may unload only at its current berth. It can return and be
reused after unloading.
</li>
<li>
Travel is between West Quay, East Quay, and Rescue Dock only. No
off-route or mid-channel stops are allowed.
</li>
</ol>
</section>
<section class="panel-section">
<p class="eyebrow">Capacity rules</p>
<div class="capacity-table">
<div class="capacity-row">
<strong>West Quay</strong><span>Maximum 5</span>
</div>
<div class="capacity-row">
<strong>East Quay</strong><span>Maximum 3</span>
</div>
<div class="capacity-row">
<strong>Rescue Dock</strong><span>Maximum 8</span>
</div>
<div class="capacity-row">
<strong>Boat 1 and Boat 2</strong><span>Maximum 4 each</span>
</div>
<div class="capacity-row">
<strong>Combined fleet</strong><span>Maximum 8 aboard</span>
</div>
</div>
<p style="margin-top: 9px">
Unloading is blocked if it would exceed a platform’s capacity.
</p>
</section>
<section class="panel-section">
<p class="eyebrow">Board controls</p>
<p class="controls-note">
Drag the 3D scene to orbit. Use the mouse wheel to zoom. Double-click
the scene to reset the camera. Platform and boat cards can also be
selected by clicking their labels in the scene.
</p>
</section>
</aside>
<aside id="dispatch" class="panel" aria-label="Dispatch controls">
<section class="panel-section">
<p class="eyebrow">Dispatch</p>
<h2>Choose a platform</h2>
<div id="platformGrid" class="platform-grid"></div>
</section>
<section class="panel-section">
<p class="eyebrow">Active vessel</p>
<h2>Choose a boat</h2>
<div id="boatGrid" class="boat-grid"></div>
</section>
<section class="panel-section">
<div class="mini-title">
<h3 id="queueTitle">Travelers at West Quay</h3>
<button id="selectAll" class="text-button" type="button">
Select all
</button>
</div>
<div id="passengerQueue" class="queue"></div>
<div class="action-grid">
<button id="boardButton" class="action" type="button">
Board selected
</button>
<button id="unloadButton" class="action secondary" type="button">
Unload all
</button>
</div>
</section>
<section class="panel-section">
<p class="eyebrow">Move active boat</p>
<h2>Sail to a marked berth</h2>
<div id="destinationList" class="destination-list"></div>
</section>
<section class="panel-section">
<div id="statusLine" class="status-line" aria-live="polite">
Select travelers and board them when the active boat is at the same
platform.
</div>
</section>
<section class="panel-section">
<div class="mini-title">
<h3>Dispatch log</h3>
<button id="resetButton" class="text-button" type="button">
Reset board
</button>
</div>
<ul id="log" class="log" aria-live="polite"></ul>
</section>
</aside>
<div class="bottom-hint">Drag to orbit · wheel to zoom · click labels to select</div>
<script type="module">
import * as THREE from
"https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const sceneHost = document.querySelector("#scene");
const labelLayer = document.querySelector("#labels");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0x071923);
scene.fog = new THREE.Fog(0x071923, 25, 55);
const camera = new THREE.PerspectiveCamera(
43,
window.innerWidth / window.innerHeight,
0.1,
100
);
const renderer = new THREE.WebGLRenderer({ antialias: true });
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;
sceneHost.appendChild(renderer.domElement);
const hemisphere = new THREE.HemisphereLight(0xb9eeff, 0x123342, 2.05);
scene.add(hemisphere);
const sun = new THREE.DirectionalLight(0xfff1d0, 3.1);
sun.position.set(-11, 20, 9);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -24;
sun.shadow.camera.right = 24;
sun.shadow.camera.top = 24;
sun.shadow.camera.bottom = -24;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 55;
sun.shadow.normalBias = 0.025;
scene.add(sun);
const rimLight = new THREE.DirectionalLight(0x44c8ff, 1.15);
rimLight.position.set(15, 7, -14);
scene.add(rimLight);
const materials = {
waterA: new THREE.MeshStandardMaterial({
color: 0x0e526c,
roughness: 0.78,
metalness: 0.08
}),
waterB: new THREE.MeshStandardMaterial({
color: 0x0d607d,
roughness: 0.72,
metalness: 0.1
}),
west: new THREE.MeshStandardMaterial({
color: 0x4187a2,
roughness: 0.76
}),
westTop: new THREE.MeshStandardMaterial({
color: 0x70b8cc,
roughness: 0.72
}),
east: new THREE.MeshStandardMaterial({
color: 0x647ca8,
roughness: 0.75
}),
eastTop: new THREE.MeshStandardMaterial({
color: 0x91a9d1,
roughness: 0.72
}),
rescue: new THREE.MeshStandardMaterial({
color: 0x32906e,
roughness: 0.72
}),
rescueTop: new THREE.MeshStandardMaterial({
color: 0x62c68d,
roughness: 0.7
}),
hull: new THREE.MeshStandardMaterial({
color: 0xf0a33b,
roughness: 0.62,
metalness: 0.08
}),
hullLight: new THREE.MeshStandardMaterial({
color: 0xffd06d,
roughness: 0.65
}),
dark: new THREE.MeshStandardMaterial({
color: 0x132b37,
roughness: 0.8
}),
route: new THREE.MeshStandardMaterial({
color: 0x63e8ff,
emissive: 0x1d92b5,
emissiveIntensity: 0.75,
roughness: 0.38
}),
land: new THREE.MeshStandardMaterial({
color: 0x29464d,
roughness: 0.94
}),
buildingA: new THREE.MeshStandardMaterial({
color: 0x34596c,
roughness: 0.85
}),
buildingB: new THREE.MeshStandardMaterial({
color: 0x455c78,
roughness: 0.85
}),
window: new THREE.MeshStandardMaterial({
color: 0xffd67a,
emissive: 0x9c571c,
emissiveIntensity: 0.45,
roughness: 0.5
}),
skin: new THREE.MeshStandardMaterial({
color: 0xffd1ad,
roughness: 0.9
}),
trousers: new THREE.MeshStandardMaterial({
color: 0x253b55,
roughness: 0.9
})
};
const personColors = [
0xef6f6c,
0xffbd59,
0x5ad1a1,
0x8b8cf0,
0xee8fc0,
0x55b8e8,
0xe5df74,
0xff9655
];
const platformInfo = {
west: {
id: "west",
name: "West Quay",
shortName: "West",
capacity: 5,
center: new THREE.Vector3(-8, 0, -4.2),
berth: new THREE.Vector3(-8, -0.48, -1.25),
deck: { cols: 5, rows: 3 },
material: materials.west,
topMaterial: materials.westTop
},
east: {
id: "east",
name: "East Quay",
shortName: "East",
capacity: 3,
center: new THREE.Vector3(8, 0, -4.2),
berth: new THREE.Vector3(8, -0.48, -1.25),
deck: { cols: 4, rows: 3 },
material: materials.east,
topMaterial: materials.eastTop
},
rescue: {
id: "rescue",
name: "Rescue Dock",
shortName: "Rescue",
capacity: 8,
center: new THREE.Vector3(0, 0, 9),
berth: new THREE.Vector3(0, -0.48, 6.15),
deck: { cols: 6, rows: 4 },
material: materials.rescue,
topMaterial: materials.rescueTop
}
};
const boatInfo = {
b1: { id: "b1", name: "Boat 1", capacity: 4 },
b2: { id: "b2", name: "Boat 2", capacity: 4 }
};
const state = {
platforms: {
west: { people: [] },
east: { people: [] },
rescue: { people: [] }
},
boats: {
b1: { at: "west", people: [] },
b2: { at: "east", people: [] }
},
people: new Map()
};
let selectedPlatform = "west";
let selectedBoat = "b1";
let selectedPeople = new Set();
let sailAnimation = null;
let completed = false;
const visual = {
platforms: {},
boats: {},
labels: []
};
const cubeGeometry = new THREE.BoxGeometry(1, 1, 1);
function makeCube(material, size, position, parent, castShadow = true) {
const mesh = new THREE.Mesh(cubeGeometry, material);
mesh.scale.set(size.x, size.y, size.z);
mesh.position.copy(position);
mesh.castShadow = castShadow;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function createWaterTiles() {
const tileSize = 1.25;
const cols = 25;
const rows = 22;
const offsetX = -15;
const offsetZ = -10;
const matricesA = [];
const matricesB = [];
const matrix = new THREE.Matrix4();
for (let x = 0; x < cols; x++) {
for (let z = 0; z < rows; z++) {
const px = offsetX + x * tileSize;
const pz = offsetZ + z * tileSize;
matrix.makeTranslation(px, -0.87, pz);
if ((x + z) % 3 === 0) {
matricesB.push(matrix.clone());
} else {
matricesA.push(matrix.clone());
}
}
}
const createInstances = (matrices, material) => {
const mesh = new THREE.InstancedMesh(
cubeGeometry,
material,
matrices.length
);
matrices.forEach((item, index) => mesh.setMatrixAt(index, item));
mesh.instanceMatrix.needsUpdate = true;
mesh.receiveShadow = true;
scene.add(mesh);
};
createInstances(matricesA, materials.waterA);
createInstances(matricesB, materials.waterB);
}
function createPlatform(info) {
const group = new THREE.Group();
group.position.copy(info.center);
group.userData.selectType = "platform";
group.userData.selectId = info.id;
scene.add(group);
const spacing = 0.95;
const width = info.deck.cols * spacing;
const depth = info.deck.rows * spacing;
for (let x = 0; x < info.deck.cols; x++) {
for (let z = 0; z < info.deck.rows; z++) {
const px = (x - (info.deck.cols - 1) / 2) * spacing;
const pz = (z - (info.deck.rows - 1) / 2) * spacing;
makeCube(
info.material,
new THREE.Vector3(spacing, 0.4, spacing),
new THREE.Vector3(px, 0, pz),
group
);
makeCube(
info.topMaterial,
new THREE.Vector3(spacing * 0.84, 0.08, spacing * 0.84),
new THREE.Vector3(px, 0.24, pz),
group,
false
);
}
}
for (const x of [-width * 0.38, width * 0.38]) {
for (const z of [-depth * 0.34, depth * 0.34]) {
makeCube(
materials.dark,
new THREE.Vector3(0.28, 1.4, 0.28),
new THREE.Vector3(x, -0.75, z),
group
);
}
}
const railMaterial = info.id === "rescue"
? materials.rescueTop
: info.topMaterial;
for (const x of [-width / 2 + 0.18, width / 2 - 0.18]) {
makeCube(
railMaterial,
new THREE.Vector3(0.13, 0.16, depth * 0.82),
new THREE.Vector3(x, 0.58, 0),
group
);
}
const label = document.createElement("button");
label.className = `scene-label${info.id === "rescue" ? " rescue" : ""}`;
label.type = "button";
label.addEventListener("click", () => {
selectedPlatform = info.id;
selectedPeople.clear();
renderUI();
});
labelLayer.appendChild(label);
visual.platforms[info.id] = {
group,
label,
anchor: info.center.clone().add(new THREE.Vector3(0, 2.05, 0))
};
}
function createBoat(info) {
const group = new THREE.Group();
group.userData.selectType = "boat";
group.userData.selectId = info.id;
scene.add(group);
const hullTiles = [
[0, -0.82],
[-0.58, -0.28],
[0.58, -0.28],
[-0.58, 0.28],
[0.58, 0.28],
[0, 0.78]
];
for (const [x, z] of hullTiles) {
makeCube(
materials.hull,
new THREE.Vector3(0.68, 0.3, 0.72),
new THREE.Vector3(x, 0, z),
group
);
}
makeCube(
materials.hullLight,
new THREE.Vector3(1.35, 0.12, 1.6),
new THREE.Vector3(0, 0.19, -0.1),
group,
false
);
makeCube(
materials.dark,
new THREE.Vector3(0.58, 0.36, 0.58),
new THREE.Vector3(0, 0.37, 0.55),
group
);
makeCube(
materials.route,
new THREE.Vector3(0.08, 0.66, 0.08),
new THREE.Vector3(0.42, 0.4, 0.55),
group,
false
);
makeCube(
materials.hullLight,
new THREE.Vector3(0.28, 0.16, 0.08),
new THREE.Vector3(0.58, 0.68, 0.55),
group,
false
);
const label = document.createElement("button");
label.className = "scene-label boat";
label.type = "button";
label.addEventListener("click", () => {
selectedBoat = info.id;
renderUI();
});
labelLayer.appendChild(label);
visual.boats[info.id] = {
group,
label,
anchor: new THREE.Vector3()
};
}
function createDecorativeIsland(x, z, width, depth) {
const group = new THREE.Group();
group.position.set(x, -0.45, z);
scene.add(group);
for (let ix = 0; ix < width; ix++) {
for (let iz = 0; iz < depth; iz++) {
makeCube(
materials.land,
new THREE.Vector3(0.95, 0.55, 0.95),
new THREE.Vector3(
(ix - (width - 1) / 2) * 0.96,
0,
(iz - (depth - 1) / 2) * 0.96
),
group
);
}
}
}
function createBuilding(x, z, width, height, depth, material) {
const group = new THREE.Group();
group.position.set(x, 0, z);
scene.add(group);
const levels = Math.max(1, Math.floor(height / 1.15));
for (let level = 0; level < levels; level++) {
makeCube(
material,
new THREE.Vector3(width, 1.05, depth),
new THREE.Vector3(0, 0.45 + level * 1.02, 0),
group
);
const windowCount = Math.max(1, Math.floor(width / 1.25));
for (let w = 0; w < windowCount; w++) {
makeCube(
materials.window,
new THREE.Vector3(0.25, 0.25, 0.06),
new THREE.Vector3(
(w - (windowCount - 1) / 2) * 0.75,
0.56 + level * 1.02,
depth / 2 + 0.035
),
group,
false
);
}
}
}
createWaterTiles();
Object.values(platformInfo).forEach(createPlatform);
Object.values(boatInfo).forEach(createBoat);
createDecorativeIsland(-13, 8, 4, 4);
createDecorativeIsland(13, 8, 4, 4);
createDecorativeIsland(-13, -11, 3, 3);
createDecorativeIsland(13, -11, 3, 3);
createBuilding(-13.5, 8, 2.2, 4.8, 2.2, materials.buildingA);
createBuilding(-11.9, 7.2, 1.7, 3.5, 1.8, materials.buildingB);
createBuilding(12.2, 8.2, 2.4, 5.6, 2.3, materials.buildingB);
createBuilding(14, 7.3, 1.5, 3.3, 1.7, materials.buildingA);
createBuilding(-13.2, -11, 2.1, 3.7, 2.1, materials.buildingA);
createBuilding(13.1, -11, 2.4, 4.5, 2.2, materials.buildingB);
function getRoutePoints(from, to) {
const west = platformInfo.west.berth.clone();
const east = platformInfo.east.berth.clone();
const rescue = platformInfo.rescue.berth.clone();
const middle = (a, b, z, spread = 0) =>
new THREE.Vector3(
THREE.MathUtils.lerp(a.x, b.x, 0.5),
-0.48,
z
);
let points;
if (from === "west" && to === "east") {
points = [
west,
new THREE.Vector3(-4.7, -0.48, 0.2),
new THREE.Vector3(0, -0.48, 2.6),
new THREE.Vector3(4.7, -0.48, 0.2),
east
];
} else if (from === "east" && to === "west") {
points = [
east,
new THREE.Vector3(4.7, -0.48, 0.2),
new THREE.Vector3(0, -0.48, 2.6),
new THREE.Vector3(-4.7, -0.48, 0.2),
west
];
} else if (from === "west" && to === "rescue") {
points = [
west,
new THREE.Vector3(-5.2, -0.48, 1.1),
new THREE.Vector3(0, -0.48, 4.8),
rescue
];
} else if (from === "rescue" && to === "west") {
points = [
rescue,
new THREE.Vector3(0, -0.48, 4.8),
new THREE.Vector3(-5.2, -0.48, 1.1),
west
];
} else if (from === "east" && to === "rescue") {
points = [
east,
new THREE.Vector3(5.2, -0.48, 1.1),
new THREE.Vector3(0, -0.48, 4.8),
rescue
];
} else {
points = [
rescue,
new THREE.Vector3(0, -0.48, 4.8),
new THREE.Vector3(5.2, -0.48, 1.1),
east
];
}
return points;
}
function createRouteMarkers() {
const routes = [
["west", "east"],
["west", "rescue"],
["east", "rescue"]
];
const markerGeometry = new THREE.BoxGeometry(0.16, 0.08, 0.16);
for (const [from, to] of routes) {
const points = getRoutePoints(from, to);
for (let i = 0; i < points.length - 1; i++) {
const a = points[i];
const b = points[i + 1];
const distance = a.distanceTo(b);
const count = Math.max(2, Math.floor(distance / 0.85));
for (let j = 1; j < count; j++) {
const point = a.clone().lerp(b, j / count);
point.y = -0.62;
const marker = new THREE.Mesh(markerGeometry, materials.route);
marker.position.copy(point);
marker.rotation.y = Math.PI / 4;
scene.add(marker);
}
}
}
}
createRouteMarkers();
function createPersonVisual(id, colorIndex) {
const group = new THREE.Group();
const shirt = new THREE.MeshStandardMaterial({
color: personColors[colorIndex % personColors.length],
roughness: 0.82
});
makeCube(
shirt,
new THREE.Vector3(0.23, 0.38, 0.18),
new THREE.Vector3(0, 0.23, 0),
group
);
makeCube(
materials.skin,
new THREE.Vector3(0.19, 0.19, 0.19),
new THREE.Vector3(0, 0.51, 0),
group
);
makeCube(
materials.trousers,
new THREE.Vector3(0.09, 0.24, 0.1),
new THREE.Vector3(-0.07, -0.04, 0),
group
);
makeCube(
materials.trousers,
new THREE.Vector3(0.09, 0.24, 0.1),
new THREE.Vector3(0.07, -0.04, 0),
group
);
group.userData.selectType = "platform";
group.userData.personId = id;
return group;
}
function layoutPlatformPeople(platformId) {
const people = state.platforms[platformId].people;
const info = platformInfo[platformId];
const group = visual.platforms[platformId].group;
people.forEach((id, index) => {
const person = state.people.get(id);
const cols = Math.min(info.deck.cols, Math.max(1, people.length));
const row = Math.floor(index / cols);
const col = index % cols;
const rowCount = Math.min(
info.deck.rows,
Math.ceil(people.length / cols)
);
const spacing = info.id === "rescue" ? 0.78 : 0.72;
person.group.position.set(
(col - (cols - 1) / 2) * spacing,
0.29,
(row - (rowCount - 1) / 2) * 0.82
);
});
}
function layoutBoatPeople(boatId) {
const people = state.boats[boatId].people;
const slots = [
[-0.43, -0.42],
[0.43, -0.42],
[-0.43, 0.02],
[0.43, 0.02]
];
people.forEach((id, index) => {
const person = state.people.get(id);
const slot = slots[index] || slots[slots.length - 1];
person.group.position.set(slot[0], 0.28, slot[1]);
});
}
function resetGame() {
for (const person of state.people.values()) {
person.group.removeFromParent();
}
state.people.clear();
state.platforms.west.people = [];
state.platforms.east.people = [];
state.platforms.rescue.people = [];
state.boats.b1.people = [];
state.boats.b2.people = [];
state.boats.b1.at = "west";
state.boats.b2.at = "east";
const ids = Array.from({ length: 8 }, (_, index) => `T${index + 1}`);
ids.slice(0, 5).forEach((id) => state.platforms.west.people.push(id));
ids.slice(5).forEach((id) => state.platforms.east.people.push(id));
ids.forEach((id, index) => {
const group = createPersonVisual(id, index);
const owner = index < 5 ? "west" : "east";
visual.platforms[owner].group.add(group);
state.people.set(id, { group });
});
visual.boats.b1.group.position.copy(platformInfo.west.berth);
visual.boats.b2.group.position.copy(platformInfo.east.berth);
visual.boats.b1.group.rotation.set(0, 0, 0);
visual.boats.b2.group.rotation.set(0, 0, 0);
layoutPlatformPeople("west");
layoutPlatformPeople("east");
layoutPlatformPeople("rescue");
selectedPlatform = "west";
selectedBoat = "b1";
selectedPeople.clear();
sailAnimation = null;
completed = false;
document.querySelector("#log").innerHTML = "";
log("Board reset. Two boats are ready at the quays.");
renderUI();
}
function log(message) {
const list = document.querySelector("#log");
const item = document.createElement("li");
item.textContent = message;
list.prepend(item);
while (list.children.length > 5) {
list.lastElementChild.remove();
}
}
function updateStatus(message, complete = false) {
const element = document.querySelector("#statusLine");
element.textContent = message;
element.classList.toggle("complete", complete);
}
function checkCompletion() {
const count = state.platforms.rescue.people.length;
if (count === 8 && !completed) {
completed = true;
updateStatus(
"Exercise complete: all eight fictional travelers are safely at Rescue Dock.",
true
);
log("Objective complete. All eight travelers reached Rescue Dock.");
}
}
function renderUI() {
const platformGrid = document.querySelector("#platformGrid");
platformGrid.innerHTML = "";
for (const info of Object.values(platformInfo)) {
const count = state.platforms[info.id].people.length;
const button = document.createElement("button");
button.type = "button";
button.className = `choice${selectedPlatform === info.id ? " active" : ""}`;
button.innerHTML = `
<strong>${info.name}</strong>
<small>${count} / ${info.capacity} present</small>
`;
button.addEventListener("click", () => {
selectedPlatform = info.id;
selectedPeople.clear();
renderUI();
});
platformGrid.appendChild(button);
}
const boatGrid = document.querySelector("#boatGrid");
boatGrid.innerHTML = "";
for (const info of Object.values(boatInfo)) {
const boat = state.boats[info.id];
const button = document.createElement("button");
button.type = "button";
button.className = `choice${selectedBoat === info.id ? " active" : ""}`;
button.innerHTML = `
<strong>${info.name}</strong>
<small>${boat.people.length} / ${info.capacity} aboard · ${
sailAnimation?.boatId === info.id ? "sailing" : platformInfo[boat.at].shortName
}</small>
`;
button.addEventListener("click", () => {
selectedBoat = info.id;
renderUI();
});
boatGrid.appendChild(button);
}
const queue = document.querySelector("#passengerQueue");
queue.innerHTML = "";
const people = state.platforms[selectedPlatform].people;
document.querySelector("#queueTitle").textContent =
`Travelers at ${platformInfo[selectedPlatform].name}`;
if (people.length === 0) {
const empty = document.createElement("span");
empty.className = "empty";
empty.textContent = "No travelers remain here.";
queue.appendChild(empty);
} else {
for (const id of people) {
const button = document.createElement("button");
button.type = "button";
button.className = `person${selectedPeople.has(id) ? " selected" : ""}`;
button.textContent = id;
button.setAttribute(
"aria-pressed",
selectedPeople.has(id) ? "true" : "false"
);
button.addEventListener("click", () => {
if (selectedPeople.has(id)) {
selectedPeople.delete(id);
} else {
selectedPeople.add(id);
}
renderUI();
});
queue.appendChild(button);
}
}
const activeBoat = state.boats[selectedBoat];
const boatCapacity = boatInfo[selectedBoat].capacity;
const boatIsHere = activeBoat.at === selectedPlatform;
const roomOnBoard = boatCapacity - activeBoat.people.length;
const selectedHere = [...selectedPeople].filter((id) =>
people.includes(id)
);
const boardButton = document.querySelector("#boardButton");
boardButton.disabled =
!!sailAnimation ||
!boatIsHere ||
selectedHere.length === 0 ||
selectedHere.length > roomOnBoard;
const unloadButton = document.querySelector("#unloadButton");
const unloadTarget = platformInfo[activeBoat.at];
const unloadCount = activeBoat.people.length;
unloadButton.disabled =
!!sailAnimation ||
unloadCount === 0 ||
state.platforms[activeBoat.at].people.length + unloadCount >
unloadTarget.capacity;
const destinationList = document.querySelector("#destinationList");
destinationList.innerHTML = "";
for (const info of Object.values(platformInfo)) {
const button = document.createElement("button");
button.type = "button";
button.className = "action secondary";
button.textContent = info.shortName;
button.disabled =
!!sailAnimation || activeBoat.at === info.id;
button.addEventListener("click", () => {
sailBoat(info.id);
});
destinationList.appendChild(button);
}
const rescued = state.platforms.rescue.people.length;
const progressBar = document.querySelector("#progressBar");
const progressText = document.querySelector("#progressText");
const progressShell = document.querySelector("#progressShell");
progressBar.style.width = `${(rescued / 8) * 100}%`;
progressText.textContent = `${rescued} of 8 travelers`;
progressShell.setAttribute("aria-valuenow", String(rescued));
for (const info of Object.values(platformInfo)) {
const count = state.platforms[info.id].people.length;
const label = visual.platforms[info.id].label;
label.innerHTML = `${info.name}<small>${count} / ${info.capacity} present</small>`;
}
for (const info of Object.values(boatInfo)) {
const boat = state.boats[info.id];
const label = visual.boats[info.id].label;
label.innerHTML = `${info.name}<small>${boat.people.length} / ${info.capacity} aboard</small>`;
}
if (!completed) {
if (sailAnimation) {
updateStatus(
`${boatInfo[sailAnimation.boatId].name} is sailing along the marked channel.`
);
} else if (!boatIsHere) {
updateStatus(
`${boatInfo[selectedBoat].name} is at ${platformInfo[activeBoat.at].name}. Sail it to ${platformInfo[selectedPlatform].name} before boarding.`
);
} else if (selectedHere.length > roomOnBoard) {
updateStatus(
`${boatInfo[selectedBoat].name} has room for only ${roomOnBoard} more traveler(s).`
);
} else {
updateStatus(
`${boatInfo[selectedBoat].name} is docked at ${platformInfo[selectedPlatform].name}. Select travelers, then board them.`
);
}
}
}
function boardSelected() {
if (sailAnimation) return;
const boat = state.boats[selectedBoat];
if (boat.at !== selectedPlatform) {
updateStatus("Boarding is blocked: the boat must be at this platform.");
return;
}
const ids = state.platforms[selectedPlatform].people.filter((id) =>
selectedPeople.has(id)
);
if (ids.length === 0) return;
if (ids.length > boatInfo[selectedBoat].capacity - boat.people.length) {
updateStatus("Boarding is blocked by the boat's capacity.");
return;
}
for (const id of ids) {
state.platforms[selectedPlatform].people =
state.platforms[selectedPlatform].people.filter((personId) => personId !== id);
boat.people.push(id);
const person = state.people.get(id);
visual.boats[selectedBoat].group.add(person.group);
person.group.userData.selectType = "boat";
person.group.userData.selectId = selectedBoat;
}
layoutPlatformPeople(selectedPlatform);
layoutBoatPeople(selectedBoat);
selectedPeople.clear();
log(
`${boatInfo[selectedBoat].name} boarded ${ids.length} traveler(s) at ${platformInfo[selectedPlatform].name}.`
);
renderUI();
checkCompletion();
}
function unloadAll() {
if (sailAnimation) return;
const boat = state.boats[selectedBoat];
const target = boat.at;
if (boat.people.length === 0) return;
if (
state.platforms[target].people.length + boat.people.length >
platformInfo[target].capacity
) {
updateStatus("Unloading is blocked: it would exceed platform capacity.");
return;
}
const count = boat.people.length;
for (const id of boat.people) {
const person = state.people.get(id);
visual.platforms[target].group.add(person.group);
person.group.userData.selectType = "platform";
person.group.userData.selectId = target;
state.platforms[target].people.push(id);
}
boat.people = [];
layoutPlatformPeople(target);
log(
`${boatInfo[selectedBoat].name} unloaded ${count} traveler(s) at ${platformInfo[target].name}.`
);
renderUI();
checkCompletion();
}
function sailBoat(destination) {
if (sailAnimation) return;
const boat = state.boats[selectedBoat];
if (boat.at === destination) return;
const points = getRoutePoints(boat.at, destination);
const distances = [];
let totalDistance = 0;
for (let i = 0; i < points.length - 1; i++) {
const distance = points[i].distanceTo(points[i + 1]);
distances.push(distance);
totalDistance += distance;
}
sailAnimation = {
boatId: selectedBoat,
from: boat.at,
to: destination,
points,
distances,
totalDistance,
startedAt: performance.now(),
duration: Math.max(1800, totalDistance * 240)
};
log(
`${boatInfo[selectedBoat].name} is sailing from ${platformInfo[boat.at].name} to ${platformInfo[destination].name}.`
);
renderUI();
}
function updateSailAnimation(time) {
if (!sailAnimation) return;
const animation = sailAnimation;
const boat = state.boats[animation.boatId];
const group = visual.boats[animation.boatId].group;
const raw = Math.min(
1,
Math.max(0, (time - animation.startedAt) / animation.duration)
);
const eased =
raw < 0.5
? 2 * raw * raw
: 1 - Math.pow(-2 * raw + 2, 2) / 2;
let remaining = eased * animation.totalDistance;
let segment = 0;
while (
segment < animation.distances.length - 1 &&
remaining > animation.distances[segment]
) {
remaining -= animation.distances[segment];
segment++;
}
const start = animation.points[segment];
const end = animation.points[segment + 1];
const segmentProgress =
animation.distances[segment] === 0
? 1
: remaining / animation.distances[segment];
group.position.lerpVectors(start, end, segmentProgress);
const direction = end.clone().sub(start);
if (direction.lengthSq() > 0.0001) {
group.rotation.y = Math.atan2(direction.x, direction.z);
}
if (raw >= 1) {
boat.at = animation.to;
group.position.copy(platformInfo[boat.at].berth);
log(
`${boatInfo[animation.boatId].name} docked at ${platformInfo[boat.at].name}.`
);
sailAnimation = null;
renderUI();
}
}
document.querySelector("#boardButton").addEventListener("click", boardSelected);
document.querySelector("#unloadButton").addEventListener("click", unloadAll);
document.querySelector("#resetButton").addEventListener("click", resetGame);
document.querySelector("#selectAll").addEventListener("click", () => {
selectedPeople = new Set(state.platforms[selectedPlatform].people);
renderUI();
});
// Camera controls are implemented directly, without camera-control addons.
const cameraTarget = new THREE.Vector3(0, 0.6, 2.2);
let cameraRadius = 29;
let cameraAzimuth = 0.34;
let cameraPolar = 0.91;
let dragging = false;
let pointerMoved = false;
let lastPointerX = 0;
let lastPointerY = 0;
function updateCamera() {
camera.position.set(
cameraTarget.x +
cameraRadius *
Math.sin(cameraPolar) *
Math.sin(cameraAzimuth),
cameraTarget.y + cameraRadius * Math.cos(cameraPolar),
cameraTarget.z +
cameraRadius *
Math.sin(cameraPolar) *
Math.cos(cameraAzimuth)
);
camera.lookAt(cameraTarget);
}
function resetCamera() {
cameraRadius = 29;
cameraAzimuth = 0.34;
cameraPolar = 0.91;
updateCamera();
}
renderer.domElement.addEventListener("pointerdown", (event) => {
if (event.button !== 0) return;
dragging = true;
pointerMoved = false;
lastPointerX = event.clientX;
lastPointerY = event.clientY;
renderer.domElement.setPointerCapture(event.pointerId);
});
renderer.domElement.addEventListener("pointermove", (event) => {
if (!dragging) return;
const dx = event.clientX - lastPointerX;
const dy = event.clientY - lastPointerY;
if (Math.hypot(dx, dy) > 2) {
pointerMoved = true;
}
cameraAzimuth -= dx * 0.006;
cameraPolar = THREE.MathUtils.clamp(
cameraPolar + dy * 0.005,
0.36,
1.34
);
lastPointerX = event.clientX;
lastPointerY = event.clientY;
updateCamera();
});
renderer.domElement.addEventListener("pointerup", (event) => {
dragging = false;
if (!pointerMoved) {
selectFromScene(event);
}
});
renderer.domElement.addEventListener("pointercancel", () => {
dragging = false;
});
renderer.domElement.addEventListener(
"wheel",
(event) => {
event.preventDefault();
cameraRadius = THREE.MathUtils.clamp(
cameraRadius + event.deltaY * 0.018,
17,
44
);
updateCamera();
},
{ passive: false }
);
renderer.domElement.addEventListener("dblclick", resetCamera);
const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();
function selectFromScene(event) {
const rect = renderer.domElement.getBoundingClientRect();
pointer.x =
((event.clientX - rect.left) / rect.width) * 2 - 1;
pointer.y =
-((event.clientY - rect.top) / rect.height) * 2 + 1;
raycaster.setFromCamera(pointer, camera);
const hits = raycaster.intersectObjects(scene.children, true);
for (const hit of hits) {
let object = hit.object;
while (object) {
if (object.userData.selectType === "platform") {
selectedPlatform = object.userData.selectId;
selectedPeople.clear();
renderUI();
return;
}
if (object.userData.selectType === "boat") {
selectedBoat = object.userData.selectId;
renderUI();
return;
}
object = object.parent;
}
}
}
function updateLabels() {
for (const info of Object.values(platformInfo)) {
updateLabel(
visual.platforms[info.id].label,
visual.platforms[info.id].anchor
);
}
for (const info of Object.values(boatInfo)) {
const item = visual.boats[info.id];
item.anchor.copy(item.group.position);
item.anchor.y += 1.35;
updateLabel(item.label, item.anchor);
}
}
function updateLabel(element, worldPosition) {
const projected = worldPosition.clone().project(camera);
const visible =
projected.z > -1 &&
projected.z < 1 &&
projected.x > -1.2 &&
projected.x < 1.2 &&
projected.y > -1.2 &&
projected.y < 1.2;
element.style.display = visible ? "block" : "none";
if (!visible) return;
const x = (projected.x * 0.5 + 0.5) * window.innerWidth;
const y = (-projected.y * 0.5 + 0.5) * window.innerHeight;
element.style.left = `${x}px`;
element.style.top = `${y}px`;
}
window.addEventListener("resize", () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.setSize(window.innerWidth, window.innerHeight);
});
resetCamera();
resetGame();
renderer.setAnimationLoop((time) => {
updateSailAnimation(time);
updateLabels();
renderer.render(scene, camera);
});
</script>
</body>
</html>
```