xonecas.ioDon't click! Sean Caetano Martin Sign in

tiny-adventure / commits / ffd2065

Guide the player to the objective and make combat and gear readable

Beacon, distance and direction, POI levels, journal NEXT marker, Equip best, clickable POI models, boss framing, end screen fixes.

Co-Authored-By: Claude Sonnet 5.5

sacenox3 days agoffd2065d7d5894c9fb7433bb2fe1ba51c36701c6parent c711fe013 files changed

README.md+9-0
@@ -38,8 +38,17 @@ The seed decides every system and its details:
3838
3939 Beating the boss ends the campaign with a stats screen.
4040
41+## Playing
42+
43+- Click a tile to walk there. Right-drag or Q/E rotates, the wheel zooms.
44+- The next main objective is always marked with a light beam and labelled with its level (`Lv N`), even in the fog. J opens the journal, which marks the next step.
45+- Walking over loot picks it up. In the inventory (I), `Equip best` gears every hero with the best items in the pack.
46+- A lost fight returns the party to the nearest spawn or cleared POI. Level up on lower level POIs and try again.
47+
4148 ## Check
4249
50+`scripts/verify.sh <outdir> [seed]` runs the live-game harness at every resolution. `scripts/playthrough.sh <outdir> <seed> [width height name]` plays a whole campaign from the title to the end screen with real clicks, records it, and fails on a softlock, a state mismatch, a layout problem or a console error. See `docs/verification.md`.
51+
4352 ```
4453 go vet ./...
4554 go test ./...
web/js/autogear.js+20-0
@@ -0,0 +1,20 @@
1+import { SLOTS } from './inventory.js';
2+
3+const score = (it) => {
4+ const b = it.bonus || {};
5+ return (b.maxHp || 0) / 3 + (b.attack || 0) + (b.defense || 0) + (b.magic || 0) + (b.speed || 0) / 2 + (b.crit || 0) / 2;
6+};
7+
8+export async function equipBest(state, equip) {
9+ let s = state;
10+ for (let pass = 0; pass < 2; pass++) {
11+ for (const u of s.party.units) {
12+ for (const slot of SLOTS) {
13+ const cur = s.party.units.find((x) => x.id === u.id).gear[slot];
14+ const pick = s.party.inventory.filter((it) => it.slot === slot && !it.key).sort((a, b) => score(b) - score(a))[0];
15+ if (pick && (!cur || score(pick) > score(cur))) s = await equip(u.id, pick.id);
16+ }
17+ }
18+ }
19+ return s;
20+}
web/js/combat.js+10-5
@@ -1,5 +1,5 @@
11 import * as THREE from '../vendor/three.module.js';
2-import { buildFigure, classColor, hashColor, mat, part } from './props.js';
2+import { buildFigure, classColor, hashColor, label, mat, part } from './props.js';
33
44 const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
55
@@ -32,13 +32,18 @@ export function createCombat(scene, party, cam, ui) {
3232 return encounter.enemies.map((e, i) => {
3333 const big = encounter.boss && i === 0;
3434 const fig = buildFigure(hashColor(e.faction || e.class), { scale: big ? 1.9 : 1.1, cls: '', enemy: true });
35- const row = i - (n - 1) / 2;
36- fig.position.set(base.x + 2.1 + (i % 2) * 0.6, base.y, base.z + row * 0.75);
35+ const side = encounter.boss ? (i % 2 ? 1 : -1) * (0.9 + Math.floor((i - 1) / 2) * 0.8) : (i - (n - 1) / 2) * 0.75;
36+ fig.position.set(base.x + (big ? 2.7 : 2.1 + (i % 2) * 0.6), base.y, base.z + (big ? 0 : side));
3737 fig.rotation.y = -Math.PI / 2;
3838 fig.scale.multiplyScalar(0.01);
3939 tween(0.35, (p) => fig.scale.setScalar((big ? 1.9 : 1.1) * Math.max(0.01, p)));
4040 scene.add(fig);
41- const bar = makeBar(fig, big ? 1.9 : 1.25);
41+ const bar = makeBar(fig, 1.25);
42+ const name = label(`${e.name} Lv ${e.level}`);
43+ const k = big ? 1.9 : 1.1;
44+ name.scale.set(2.2 / k, 0.42 / k, 1);
45+ name.position.y = 1.6;
46+ fig.add(name);
4247 return { unit: e, fig, bar, hp: e.stats.hp, max: e.stats.maxHp, home: fig.position.clone() };
4348 });
4449 }
@@ -91,7 +96,7 @@ export function createCombat(scene, party, cam, ui) {
9196 u.abilities.forEach((a) => abilities.set(a.id, a));
9297 });
9398 const mid = party.pos.clone();
94- mid.x += 1.0;
99+ mid.x += 1.6;
95100 cam.setFocus(mid, 10);
96101 ui.renderParty(state, hp);
97102 ui.logLine(`⚔ ${enc.boss ? 'Boss fight' : 'Combat'}: ${foes.map((f) => f.unit.name).join(', ')}`, 'head');
web/js/compass.js+9-0
@@ -0,0 +1,9 @@
1+const NAMES = ['E', 'SE', 'S', 'SW', 'W', 'NW', 'N', 'NE'];
2+
3+export function bearing(from, to) {
4+ const dx = to.x - from.x;
5+ const dy = to.y - from.y;
6+ if (!dx && !dy) return 'here';
7+ const dir = NAMES[Math.round(Math.atan2(dy, dx) / (Math.PI / 4) + 8) % 8];
8+ return `${Math.abs(dx) + Math.abs(dy)} tiles ${dir}`;
9+}
web/js/floaters.js+11-2
@@ -7,6 +7,7 @@ const LIFE = 1.3;
77
88 export function createFloaters(layer) {
99 const live = [];
10+ let count = 0;
1011
1112 function spawn(x, y, text, cls = 'dmg') {
1213 const lab = labelTexture(String(text), COLORS[cls] || COLORS.dmg);
@@ -15,7 +16,7 @@ export function createFloaters(layer) {
1516 const hgt = SIZE[cls] * 1.5 * layer.scale;
1617 sprite.scale.set(hgt * lab.aspect, hgt, 1);
1718 sprite.renderOrder = 20;
18- live.push({ sprite, x, y, t: 0, rise: 56 * layer.scale });
19+ live.push({ sprite, x: x + ((count++ % 3) - 1) * 22 * layer.scale, y, t: 0, rise: 56 * layer.scale });
1920 layer.scene.add(sprite);
2021 }
2122
@@ -34,5 +35,13 @@ export function createFloaters(layer) {
3435 }
3536 }
3637
37- return { spawn, update };
38+ function clear() {
39+ for (const f of live) {
40+ layer.scene.remove(f.sprite);
41+ f.sprite.material.dispose();
42+ }
43+ live.length = 0;
44+ }
45+
46+ return { spawn, update, clear };
3847 }
web/js/hud.js+3-1
@@ -1,3 +1,4 @@
1+import { bearing } from './compass.js';
12 import { drawText, wrap } from './text.js';
23 import { abilityIcon } from './icons.js';
34 import { classColor } from './props.js';
@@ -29,7 +30,8 @@ export function createHud(layer, m, f) {
2930 f.panel(ctx, 0, 0, w, h);
3031 const s = m.state;
3132 const next = s.campaign.main.steps.find((q) => !q.done);
32- const text = m.toast || (next ? next.text : 'The deed is done.');
33+ const poi = next && s.map.pois.find((q) => q.id === next.poi);
34+ const text = m.toast || (next ? `${next.text}${poi ? ` - ${bearing(s.party, poi)}` : ''}` : 'The deed is done.');
3335 ctx.fillStyle = m.toast ? '#ffd27a' : GOLD;
3436 ctx.beginPath();
3537 ctx.moveTo(14, h / 2 - 5);
web/js/inventory.js+6-2
@@ -91,7 +91,7 @@ export function createInventory(layer, m, f) {
9191 drawText(ctx, it.name, x + CELL.w / 2, y + 40, { size: 10, align: 'center', color: rarityColor(it.rarity), maxW: CELL.w - 6, fit: true });
9292 drawText(ctx, it.slot, x + CELL.w / 2, y + 50, { size: 8.5, align: 'center', color: '#8a7a5a', maxW: CELL.w - 6 });
9393 tips[key] = `${describe(it)} - click to equip`;
94- wd.hit(x, y, CELL.w, CELL.h, { key, onClick: () => m.equip(u.id, it.id) });
94+ wd.hit(x, y, CELL.w, CELL.h, { key, name: key, onClick: () => m.equip(u.id, it.id) });
9595 if (wd.hovered(key) || (m.cursorOn && m.cursor === 4 + idx)) {
9696 ctx.strokeStyle = '#ffe9a0';
9797 ctx.lineWidth = 2;
@@ -108,7 +108,11 @@ export function createInventory(layer, m, f) {
108108 ctx.fillRect(x, gy + (th * m.packRow) / total, 4, (th * rows) / total);
109109 }
110110 const key = wd.hoverKey() ?? (m.cursorOn ? (m.cursor < 4 ? `slot-${m.cursor}` : `item-${m.cursor - 4}`) : null);
111- drawText(ctx, tips[key] || 'I or Esc closes. Arrows move, Enter equips, Tab switches hero.', PAD + 28, h - PAD - 14, { size: 12, color: '#3a2a14', shadow: null, maxW: inner - 28, fit: true });
111+ const bw = 92;
112+ const by = h - PAD - 20;
113+ f.button(ctx, w - PAD - bw, by, bw, 26, 'Equip best', { hover: wd.hovered('equip-best'), size: 12, primary: true });
114+ wd.hit(w - PAD - bw, by, bw, 26, { name: 'equip-best', key: 'equip-best', onClick: () => m.equipBest() });
115+ drawText(ctx, tips[key] || 'I or Esc closes. Arrows move, Enter equips, Tab switches hero.', PAD + 28, h - PAD - 14, { size: 12, color: '#3a2a14', shadow: null, maxW: inner - 28 - bw - 8, fit: true });
112116 },
113117 });
114118 }
web/js/journal.js+8-3
@@ -1,10 +1,15 @@
11 import { drawText, font, wrap, lineHeight } from './text.js';
22 import { chrome, INK, PAD } from './chrome.js';
33
4-function blocks(c, hints) {
4+function blocks(c, hints, pois) {
55 const out = [];
66 const head = (t, size = 15) => out.push({ t, size, weight: 'bold', color: INK, gap: 8 });
7- const steps = (q) => q.steps.forEach((s) => out.push({ t: s.text, size: 13, color: s.done ? '#6a5a40' : INK, indent: 20, box: s.done ? 2 : 1 }));
7+ const next = c.main.steps.find((s) => !s.done);
8+ const steps = (q) => q.steps.forEach((s) => {
9+ const lv = pois.find((p) => p.id === s.poi)?.level;
10+ const now = s === next;
11+ out.push({ t: `${now ? 'NEXT: ' : ''}${s.text}${lv && !s.done ? ` (Lv ${lv})` : ''}`, size: 13, weight: now ? 'bold' : undefined, color: s.done ? '#6a5a40' : now ? '#8a2a10' : INK, indent: 20, box: s.done ? 2 : 1 });
12+ });
813 head(c.main.name, 17);
914 steps(c.main);
1015 for (const q of c.sideQuests) {
@@ -31,7 +36,7 @@ export function createJournal(layer, m, f) {
3136 const bottom = h - PAD + 4;
3237 const width = w - PAD * 2 - 12;
3338 const lines = [];
34- for (const b of blocks(m.state.campaign, m.state.map.spawns)) {
39+ for (const b of blocks(m.state.campaign, m.state.map.spawns, m.state.map.pois)) {
3540 const ls = wrap(ctx, b.t, b.size, b.weight, width - (b.indent || 0));
3641 if (b.gap) lines.push({ gap: b.gap });
3742 ls.forEach((t, i) => lines.push({ t, b, first: i === 0 }));
web/js/main.js+7-12
@@ -7,6 +7,7 @@ import { createCamera } from './camera.js';
77 import { createCombat } from './combat.js';
88 import { createUI } from './ui.js';
99 import { mat } from './props.js';
10+import { equipBest } from './autogear.js';
1011 import { installDebug, track } from './debug.js';
1112
1213 const canvas = document.getElementById('stage');
@@ -39,6 +40,7 @@ scene.add(marker);
3940 const ui = await createUI(renderer, canvas, {
4041 onEquip: (unit, item) => mutate(() => api.equip(unit, item)),
4142 onUnequip: (unit, item) => mutate(() => api.equip(unit, item, true)),
43+ onEquipBest: () => mutate(() => equipBest(state, api.equip)),
4244 });
4345 const combat = createCombat(scene, party, cam, ui);
4446
@@ -133,7 +135,7 @@ async function go(t) {
133135 world.showLabels(true);
134136 const r = next.rewards;
135137 if (r) ui.logLine(`Victory: +${r.xp} XP, +${r.gold} gold${r.items?.length ? ', ' + r.items.map((i) => i.name).join(', ') : ''}`, 'reward');
136- if (next.phase === 'defeat') ui.toast('Your party was routed and fell back to the start');
138+ if (next.phase === 'defeat') ui.toast('Your party was routed and fell back to camp');
137139 }
138140 state = next;
139141 world.refresh(next);
@@ -144,7 +146,10 @@ async function go(t) {
144146 cam.snap(p);
145147 }
146148 if (next.winner || next.phase === 'victory') return endGame(next);
147- await collectHere();
149+ for (const it of next.found || []) {
150+ ui.logLine(`Found ${it.name} (${it.rarity})`, 'reward');
151+ ui.toast(`Found ${it.name}`);
152+ }
148153 const sp = state.map.spawns.find((s) => s.x === state.party.x && s.y === state.party.y);
149154 if (sp) ui.logLine(sp.hint, 'hint');
150155 } catch (e) {
@@ -155,16 +160,6 @@ async function go(t) {
155160 }
156161 }
157162
158-async function collectHere() {
159- const l = state.map.loot.find((n) => !n.collected && n.x === state.party.x && n.y === state.party.y);
160- if (!l) return;
161- state = await api.interact(l.id);
162- world.refresh(state);
163- ui.render(state);
164- ui.logLine(`Found ${l.item.name} (${l.item.rarity})`, 'reward');
165- ui.toast(`Found ${l.item.name}`);
166-}
167-
168163 async function restart() {
169164 const s = await api.newGame();
170165 load(s);
web/js/props.js+3-1
@@ -32,7 +32,9 @@ export function hashColor(id) {
3232 export function label(text, color = '#f4e6c0') {
3333 const c = new OffscreenCanvas(512, 96);
3434 const g = c.getContext('2d');
35- g.font = 'bold 44px serif';
35+ let size = 44;
36+ g.font = `bold ${size}px serif`;
37+ while (g.measureText(text).width > 480 && size > 20) g.font = `bold ${--size}px serif`;
3638 g.textAlign = 'center';
3739 g.lineWidth = 8;
3840 g.strokeStyle = '#1b1208';
web/js/screens.js+1-1
@@ -44,7 +44,7 @@ function end(ctx, w, h, wd, f, m) {
4444 drawText(ctx, 'Victory!', w / 2, y, { size: 36, weight: 'bold', align: 'center', color: '#7a4a08', shadow: '#fff5' });
4545 y = paragraph(ctx, `${s.campaign.main.name} is complete`, y + 48, w, { size: 14, color: '#4a3a20' });
4646 y += 8;
47- const rows = [['Battles won', sum.battles], ['Foes slain', sum.kills], ['Loot found', sum.loot], ['Steps walked', sum.steps], ['Time', fmtTime(sum.seconds)], ['Gold', s.party.gold]];
47+ const rows = [['Battles won', sum.battles], ['Foes slain', sum.kills], ['Loot found', sum.loot], ['Quest steps done', sum.steps], ['Time', fmtTime(sum.seconds)], ['Gold', s.party.gold]];
4848 for (const [k, v] of rows) {
4949 drawText(ctx, k, PAD + 20, y, { size: 14, color: '#4a3a20', shadow: null });
5050 drawText(ctx, String(v), w - PAD - 20, y, { size: 14, weight: 'bold', align: 'right', color: INK, shadow: null });
web/js/ui.js+2-0
@@ -48,6 +48,7 @@ export async function createUI(renderer, canvas, h) {
4848 m.logRowsFor = (width) => logRows(probe, m.log, width - 16).length;
4949 m.equip = (u, i) => h.onEquip(u, i);
5050 m.unequip = (u, i) => h.onUnequip(u, i);
51+ m.equipBest = () => h.onEquipBest();
5152
5253 const widgets = {
5354 ...createHud(layer, m, frames),
@@ -196,6 +197,7 @@ export async function createUI(renderer, canvas, h) {
196197 floater: (x, y, text, cls) => floaters.spawn(x, y, text, cls),
197198 setCombat(on) {
198199 m.combat = on;
200+ if (!on) floaters.clear();
199201 if (on) m.panel = null;
200202 refresh();
201203 },
web/js/world.js+29-6
@@ -88,13 +88,14 @@ export function createWorld(scene, state, tex) {
8888 l.visible = false;
8989 group.add(l);
9090 }
91+ obj.userData.tile = { x, y };
9192 const t = { x, y, obj, label: l, hide: () => false };
9293 things.push(t);
9394 return t;
9495 };
9596 for (const poi of map.pois) {
9697 const c = factionColor[poi.faction] || '#aa3333';
97- const t = add(buildPOI(poi, c, poi.id === lastPoi), poi.x, poi.y, poi.name);
98+ const t = add(buildPOI(poi, c, poi.id === lastPoi), poi.x, poi.y, `${poi.name} Lv ${poi.level}`);
9899 poiObjs[poi.id] = { t, c };
99100 }
100101 for (const sp of map.spawns) add(buildSpawn(sp), sp.x, sp.y, sp.kind);
@@ -104,6 +105,11 @@ export function createWorld(scene, state, tex) {
104105 lootObjs[l.id] = { t, collected: l.collected };
105106 }
106107
108+ const beacon = new THREE.Mesh(new THREE.CylinderGeometry(0.18, 0.18, 6, 12, 1, true), mat('#ffe08a', { emissive: '#ffc040', emissiveIntensity: 1.4, transparent: true, opacity: 0.45, side: THREE.DoubleSide }));
109+ beacon.visible = false;
110+ group.add(beacon);
111+ let objective = null;
112+
107113 const frame = new THREE.Group();
108114 const woodMat = new THREE.MeshStandardMaterial({ map: tex.wood, color: tex.wood.userData.fromFile ? '#c9a070' : '#ffffff', roughness: 0.8 });
109115 const bar = (w, d, x, z) => {
@@ -136,12 +142,20 @@ export function createWorld(scene, state, tex) {
136142 }
137143 }
138144 for (const l of cur.map.loot) lootObjs[l.id].collected = l.collected;
145+ const next = cur.campaign.main.steps.find((s) => !s.done);
146+ const target = next && cur.map.pois.find((p) => p.id === next.poi);
147+ objective = target ? poiObjs[target.id].t : null;
148+ beacon.visible = !!objective;
149+ if (objective) {
150+ const bp = worldPos(target.x, target.y);
151+ beacon.position.set(bp.x, bp.y + 3, bp.z);
152+ }
139153 applyThings();
140154 }
141155
142156 function applyThings() {
143157 for (const t of things) {
144- const v = explored[t.y * W + t.x] === 1 && !t.hide();
158+ const v = (explored[t.y * W + t.x] === 1 || t === objective) && !t.hide();
145159 t.obj.visible = v;
146160 if (t.label) t.label.visible = v && labelsOn;
147161 }
@@ -161,6 +175,12 @@ export function createWorld(scene, state, tex) {
161175 }
162176
163177 function path(from, to) {
178+ const blocked = new Set(map.pois.filter((q) => !poiObjs[q.id].cleared && !(q.x === to.x && q.y === to.y)).map((q) => q.y * W + q.x));
179+ const out = route(from, to, blocked);
180+ return out.length ? out : route(from, to, new Set());
181+ }
182+
183+ function route(from, to, blocked) {
164184 const key = (x, y) => y * W + x;
165185 const prev = new Map([[key(from.x, from.y), null]]);
166186 const queue = [[from.x, from.y]];
@@ -170,7 +190,7 @@ export function createWorld(scene, state, tex) {
170190 for (const [dx, dy] of [[1, 0], [-1, 0], [0, 1], [0, -1]]) {
171191 const nx = cx + dx;
172192 const ny = cy + dy;
173- if (nx < 0 || ny < 0 || nx >= W || ny >= H || prev.has(key(nx, ny)) || !map.tiles[ny][nx].walkable) continue;
193+ if (nx < 0 || ny < 0 || nx >= W || ny >= H || prev.has(key(nx, ny)) || !map.tiles[ny][nx].walkable || blocked.has(key(nx, ny))) continue;
174194 prev.set(key(nx, ny), [cx, cy]);
175195 queue.push([nx, ny]);
176196 }
@@ -183,13 +203,16 @@ export function createWorld(scene, state, tex) {
183203 const raycaster = new THREE.Raycaster();
184204 function pick(ndc, camera) {
185205 raycaster.setFromCamera(ndc, camera);
186- const hits = raycaster.intersectObjects(meshes, false);
187- if (!hits.length) return null;
188- const [x, y] = hits[0].object.userData.tiles[hits[0].instanceId];
206+ const solids = things.filter((t) => t.obj.visible).map((t) => t.obj);
207+ const hit = raycaster.intersectObjects([...meshes, ...solids], true)[0];
208+ if (!hit) return null;
209+ for (let o = hit.object; o; o = o.parent) if (o.userData.tile) return o.userData.tile;
210+ const [x, y] = hit.object.userData.tiles[hit.instanceId];
189211 return { x, y };
190212 }
191213
192214 function update(t) {
215+ beacon.material.opacity = 0.35 + Math.sin(t * 3) * 0.12;
193216 for (const l of Object.values(lootObjs)) {
194217 const gem = l.t.obj.userData.gem;
195218 if (gem) gem.position.y = 0.7 + Math.sin(t * 2.5) * 0.06;