Board scene
The board-game recipe: a Game looked at from above and the slot-based HUD doing the rest — a score line up top, a blinking hint, a button below the board, and a dialog when you win.
The whole game
ts
import * as THREE from 'three';
import { Game } from '@maomi/sge';
import { defaultLights } from '@maomi/sge/lights';
import { stageBackdrop } from '@maomi/sge/backdrop';
/* The board-game recipe: a Game looked at from above, a stage backdrop, and the slot-based
HUD driving score, hints, and a dialog — no physics involved. */
export const createGame = (): HTMLElement => {
const game = new Game();
game.renderer.setClearColor(0x10131f);
game.scene.background = stageBackdrop('#233047', '#0b0f1c', 'rgba(255,255,255,0.05)');
game.scene.add(defaultLights({ shadowExtent: 20, shadowNormalBias: 0 }));
// An 8×8 checkerboard of extruded tiles.
const board = new THREE.Group();
const light = new THREE.MeshLambertMaterial({ color: 0xd8c9a3 });
const dark = new THREE.MeshLambertMaterial({ color: 0x4b3f2f });
for (let x = 0; x < 8; x++) {
for (let z = 0; z < 8; z++) {
const tile = new THREE.Mesh(new THREE.BoxGeometry(1, 0.2, 1), (x + z) % 2 ? dark : light);
tile.position.set(x - 3.5, 0, z - 3.5);
tile.receiveShadow = true;
board.add(tile);
}
}
game.scene.add(board);
// A few pieces to look at.
const piece = new THREE.MeshStandardMaterial({ color: 0xcc4444, roughness: 0.4 });
[[-2.5, -2.5], [0.5, 1.5], [2.5, -0.5]].forEach(([x, z]) => {
const p = new THREE.Mesh(new THREE.CylinderGeometry(0.32, 0.4, 0.5, 24), piece);
p.position.set(x, 0.35, z);
p.castShadow = true;
board.add(p);
});
let score = 0;
game.hud.text('score', 'Score: 0', 'top');
game.hud.hint('click +1 to score');
game.hud.button('plus', '+1', () => {
score += 1;
game.hud.text('score', `Score: ${score}`, 'top');
game.hud.hint('');
if (score === 5) game.hud.dialog({ title: 'You win', lines: ['Five points — the demo is complete.'], onClose: () => game.hud.dialog(null) });
}, 'below-center');
game.hud.root.style.setProperty('--hud-gap', '30vh');
game.onFrame = (delta) => { board.rotation.y += delta * 0.1; };
return game.start(0, 12, 0.001);
};Things to notice:
- Every HUD call upserts by id —
hud.text('score', …)is called on every click and just rewrites the line. --hud-gappositionsabove-center/below-centerrelative to the board's size; the game knows how big its board is, the HUD doesn't.- The dialog takes the pointer while open; the world underneath is dimmed and unclickable.