Prompt specification
Build or customize the Three.js 3D scene "Inclusive Field-Day Game Design" 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: Inclusive Field-Day Game Design
Category: Voxel Worlds · Style: Voxel 3D
License: MIT · Reference: https://three3d.app/scene/inclusive-field-day-game-design-x3647
Scene Description Prompt:
Please create one self-contained HTML file with Three.js from cdnjs showing fair comparisons under explicit game rules. Create an original community game with adjustable launch aids and clearly stated goals. Show which constraints change and avoid claiming that one adjustment makes all participants equivalent. Voxel style.
Working Three.js Starter (inclusive-field-day-game-design-x3647):
```html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Common Skyway — Voxel Parcel Trials</title>
<style>
:root {
--ink: #26343b;
--muted: #647077;
--paper: #f4efe4;
--paper-dark: #e7dece;
--line: #26343b;
--accent: #ed6949;
--accent-dark: #b9432d;
--green: #278a72;
--yellow: #f2c84b;
--blue: #4c8fb7;
--red: #bd4138;
--shadow: 4px 4px 0 rgba(38, 52, 59, 0.18);
}
* { box-sizing: border-box; }
html, body {
margin: 0;
min-height: 100%;
background: var(--paper);
color: var(--ink);
font-family: "Trebuchet MS", "Avenir Next", system-ui, sans-serif;
}
body { overflow: hidden; }
button, input { font: inherit; }
button {
color: inherit;
cursor: pointer;
}
button:focus-visible,
input:focus-visible,
summary:focus-visible {
outline: 3px solid var(--blue);
outline-offset: 2px;
}
#app {
height: 100vh;
display: grid;
grid-template-rows: auto minmax(0, 1fr);
}
header {
min-height: 82px;
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
padding: 12px 18px;
border-bottom: 3px solid var(--line);
background: #fffaf0;
z-index: 5;
}
.brand {
min-width: 250px;
}
.eyebrow {
margin: 0 0 2px;
color: var(--accent-dark);
font-size: 11px;
font-weight: 900;
letter-spacing: 0.15em;
text-transform: uppercase;
}
h1 {
margin: 0;
font-size: clamp(20px, 2.4vw, 31px);
line-height: 1;
letter-spacing: -0.04em;
}
.subtitle {
margin: 5px 0 0;
color: var(--muted);
font-size: 12px;
}
.stats {
display: flex;
flex-wrap: wrap;
justify-content: flex-end;
gap: 8px;
}
.stat {
min-width: 104px;
padding: 8px 11px;
border: 2px solid var(--line);
background: var(--paper);
box-shadow: 2px 2px 0 rgba(38, 52, 59, 0.12);
}
.stat small {
display: block;
margin-bottom: 2px;
color: var(--muted);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.stat strong { font-size: 15px; }
main {
min-height: 0;
display: grid;
grid-template-columns: 316px minmax(360px, 1fr) 342px;
}
aside {
min-height: 0;
overflow: auto;
padding: 12px;
background: var(--paper);
scrollbar-width: thin;
}
aside.left { border-right: 3px solid var(--line); }
aside.right { border-left: 3px solid var(--line); }
#viewport {
position: relative;
min-width: 0;
min-height: 0;
overflow: hidden;
background: #cbdde1;
}
#scene {
position: absolute;
inset: 0;
}
#scene canvas {
display: block;
width: 100%;
height: 100%;
touch-action: none;
}
#labels {
position: absolute;
inset: 0;
pointer-events: none;
overflow: hidden;
}
.world-label {
position: absolute;
left: 0;
top: 0;
transform: translate(-50%, -50%);
min-width: 82px;
padding: 5px 8px;
border: 2px solid var(--line);
background: rgba(255, 250, 240, 0.94);
box-shadow: 2px 2px 0 rgba(38, 52, 59, 0.18);
text-align: center;
white-space: nowrap;
font-size: 11px;
}
.world-label b,
.world-label span { display: block; }
.world-label span {
color: var(--muted);
font-size: 9px;
font-weight: 900;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.world-label.district {
border-width: 3px;
}
.world-label.station {
padding: 4px 7px;
background: rgba(38, 52, 59, 0.9);
color: white;
border-color: rgba(255,255,255,0.4);
}
.world-label.station span { color: #d6e2df; }
.card {
margin-bottom: 12px;
border: 2px solid var(--line);
background: #fffaf0;
box-shadow: var(--shadow);
}
.card > h2,
.card > summary {
margin: 0;
padding: 10px 12px;
border-bottom: 2px solid var(--line);
font-size: 13px;
letter-spacing: 0.04em;
text-transform: uppercase;
}
summary {
cursor: pointer;
list-style: none;
}
summary::-webkit-details-marker { display: none; }
summary::after {
content: "+";
float: right;
font-size: 18px;
line-height: 14px;
}
details[open] summary::after { content: "−"; }
.card-body { padding: 11px 12px 12px; }
.rules {
margin: 0;
padding-left: 18px;
color: #48565b;
font-size: 12px;
line-height: 1.45;
}
.rules li + li { margin-top: 6px; }
.notice {
margin: 10px 0 0;
padding: 9px 10px;
border-left: 4px solid var(--green);
background: #e1f0e7;
color: #31554a;
font-size: 11px;
line-height: 1.4;
}
.section-label {
display: flex;
justify-content: space-between;
align-items: center;
margin: 0 0 8px;
color: var(--muted);
font-size: 10px;
font-weight: 900;
letter-spacing: 0.08em;
text-transform: uppercase;
}
.selection-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
}
.selection-grid.targets {
grid-template-columns: repeat(3, 1fr);
}
.select-button {
position: relative;
min-height: 46px;
padding: 7px 6px;
border: 2px solid var(--line);
background: var(--paper);
font-size: 11px;
font-weight: 900;
line-height: 1.15;
}
.select-button small {
display: block;
margin-top: 3px;
color: var(--muted);
font-size: 9px;
font-weight: 700;
}
.select-button.active {
color: white;
background: var(--ink);
box-shadow: inset 0 -5px 0 rgba(255,255,255,0.14);
}
.select-button.active small { color: #d7e4df; }
.select-button.target.active {
background: var(--target-color, var(--green));
}
.control + .control {
margin-top: 13px;
}
.control-head {
display: flex;
justify-content: space-between;
align-items: baseline;
gap: 8px;
margin-bottom: 5px;
font-size: 12px;
font-weight: 900;
}
output {
min-width: 58px;
padding: 2px 6px;
border: 2px solid var(--line);
background: var(--yellow);
text-align: center;
font-size: 11px;
}
input[type="range"] {
width: 100%;
margin: 0;
accent-color: var(--accent);
cursor: pointer;
}
.range-labels {
display: flex;
justify-content: space-between;
margin-top: 2px;
color: var(--muted);
font-size: 9px;
}
.button-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 7px;
margin-top: 12px;
}
.button {
min-height: 39px;
padding: 8px 9px;
border: 2px solid var(--line);
background: var(--paper);
box-shadow: 2px 2px 0 rgba(38,52,59,0.16);
font-size: 11px;
font-weight: 900;
}
.button:hover:not(:disabled) { transform: translateY(-1px); }
.button:active:not(:disabled) { transform: translate(1px, 1px); }
.button.primary {
color: white;
background: var(--accent);
border-color: var(--accent-dark);
}
.button.green {
color: white;
background: var(--green);
border-color: #1d6958;
}
.button:disabled {
cursor: not-allowed;
opacity: 0.46;
box-shadow: none;
}
#launchButton {
width: 100%;
min-height: 48px;
margin-top: 10px;
font-size: 13px;
}
.micro-status {
min-height: 34px;
margin: 8px 0 0;
color: var(--muted);
font-size: 10px;
line-height: 1.4;
}
.ledger {
display: grid;
gap: 1px;
border: 1px solid #c8bda9;
background: #c8bda9;
}
.ledger-row {
display: grid;
grid-template-columns: 1fr auto 46px;
align-items: center;
gap: 7px;
min-height: 30px;
padding: 5px 7px;
background: #fffaf0;
font-size: 10px;
}
.ledger-row b { font-size: 11px; }
.tag {
padding: 2px 4px;
text-align: center;
font-size: 8px;
font-weight: 900;
letter-spacing: 0.05em;
text-transform: uppercase;
}
.tag.aid { background: #f8df9b; }
.tag.derived { background: #d7e8f1; }
.tag.fixed { background: #e1e5df; }
.compliance {
margin-top: 9px;
padding: 8px;
border: 2px solid var(--line);
font-size: 10px;
line-height: 1.45;
}
.compliance.ok {
background: #e1f0e7;
border-color: var(--green);
}
.compliance.bad {
background: #f5dfd8;
border-color: var(--red);
}
.goal-row {
margin-bottom: 12px;
}
.goal-row:last-child { margin-bottom: 0; }
.goal-head {
display: flex;
justify-content: space-between;
margin-bottom: 5px;
font-size: 11px;
font-weight: 900;
}
.progress {
height: 15px;
padding: 2px;
border: 2px solid var(--line);
background: var(--paper);
}
.progress > div {
height: 100%;
width: 0;
background: var(--district-color);
transition: width 220ms ease;
}
.goal-summary {
margin: 12px 0 0;
padding: 8px;
border: 2px solid var(--line);
background: #f7e9bd;
font-size: 10px;
line-height: 1.4;
}
.audit-table {
width: 100%;
border-collapse: collapse;
font-size: 9px;
}
.audit-table th {
padding: 5px 3px;
border-bottom: 2px solid var(--line);
color: var(--muted);
font-size: 8px;
letter-spacing: 0.03em;
text-align: left;
text-transform: uppercase;
}
.audit-table td {
padding: 7px 3px;
border-bottom: 1px solid #cfc4b1;
vertical-align: top;
line-height: 1.25;
}
.audit-table tr.selected { background: #f7e9bd; }
.good { color: #1d725d; font-weight: 900; }
.bad { color: var(--red); font-weight: 900; }
.fair-note {
margin: 10px 0 0;
padding: 9px;
border: 2px solid var(--line);
background: #e1edf2;
font-size: 10px;
line-height: 1.45;
}
#eventLog {
display: grid;
gap: 6px;
max-height: 225px;
overflow: auto;
}
.log-item {
padding: 7px 8px;
border-left: 4px solid var(--muted);
background: var(--paper);
color: #4c585c;
font-size: 10px;
line-height: 1.4;
}
.log-item.success { border-color: var(--green); }
.log-item.miss { border-color: var(--red); }
.viewport-badge {
position: absolute;
top: 12px;
left: 12px;
max-width: calc(100% - 180px);
padding: 9px 11px;
border: 2px solid var(--line);
background: rgba(255,250,240,0.9);
box-shadow: var(--shadow);
pointer-events: none;
}
.viewport-badge strong { display: block; font-size: 12px; }
.viewport-badge span { color: var(--muted); font-size: 10px; }
.camera-controls {
position: absolute;
right: 12px;
bottom: 12px;
display: grid;
grid-template-columns: repeat(3, 34px);
gap: 5px;
}
.camera-controls button {
width: 34px;
height: 34px;
border: 2px solid var(--line);
background: rgba(255,250,240,0.92);
box-shadow: 2px 2px 0 rgba(38,52,59,0.16);
font-weight: 900;
}
.camera-help {
position: absolute;
left: 12px;
bottom: 12px;
padding: 7px 9px;
border: 2px solid var(--line);
background: rgba(255,250,240,0.88);
color: var(--muted);
font-size: 9px;
pointer-events: none;
}
#endBanner {
position: absolute;
left: 50%;
top: 50%;
width: min(390px, calc(100% - 30px));
padding: 18px;
transform: translate(-50%, -50%) rotate(-1deg);
border: 3px solid var(--line);
background: #fffaf0;
box-shadow: 7px 7px 0 rgba(38,52,59,0.25);
text-align: center;
z-index: 10;
}
#endBanner.hidden { display: none; }
#endBanner h2 { margin: 0 0 7px; font-size: 25px; }
#endBanner p { margin: 0; color: var(--muted); font-size: 12px; }
@media (max-width: 1180px) {
main { grid-template-columns: 292px minmax(360px, 1fr) 310px; }
aside { padding: 9px; }
}
@media (max-width: 920px) {
body { overflow: auto; }
#app { height: auto; min-height: 100vh; }
header { align-items: flex-start; flex-direction: column; }
.stats { justify-content: flex-start; }
main { display: flex; flex-direction: column; }
#viewport { order: -1; height: 58vh; min-height: 420px; }
aside { overflow: visible; }
aside.left { border-right: 0; border-bottom: 3px solid var(--line); }
aside.right { border-left: 0; border-top: 3px solid var(--line); }
}
@media (max-width: 500px) {
.stats { display: grid; grid-template-columns: repeat(2, 1fr); width: 100%; }
.stat { min-width: 0; }
.selection-grid.targets { grid-template-columns: 1fr; }
.camera-help { display: none; }
.viewport-badge { max-width: calc(100% - 100px); }
}
</style>
</head>
<body>
<div id="app">
<header>
<div class="brand">
<p class="eyebrow">A cooperative neighborhood launch game</p>
<h1>COMMON SKYWAY</h1>
<p class="subtitle">Four crews. Three plazas. One shared set of adjustable launch aids.</p>
</div>
<div class="stats" aria-live="polite">
<div class="stat">
<small>Parcels stocked</small>
<strong id="stockStat">0 / 9</strong>
</div>
<div class="stat">
<small>Crew quota</small>
<strong id="quotaStat">0 / 4</strong>
</div>
<div class="stat">
<small>Launches used</small>
<strong id="launchStat">0 / 12</strong>
</div>
<div class="stat">
<small>Lift units left</small>
<strong id="energyStat">620</strong>
</div>
</div>
</header>
<main>
<aside class="left">
<details class="card" open>
<summary>Rules and goal</summary>
<div class="card-body">
<ol class="rules">
<li>Stock <b>3 parcels in each of the 3 plazas</b>: 9 successful deliveries total.</li>
<li><b>Every crew must complete at least one delivery</b> before the community goal is complete.</li>
<li>Use no more than <b>12 launches</b> and <b>620 shared lift units</b>.</li>
<li>A parcel counts only if it lands within <b>3.2 m of the chosen plaza center</b>. There is no nearest-plaza credit.</li>
<li>Air is calm and every shot is deterministic. Gravity is 9.81 m/s².</li>
<li>Switching crews <b>does not reset the aid settings</b>. This supports matched-setting comparisons.</li>
</ol>
<p class="notice">
The aid sliders are shared comparison variables. They do not erase fixed differences in
parcel mass, tension ceilings, guide-angle windows, or dock locations.
</p>
</div>
</details>
<section class="card">
<h2>1 · Choose a crew</h2>
<div class="card-body">
<div class="section-label">
<span>Changing crew keeps aids</span>
<span>4 crews</span>
</div>
<div id="crewButtons" class="selection-grid"></div>
</div>
</section>
<section class="card">
<h2>2 · Choose a destination</h2>
<div class="card-body">
<div class="selection-grid targets" id="targetButtons"></div>
</div>
</section>
<section class="card">
<h2>3 · Adjust shared launch aids</h2>
<div class="card-body">
<div class="control">
<div class="control-head">
<label for="power">Spring tension</label>
<output id="powerOutput" for="power">65%</output>
</div>
<input id="power" type="range" min="30" max="100" step="1" value="65">
<div class="range-labels"><span>30%</span><span>100%</span></div>
</div>
<div class="control">
<div class="control-head">
<label for="angle">Guide angle</label>
<output id="angleOutput" for="angle">45°</output>
</div>
<input id="angle" type="range" min="15" max="75" step="1" value="45">
<div class="range-labels"><span>15°</span><span>75°</span></div>
</div>
<div class="control">
<div class="control-head">
<label for="height">Release height</label>
<output id="heightOutput" for="height">2.0 m</output>
</div>
<input id="height" type="range" min="1" max="4" step="0.1" value="2">
<div class="range-labels"><span>1.0 m</span><span>4.0 m</span></div>
</div>
<div class="button-row">
<button class="button" id="kitButton" type="button">Load shared test kit</button>
<button class="button green" id="autoFitButton" type="button">Auto-fit selected crew</button>
</div>
<button class="button primary" id="launchButton" type="button">LAUNCH PARCEL</button>
<p class="micro-status" id="launchStatus"></p>
</div>
</section>
<section class="card">
<h2>Constraint ledger</h2>
<div class="card-body">
<div id="constraintLedger" class="ledger"></div>
<div id="complianceBox" class="compliance"></div>
</div>
</section>
</aside>
<section id="viewport" aria-label="Voxel launch neighborhood">
<div id="scene"></div>
<div id="labels"></div>
<div class="viewport-badge">
<strong id="viewportTitle">Ari → Moss Ward</strong>
<span>Calm air · deterministic physics · drag to orbit</span>
</div>
<div class="camera-help">
Drag: orbit · Shift/right-drag: pan · Wheel/pinch: zoom
</div>
<div class="camera-controls" aria-label="Camera controls">
<button id="camOut" type="button" title="Zoom out">−</button>
<button id="camReset" type="button" title="Reset camera">⌂</button>
<button id="camIn" type="button" title="Zoom in">+</button>
</div>
<div id="endBanner" class="hidden">
<h2 id="endTitle"></h2>
<p id="endText"></p>
</div>
</section>
<aside class="right">
<section class="card">
<h2>Community stock board</h2>
<div class="card-body" id="goalBoard"></div>
</section>
<section class="card">
<h2>Matched-aid audit</h2>
<div class="card-body">
<div class="section-label">
<span id="auditTarget">Against Moss Ward</span>
<span>No charge</span>
</div>
<table class="audit-table">
<thead>
<tr>
<th>Crew / fixed</th>
<th>Legal?</th>
<th>Predicted miss</th>
<th>Cost</th>
</tr>
</thead>
<tbody id="auditBody"></tbody>
</table>
<p class="fair-note">
<b>Matched settings are not equalization.</b> Every row uses the same slider values.
Mass, tension ceilings, guide windows, dock locations, and therefore range requirements
still differ.
</p>
</div>
</section>
<section class="card">
<h2>Launch log</h2>
<div class="card-body">
<div id="eventLog" aria-live="polite"></div>
</div>
</section>
<button class="button" id="resetButton" type="button">RESET TRIAL · KEEP CURRENT AIDS</button>
</aside>
</main>
</div>
<script type="module">
import * as THREE from "https://cdnjs.cloudflare.com/ajax/libs/three.js/0.160.0/three.module.min.js";
const $ = id => document.getElementById(id);
const clamp = THREE.MathUtils.clamp;
const GRAVITY = 9.81;
const MAX_LAUNCHES = 12;
const ENERGY_BUDGET = 620;
const DELIVERY_RADIUS = 3.2;
const crews = [
{
id: "ari", name: "Ari", mass: 8, cap: 95, minAngle: 30, maxAngle: 70,
color: 0xf2c84b, station: new THREE.Vector3(-25, 0, -13)
},
{
id: "nia", name: "Nia", mass: 12, cap: 80, minAngle: 25, maxAngle: 60,
color: 0xed6949, station: new THREE.Vector3(25, 0, -13)
},
{
id: "oli", name: "Oli", mass: 16, cap: 65, minAngle: 40, maxAngle: 75,
color: 0x4c8fb7, station: new THREE.Vector3(25, 0, 13)
},
{
id: "sol", name: "Sol", mass: 11, cap: 90, minAngle: 20, maxAngle: 50,
color: 0x62a875, station: new THREE.Vector3(-25, 0, 13)
}
];
const districts = [
{
id: "moss", name: "Moss Ward", short: "Moss", color: 0x62a875,
css: "#62a875", position: new THREE.Vector3(-7, 0, 0), count: 0
},
{
id: "beacon", name: "Beacon Ward", short: "Beacon", color: 0xed6949,
css: "#ed6949", position: new THREE.Vector3(1, 0, -7), count: 0
},
{
id: "orchard", name: "Orchard Ward", short: "Orchard", color: 0x4c8fb7,
css: "#4c8fb7", position: new THREE.Vector3(8, 0, 0), count: 0
}
];
const state = {
crewId: "ari",
targetId: "moss",
settings: { power: 65, angle: 45, height: 2.0 },
launches: 0,
energy: ENERGY_BUDGET,
crewSuccess: Object.fromEntries(crews.map(c => [c.id, 0])),
animating: false,
pendingShot: null,
flightElapsed: 0,
finished: false
};
const getCrew = () => crews.find(c => c.id === state.crewId);
const getDistrict = () => districts.find(d => d.id === state.targetId);
// ----- Three.js scene -----------------------------------------------------
const viewport = $("viewport");
const sceneHost = $("scene");
const labelHost = $("labels");
const scene = new THREE.Scene();
scene.background = new THREE.Color(0xcbdde1);
scene.fog = new THREE.Fog(0xcbdde1, 70, 145);
const camera = new THREE.PerspectiveCamera(42, 1, 0.1, 240);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.08;
renderer.domElement.setAttribute("aria-label", "Interactive voxel launch neighborhood");
sceneHost.appendChild(renderer.domElement);
const hemi = new THREE.HemisphereLight(0xeaf8ff, 0x9f8768, 2.25);
scene.add(hemi);
const sun = new THREE.DirectionalLight(0xfff1cf, 3.0);
sun.position.set(-28, 50, 24);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.camera.left = -58;
sun.shadow.camera.right = 58;
sun.shadow.camera.top = 48;
sun.shadow.camera.bottom = -48;
sun.shadow.camera.near = 1;
sun.shadow.camera.far = 120;
sun.shadow.bias = -0.0006;
scene.add(sun);
const materialCache = new Map();
function material(color) {
if (!materialCache.has(color)) {
materialCache.set(color, new THREE.MeshStandardMaterial({
color,
roughness: 0.86,
metalness: 0.02
}));
}
return materialCache.get(color);
}
function addBox(parent, width, height, depth, color, x = 0, y = 0, z = 0) {
const mesh = new THREE.Mesh(
new THREE.BoxGeometry(width, height, depth),
color?.isMaterial ? color : material(color)
);
mesh.position.set(x, y, z);
mesh.castShadow = true;
mesh.receiveShadow = true;
parent.add(mesh);
return mesh;
}
function addLabel(className, html) {
const label = document.createElement("div");
label.className = `world-label ${className}`;
label.innerHTML = html;
labelHost.appendChild(label);
return label;
}
// Raised voxel terrain.
addBox(scene, 90, 1.1, 70, 0xc8b997, 0, -0.57, 0);
const nx = 44;
const nz = 34;
const tileGeometry = new THREE.BoxGeometry(1.94, 0.16, 1.94);
const tileMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
roughness: 0.96,
vertexColors: true
});
const tiles = new THREE.InstancedMesh(tileGeometry, tileMaterial, nx * nz);
tiles.receiveShadow = true;
tiles.instanceMatrix.setUsage(THREE.StaticDrawUsage);
const tilePalette = [
new THREE.Color(0xd9d1b8),
new THREE.Color(0xe5dcc5),
new THREE.Color(0xcfc8ad),
new THREE.Color(0xded4ba),
new THREE.Color(0xc9c8aa)
];
const matrix = new THREE.Matrix4();
let tileIndex = 0;
for (let ix = 0; ix < nx; ix++) {
for (let iz = 0; iz < nz; iz++) {
const x = -43 + ix * 2;
const z = -33 + iz * 2;
matrix.makeTranslation(x, 0.01, z);
tiles.setMatrixAt(tileIndex, matrix);
const variation = Math.abs((ix * 17 + iz * 31) % 11);
tiles.setColorAt(tileIndex, tilePalette[variation % tilePalette.length]);
tileIndex++;
}
}
tiles.instanceMatrix.needsUpdate = true;
if (tiles.instanceColor) tiles.instanceColor.needsUpdate = true;
scene.add(tiles);
// Simple voxel landscaping.
const treePositions = [
[-38,-25],[-32,-26],[-37,-16],[-40,-4],[-38,9],[-35,20],[-30,27],
[39,-25],[34,-26],[39,-15],[40,-3],[38,10],[34,22],[29,28],
[-18,25],[-9,27],[0,27],[10,26],[19,26],[-17,-27],[-8,-27],[2,-27],[12,-27],[21,-27]
];
for (const [x, z] of treePositions) {
const tree = new THREE.Group();
tree.position.set(x, 0, z);
addBox(tree, 0.65, 2.4, 0.65, 0x886846, 0, 1.2, 0);
addBox(tree, 2.2, 1.7, 2.2, 0x5e986c, 0, 2.55, 0);
addBox(tree, 1.5, 1.1, 1.5, 0x76aa76, 0.25, 3.45, 0.1);
scene.add(tree);
}
// Blocky neighborhood buildings near the edges.
const buildings = [
[-35,-7,7,6,5,0xb86c52],
[-29,-7,5,9,4,0x7895a3],
[35,-7,7,8,5,0xd39a55],
[30,-8,5,6,4,0x8b9f75],
[-36,8,6,7,5,0x8d7fa2],
[35,8,7,10,5,0xb85e62],
[-12,-25,7,5,5,0x7698a4],
[10,-25,8,7,5,0xd29555],
[-14,24,7,6,5,0x7b9a77],
[15,24,8,5,5,0x9a7fa0]
];
for (const [x,z,w,h,d,c] of buildings) {
addBox(scene, w, h, d, c, x, h / 2, z);
addBox(scene, w + 0.4, 0.55, d + 0.4, 0x4d5c62, x, h + 0.22, z);
for (let row = 0; row < Math.floor(h / 3); row++) {
addBox(scene, 1.15, 1.2, 0.12, 0xf2d68b, x - w * 0.23, 1.8 + row * 2.4, z + d / 2 + 0.07);
addBox(scene, 1.15, 1.2, 0.12, 0xf2d68b, x + w * 0.23, 1.8 + row * 2.4, z + d / 2 + 0.07);
}
}
// District landing pads.
const districtVisuals = {};
for (const district of districts) {
const group = new THREE.Group();
group.position.copy(district.position);
scene.add(group);
addBox(group, 6.4, 0.18, 6.4, district.color, 0, 0.15, 0);
const borderMaterial = new THREE.MeshStandardMaterial({
color: 0x34464d,
roughness: 0.8
});
addBox(group, 6.9, 0.3, 0.38, borderMaterial, 0, 0.3, -3.25);
addBox(group, 6.9, 0.3, 0.38, borderMaterial, 0, 0.3, 3.25);
addBox(group, 0.38, 0.3, 6.15, borderMaterial, -3.25, 0.3, 0);
addBox(group, 0.38, 0.3, 6.15, borderMaterial, 3.25, 0.3, 0);
addBox(group, 2.5, 0.08, 0.28, 0xfff2bd, 0, 0.28, 0);
addBox(group, 0.28, 0.08, 2.5, 0xfff2bd, 0, 0.28, 0);
const label = addLabel("district", `
<b>${district.name}</b>
<span>0 / 3 parcels</span>
`);
label.style.borderColor = district.css;
districtVisuals[district.id] = { group, borderMaterial, label };
}
// Crew docks and launchers.
const stationVisuals = {};
for (const crew of crews) {
const group = new THREE.Group();
group.position.copy(crew.station);
scene.add(group);
addBox(group, 4.3, 0.55, 4.3, 0x59686b, 0, 0.25, 0);
addBox(group, 3.5, 0.16, 3.5, crew.color, 0, 0.61, 0);
addBox(group, 1.0, 2.9, 1.0, 0x536267, 0, 1.7, 0);
addBox(group, 1.7, 0.45, 1.7, crew.color, 0, 3.05, 0);
const aimGroup = new THREE.Group();
group.add(aimGroup);
const rail = addBox(aimGroup, 0.9, 0.35, 4.2, 0x34464d, 0, 1.2, 1.8);
rail.rotation.x = -0.06;
addBox(aimGroup, 0.35, 1.25, 0.35, 0x34464d, -0.78, 0.75, 0.8);
addBox(aimGroup, 0.35, 1.25, 0.35, 0x34464d, 0.78, 0.75, 0.8);
const crate = makeParcel(0xf2c84b);
crate.scale.setScalar(0.82);
crate.position.set(0, 2.0, 2.4);
aimGroup.add(crate);
// Static block flag.
addBox(group, 0.22, 4.2, 0.22, 0x536267, -2.7, 2.1, -1.8);
addBox(group, 1.35, 0.75, 0.22, crew.color, -2.1, 3.65, -1.8);
const label = addLabel("station", `
<b>${crew.name}</b>
<span>${crew.mass} kg crew</span>
`);
stationVisuals[crew.id] = { group, aimGroup, crate, rail, label };
}
function makeParcel(color = 0xdca85f) {
const group = new THREE.Group();
addBox(group, 0.95, 0.82, 0.95, color, 0, 0, 0);
addBox(group, 0.14, 0.86, 0.99, 0xfff0bb, 0, 0, 0);
addBox(group, 0.99, 0.86, 0.14, 0xfff0bb, 0, 0, 0);
addBox(group, 0.32, 0.15, 0.32, 0x56666a, 0, 0.49, 0);
return group;
}
// Selected-crew square marker.
const selectionMarker = new THREE.Group();
const selectionMaterial = new THREE.MeshBasicMaterial({ color: 0x26343b });
addBox(selectionMarker, 5.1, 0.1, 0.28, selectionMaterial, 0, 0.1, -2.35);
addBox(selectionMarker, 5.1, 0.1, 0.28, selectionMaterial, 0, 0.1, 2.35);
addBox(selectionMarker, 0.28, 0.1, 4.4, selectionMaterial, -2.35, 0.1, 0);
addBox(selectionMarker, 0.28, 0.1, 4.4, selectionMaterial, 2.35, 0.1, 0);
scene.add(selectionMarker);
// Preview path and landing marker.
const previewMaterial = new THREE.MeshStandardMaterial({
color: 0xf2c84b,
emissive: 0x6b5310,
emissiveIntensity: 0.35,
roughness: 0.7
});
const previewPath = new THREE.InstancedMesh(
new THREE.BoxGeometry(0.22, 0.22, 0.22),
previewMaterial,
46
);
previewPath.frustumCulled = false;
scene.add(previewPath);
const endpointMarker = new THREE.Group();
const endpointMaterial = new THREE.MeshBasicMaterial({ color: 0x278a72 });
addBox(endpointMarker, 1.9, 0.12, 0.24, endpointMaterial, 0, 0, -0.78);
addBox(endpointMarker, 1.9, 0.12, 0.24, endpointMaterial, 0, 0, 0.78);
addBox(endpointMarker, 0.24, 0.12, 1.3, endpointMaterial, -0.78, 0, 0);
addBox(endpointMarker, 0.24, 0.12, 1.3, endpointMaterial, 0.78, 0, 0);
scene.add(endpointMarker);
const flyingParcel = makeParcel(0xf2c84b);
flyingParcel.visible = false;
scene.add(flyingParcel);
const parcelVisuals = [];
// ----- Camera controls implemented locally --------------------------------
const cameraState = {
radius: 63,
theta: 0.72,
phi: 0.98,
target: new THREE.Vector3(0, 0, 0)
};
function updateCamera() {
const sinPhi = Math.sin(cameraState.phi);
camera.position.set(
cameraState.target.x + cameraState.radius * sinPhi * Math.sin(cameraState.theta),
cameraState.target.y + cameraState.radius * Math.cos(cameraState.phi),
cameraState.target.z + cameraState.radius * sinPhi * Math.cos(cameraState.theta)
);
camera.lookAt(cameraState.target);
camera.updateMatrixWorld();
}
function resetCamera() {
cameraState.radius = 63;
cameraState.theta = 0.72;
cameraState.phi = 0.98;
cameraState.target.set(0, 0, 0);
updateCamera();
}
const pointers = new Map();
let lastPinchDistance = 0;
renderer.domElement.addEventListener("contextmenu", e => e.preventDefault());
renderer.domElement.addEventListener("pointerdown", e => {
renderer.domElement.setPointerCapture(e.pointerId);
pointers.set(e.pointerId, { x: e.clientX, y: e.clientY });
if (pointers.size === 2) {
const points = [...pointers.values()];
lastPinchDistance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
}
});
renderer.domElement.addEventListener("pointermove", e => {
if (!pointers.has(e.pointerId)) return;
const previous = pointers.get(e.pointerId);
const dx = e.clientX - previous.x;
const dy = e.clientY - previous.y;
previous.x = e.clientX;
previous.y = e.clientY;
if (pointers.size === 2) {
const points = [...pointers.values()];
const distance = Math.hypot(
points[0].x - points[1].x,
points[0].y - points[1].y
);
if (lastPinchDistance > 0 && distance > 0) {
cameraState.radius = clamp(
cameraState.radius * (lastPinchDistance / distance),
25, 105
);
}
lastPinchDistance = distance;
return;
}
if (e.shiftKey || e.buttons === 2) {
const right = new THREE.Vector3().setFromMatrixColumn(camera.matrix, 0);
right.y = 0;
right.normalize();
const forward = new THREE.Vector3();
camera.getWorldDirection(forward);
forward.y = 0;
forward.normalize();
const panScale = cameraState.radius / 600;
cameraState.target
.addScaledVector(right, -dx * panScale)
.addScaledVector(forward, dy * panScale);
cameraState.target.x = clamp(cameraState.target.x, -28, 28);
cameraState.target.z = clamp(cameraState.target.z, -24, 24);
} else {
cameraState.theta -= dx * 0.006;
cameraState.phi = clamp(cameraState.phi - dy * 0.005, 0.25, 1.43);
}
});
function releasePointer(e) {
pointers.delete(e.pointerId);
if (pointers.size < 2) lastPinchDistance = 0;
}
renderer.domElement.addEventListener("pointerup", releasePointer);
renderer.domElement.addEventListener("pointercancel", releasePointer);
renderer.domElement.addEventListener("wheel", e => {
e.preventDefault();
cameraState.radius = clamp(
cameraState.radius * Math.exp(e.deltaY * 0.001),
25, 105
);
}, { passive: false });
renderer.domElement.addEventListener("dblclick", resetCamera);
$("camIn").addEventListener("click", () => {
cameraState.radius = clamp(cameraState.radius - 7, 25, 105);
});
$("camOut").addEventListener("click", () => {
cameraState.radius = clamp(cameraState.radius + 7, 25, 105);
});
$("camReset").addEventListener("click", resetCamera);
// ----- Rules and physics --------------------------------------------------
function getViolations(crew, settings) {
const violations = [];
if (settings.power > crew.cap) {
violations.push(`tension ${settings.power}% exceeds the ${crew.cap}% ceiling`);
}
if (settings.angle < crew.minAngle || settings.angle > crew.maxAngle) {
violations.push(`guide ${settings.angle}° is outside ${crew.minAngle}–${crew.maxAngle}°`);
}
return violations;
}
function computeShot(crew, district, settings) {
const direction = district.position.clone()
.sub(crew.station)
.setY(0)
.normalize();
const origin = crew.station.clone()
.addScaledVector(direction, 2.4)
.setY(settings.height);
// The same spring setting produces less launch speed for a heavier parcel.
const speed = (6 + settings.power * 0.17) * Math.sqrt(12 / crew.mass);
const pitch = THREE.MathUtils.degToRad(settings.angle);
const horizontalSpeed = speed * Math.cos(pitch);
const verticalSpeed = speed * Math.sin(pitch);
const flightTime = (
verticalSpeed +
Math.sqrt(verticalSpeed * verticalSpeed + 2 * GRAVITY * settings.height)
) / GRAVITY;
const horizontalRange = horizontalSpeed * flightTime;
const endpoint = origin.clone()
.addScaledVector(direction, horizontalRange)
.setY(0);
const miss = endpoint.distanceTo(district.position);
const violations = getViolations(crew, settings);
const cost = Math.ceil(
crew.mass * (0.3 + 0.7 * settings.power / 100) * 4 +
Math.max(0, settings.height - 1) * 6
);
return {
crew,
district,
settings: { ...settings },
direction,
origin,
endpoint,
speed,
horizontalSpeed,
verticalSpeed,
flightTime,
horizontalRange,
miss,
cost,
violations,
legal: violations.length === 0
};
}
function findAutoFit(crew, district) {
const targetDistance = district.position.distanceTo(crew.station) - 2.4;
let best = null;
for (let height = 1; height <= 4.001; height += 0.25) {
for (let power = 30; power <= crew.cap; power += 1) {
const speed = (6 + power * 0.17) * Math.sqrt(12 / crew.mass);
for (let angle = crew.minAngle; angle <= crew.maxAngle; angle += 1) {
const pitch = THREE.MathUtils.degToRad(angle);
const vy = speed * Math.sin(pitch);
const vh = speed * Math.cos(pitch);
const flightTime = (
vy + Math.sqrt(vy * vy + 2 * GRAVITY * height)
) / GRAVITY;
const range = vh * flightTime;
const miss = Math.abs(range - targetDistance);
if (!best || miss < best.miss - 0.001) {
best = {
settings: { power, angle, height: Number(height.toFixed(2)) },
miss
};
}
}
}
}
return best;
}
// ----- UI construction ----------------------------------------------------
$("crewButtons").innerHTML = crews.map(crew => `
<button class="select-button" type="button" data-crew="${crew.id}">
${crew.name}
<small>${crew.mass} kg · ≤${crew.cap}% tension</small>
</button>
`).join("");
$("targetButtons").innerHTML = districts.map(district => `
<button class="select-button target" type="button"
data-target="${district.id}" style="--target-color:${district.css}">
${district.short}
<small>0 / 3</small>
</button>
`).join("");
$("goalBoard").innerHTML = districts.map(district => `
<div class="goal-row" style="--district-color:${district.css}">
<div class="goal-head">
<span>${district.name}</span>
<strong>${district.count} / 3</strong>
</div>
<div class="progress"><div style="width:${district.count / 3 * 100}%"></div></div>
</div>
`).join("") + `
<div class="goal-summary" id="goalSummary"></div>
`;
function updateSelectionButtons() {
document.querySelectorAll("[data-crew]").forEach(button => {
button.classList.toggle("active", button.dataset.crew === state.crewId);
});
document.querySelectorAll("[data-target]").forEach(button => {
button.classList.toggle("active", button.dataset.target === state.targetId);
});
}
function updateHeader() {
const stocked = districts.reduce((sum, district) => sum + district.count, 0);
const quota = Object.values(state.crewSuccess).filter(Boolean).length;
$("stockStat").textContent = `${stocked} / 9`;
$("quotaStat").textContent = `${quota} / 4`;
$("launchStat").textContent = `${state.launches} / ${MAX_LAUNCHES}`;
$("energyStat").textContent = state.energy;
$("goalSummary").innerHTML = `
<b>Community goal:</b> 9 stocked parcels and one successful delivery from every crew.
Currently: <b>${stocked}/9 parcels</b>, <b>${quota}/4 crews</b>.
`;
}
function updateGoalBoard() {
districts.forEach(district => {
const row = document.querySelectorAll(".goal-row")[districts.indexOf(district)];
row.querySelector(".goal-head strong").textContent = `${district.count} / 3`;
row.querySelector(".progress > div").style.width = `${district.count / 3 * 100}%`;
const button = document.querySelector(`[data-target="${district.id}"]`);
button.querySelector("small").textContent = `${district.count} / 3`;
const label = districtVisuals[district.id].label;
label.querySelector("span").textContent = `${district.count} / 3 parcels`;
});
}
function updateAudit() {
const district = getDistrict();
$("auditTarget").textContent = `Against ${district.name}`;
$("auditBody").innerHTML = crews.map(crew => {
const shot = computeShot(crew, district, state.settings);
const legal = shot.legal;
const selected = crew.id === state.crewId ? "selected" : "";
const legalText = legal
? `<span class="good">Yes</span>`
: `<span class="bad">No</span><br>${shot.violations[0]}`;
const missText = legal
? `${shot.miss.toFixed(1)} m`
: "—";
const costText = legal ? `${shot.cost} LU` : "—";
return `
<tr class="${selected}">
<td>
<b>${crew.name}</b><br>
${crew.mass} kg · ≤${crew.cap}%<br>
${crew.minAngle}–${crew.maxAngle}°
</td>
<td>${legalText}</td>
<td>${missText}</td>
<td>${costText}</td>
</tr>
`;
}).join("");
}
function updateLedger() {
const crew = getCrew();
const shot = computeShot(crew, getDistrict(), state.settings);
const rows = [
["Spring tension", `${state.settings.power}%`, "aid"],
["Guide angle", `${state.settings.angle}°`, "aid"],
["Release height", `${state.settings.height.toFixed(1)} m`, "aid"],
["Outgoing speed", `${shot.speed.toFixed(1)} m/s`, "derived"],
["Lift-unit cost", shot.legal ? `${shot.cost} LU` : "Blocked", "derived"],
["Parcel mass", `${crew.mass} kg`, "fixed"],
["Tension ceiling", `≤ ${crew.cap}%`, "fixed"],
["Guide window", `${crew.minAngle}–${crew.maxAngle}°`, "fixed"],
["Dock origin", `${crew.station.x}, ${crew.station.z}`, "fixed"]
];
$("constraintLedger").innerHTML = rows.map(([name, value, type]) => `
<div class="ledger-row">
<span>${name}</span>
<b>${value}</b>
<span class="tag ${type}">${type}</span>
</div>
`).join("");
const compliance = $("complianceBox");
if (shot.violations.length === 0) {
compliance.className = "compliance ok";
compliance.innerHTML = `
<b>${crew.name}'s current aids are legal.</b><br>
Predicted impact: ${shot.miss.toFixed(1)} m from ${getDistrict().name}'s center.
The fixed parcel mass still changes the resulting speed.
`;
} else {
compliance.className = "compliance bad";
compliance.innerHTML = `
<b>Launch blocked for ${crew.name}.</b><br>
${shot.violations.join("; ")}.
`;
}
}
function updateLaunchState() {
const crew = getCrew();
const shot = computeShot(crew, getDistrict(), state.settings);
const reasons = [...shot.violations];
if (state.launches >= MAX_LAUNCHES) reasons.push("the 12-launch limit is reached");
if (shot.cost > state.energy) reasons.push(`the shot needs ${shot.cost} lift units but only ${state.energy} remain`);
if (state.animating) reasons.push("a parcel is currently in flight");
if (state.finished) reasons.push("the trial is complete");
$("launchButton").disabled = reasons.length > 0;
if (reasons.length) {
$("launchStatus").textContent = `Cannot launch: ${reasons.join("; ")}.`;
} else {
$("launchStatus").textContent =
`${shot.miss.toFixed(1)} m predicted miss · ${shot.cost} lift units · ` +
`flight time ${shot.flightTime.toFixed(1)} s.`;
}
}
function updateVisuals() {
const district = getDistrict();
for (const crew of crews) {
const direction = district.position.clone()
.sub(crew.station)
.setY(0)
.normalize();
const yaw = Math.atan2(direction.x, direction.z);
const visual = stationVisuals[crew.id];
visual.aimGroup.rotation.y = yaw;
visual.crate.position.y = state.settings.height;
visual.rail.position.y = 0.85 + state.settings.height * 0.25;
}
const crew = getCrew();
selectionMarker.position.set(crew.station.x, 0.03, crew.station.z);
for (const d of districts) {
districtVisuals[d.id].borderMaterial.color.set(
d.id === district.id ? d.color : 0x34464d
);
}
const shot = computeShot(crew, district, state.settings);
const previewColor = shot.legal && shot.miss <= DELIVERY_RADIUS
? 0x278a72
: 0xed6949;
previewMaterial.color.set(previewColor);
previewMaterial.emissive.set(previewColor).multiplyScalar(0.23);
endpointMaterial.color.set(previewColor);
for (let i = 0; i < 46; i++) {
const fraction = i / 45;
const time = shot.flightTime * fraction;
const x = shot.origin.x + shot.direction.x * shot.horizontalSpeed * time;
const z = shot.origin.z + shot.direction.z * shot.horizontalSpeed * time;
const y = Math.max(
0.22,
shot.origin.y + shot.verticalSpeed * time - 0.5 * GRAVITY * time * time
);
const scale = 0.8 + Math.sin(fraction * Math.PI) * 0.35;
matrix.compose(
new THREE.Vector3(x, y, z),
new THREE.Quaternion(),
new THREE.Vector3(scale, scale, scale)
);
previewPath.setMatrixAt(i, matrix);
}
previewPath.instanceMatrix.needsUpdate = true;
endpointMarker.position.set(shot.endpoint.x, 0.25, shot.endpoint.z);
$("viewportTitle").textContent = `${crew.name} → ${district.name}`;
}
function updateAll() {
updateSelectionButtons();
updateHeader();
updateGoalBoard();
updateAudit();
updateLedger();
updateLaunchState();
updateVisuals();
}
function addLog(message, type = "") {
const item = document.createElement("div");
item.className = `log-item ${type}`;
item.textContent = message;
$("eventLog").prepend(item);
while ($("eventLog").children.length > 9) {
$("eventLog").lastElementChild.remove();
}
}
function setSettings(settings, message) {
state.settings = { ...settings };
$("power").value = state.settings.power;
$("angle").value = state.settings.angle;
$("height").value = state.settings.height;
$("powerOutput").textContent = `${state.settings.power}%`;
$("angleOutput").textContent = `${state.settings.angle}°`;
$("heightOutput").textContent = `${state.settings.height.toFixed(1)} m`;
if (message) $("launchStatus").textContent = message;
updateAll();
}
// ----- Launch and scoring -------------------------------------------------
function launchParcel() {
if ($("launchButton").disabled) return;
const crew = getCrew();
const district = getDistrict();
const shot = computeShot(crew, district, state.settings);
state.launches++;
state.energy -= shot.cost;
state.animating = true;
state.pendingShot = shot;
state.flightElapsed = 0;
flyingParcel.visible = true;
flyingParcel.position.copy(shot.origin);
flyingParcel.rotation.set(0, 0, 0);
updateAll();
}
function resolveLanding(shot) {
const success = shot.miss <= DELIVERY_RADIUS;
const district = shot.district;
if (success) {
district.count++;
state.crewSuccess[shot.crew.id]++;
const parcel = makeParcel(district.color);
parcel.position.set(
shot.endpoint.x,
0.62 + (district.count - 1) * 0.72,
shot.endpoint.z
);
parcel.rotation.y = Math.PI * 0.25;
scene.add(parcel);
parcelVisuals.push(parcel);
addLog(
`${shot.crew.name} delivered to ${district.name} (${district.count}/3). ` +
`Impact was ${shot.miss.toFixed(1)} m from center.`,
"success"
);
} else {
const parcel = makeParcel(0xa46e50);
parcel.position.set(shot.endpoint.x, 0.58, shot.endpoint.z);
parcel.rotation.y = Math.PI * 0.12;
scene.add(parcel);
parcelVisuals.push(parcel);
addLog(
`${shot.crew.name} missed ${district.name} by ${shot.miss.toFixed(1)} m. ` +
`Only the chosen plaza can receive credit.`,
"miss"
);
}
flyingParcel.visible = false;
state.animating = false;
state.pendingShot = null;
const stocked = districts.reduce((sum, d) => sum + d.count, 0);
const quota = Object.values(state.crewSuccess).filter(Boolean).length;
const won = stocked >= 9 && quota >= 4;
if (won) {
finishGame(true, "All three wards are stocked and every crew contributed a successful delivery.");
} else if (state.launches >= MAX_LAUNCHES) {
finishGame(false, "The 12-launch limit was reached before the community goal was completed.");
}
updateAll();
}
function finishGame(won, message) {
state.finished = true;
$("endTitle").textContent = won ? "COMMON SKYWAY COMPLETE" : "TRIAL INCOMPLETE";
$("endText").textContent = message;
$("endBanner").classList.remove("hidden");
addLog(won ? message : message, won ? "success" : "miss");
updateLaunchState();
}
function resetGame() {
state.launches = 0;
state.energy = ENERGY_BUDGET;
state.crewSuccess = Object.fromEntries(crews.map(c => [c.id, 0]));
state.animating = false;
state.pendingShot = null;
state.finished = false;
districts.forEach(district => district.count = 0);
parcelVisuals.forEach(parcel => scene.remove(parcel));
parcelVisuals.length = 0;
flyingParcel.visible = false;
$("eventLog").innerHTML = "";
$("endBanner").classList.add("hidden");
addLog("New trial. Current aid settings are preserved for a fair matched-setting comparison.");
updateAll();
}
// ----- Events -------------------------------------------------------------
$("crewButtons").addEventListener("click", e => {
const button = e.target.closest("[data-crew]");
if (!button) return;
state.crewId = button.dataset.crew;
$("launchStatus").textContent =
`${getCrew().name} selected. Shared aid settings were not changed.`;
updateAll();
});
$("targetButtons").addEventListener("click", e => {
const button = e.target.closest("[data-target]");
if (!button) return;
state.targetId = button.dataset.target;
$("launchStatus").textContent =
`Destination changed to ${getDistrict().name}. No launch charge.`;
updateAll();
});
$("power").addEventListener("input", e => {
setSettings({
...state.settings,
power: Number(e.target.value)
}, "Manual aid adjustment: spring tension changed.");
});
$("angle").addEventListener("input", e => {
setSettings({
...state.settings,
angle: Number(e.target.value)
}, "Manual aid adjustment: guide angle changed.");
});
$("height").addEventListener("input", e => {
setSettings({
...state.settings,
height: Number(e.target.value)
}, "Manual aid adjustment: release height changed.");
});
$("kitButton").addEventListener("click", () => {
setSettings(
{ power: 65, angle: 45, height: 2.0 },
"Shared test kit loaded. All audit rows now use these exact values."
);
});
$("autoFitButton").addEventListener("click", () => {
const crew = getCrew();
const district = getDistrict();
const best = findAutoFit(crew, district);
setSettings(best.settings);
if (best.miss <= DELIVERY_RADIUS) {
$("launchStatus").textContent =
`Auto-fit found legal aids. Predicted miss: ${best.miss.toFixed(1)} m. ` +
`Other crews may still have different outcomes under these same settings.`;
} else {
$("launchStatus").textContent =
`Closest legal auto-fit still misses by ${best.miss.toFixed(1)} m. ` +
`A fixed crew constraint prevents a better fit.`;
}
});
$("launchButton").addEventListener("click", launchParcel);
$("resetButton").addEventListener("click", resetGame);
window.addEventListener("keydown", e => {
if (e.target.matches("input, button, summary")) return;
if (e.code === "Space") {
e.preventDefault();
launchParcel();
}
if (e.key.toLowerCase() === "r") resetCamera();
});
// ----- Resize and render loop ---------------------------------------------
function resize() {
const width = sceneHost.clientWidth;
const height = sceneHost.clientHeight;
if (!width || !height) return;
renderer.setSize(width, height, false);
camera.aspect = width / height;
camera.updateProjectionMatrix();
}
new ResizeObserver(resize).observe(sceneHost);
resize();
resetCamera();
const projected = new THREE.Vector3();
function positionLabel(label, worldPosition) {
projected.copy(worldPosition).project(camera);
const x = (projected.x * 0.5 + 0.5) * sceneHost.clientWidth;
const y = (-projected.y * 0.5 + 0.5) * sceneHost.clientHeight;
const visible = projected.z > -1 && projected.z < 1;
label.style.display = visible ? "block" : "none";
label.style.left = `${x}px`;
label.style.top = `${y}px`;
}
const clock = new THREE.Clock();
function animate() {
requestAnimationFrame(animate);
const dt = Math.min(clock.getDelta(), 0.05);
updateCamera();
if (state.pendingShot) {
const shot = state.pendingShot;
state.flightElapsed += dt;
const duration = clamp(shot.flightTime * 0.7, 1.15, 2.7);
const progress = clamp(state.flightElapsed / duration, 0, 1);
const time = progress * shot.flightTime;
flyingParcel.position.set(
shot.origin.x + shot.direction.x * shot.horizontalSpeed * time,
Math.max(
0.52,
shot.origin.y + shot.verticalSpeed * time - 0.5 * GRAVITY * time * time
),
shot.origin.z + shot.direction.z * shot.horizontalSpeed * time
);
flyingParcel.rotation.x += dt * 2.4;
flyingParcel.rotation.z += dt * 1.3;
if (progress >= 1) resolveLanding(shot);
}
for (const district of districts) {
positionLabel(
districtVisuals[district.id].label,
district.position.clone().setY(2.4)
);
}
for (const crew of crews) {
positionLabel(
stationVisuals[crew.id].label,
crew.station.clone().setY(4.6)
);
}
renderer.render(scene, camera);
}
resetGame();
animate();
</script>
</body>
</html>
```