Game over, victory and results screens for browser games. Tested helpers for stats, a grade, new records against saved bests (higher or lower is better per stat), numbers that count up one row at a time and can be skipped, an input delay so a held button doesn't restart instantly, share text, and restart options (retry first, continue, level select, menu); plus what to show after losing versus ...
Download skill (.zip) Files on GitHubGame over screen
What to show
| After losing | After winning |
|---|---|
| Score and best, how close they got (“2 waves from the record”) | Score, time, grade, new records |
| One tip or what killed them | Rewards earned, what unlocked |
| Retry focused, instant | Next level focused, Retry, Level select |
Keep losing light: no long animation, no lecture. Players who just lost want to try again.
assets/results.js
import { buildResults, createResultsScreen, shareLine, restartOptions } from "./results.js";
const res = buildResults({ score, time, kills }, { best: save.get("best"), better: { score: "max", time: "min" }, gradeBy: (s) => s.score / 5000 });
save.set("best", res.best); // res.newBest, res.records [{ stat, value, previous }], res.grade "S".."D"
const screen = createResultsScreen(res, { rows: [{ label: "Score", value: score }, { label: "Time", value: fmtTime(time) }], reducedMotion });
update: screen.update(dt); if (confirmPressed && screen.skip()) return; if (screen.ready) menu.handle(input);
draw: rows where screen.rowVisible(i), value screen.shownValue(i); grade when screen.gradeVisible
share: shareLine({ game: "Gem Dash", score, grade: res.grade, time }) -> "Gem Dash: 4,200 (A) in 1:23. Can you beat it?"
restartOptions({ hasCheckpoint, hasLevels }) // Retry first, on Enter/Space/R
- The first confirm while numbers count finishes them; the next one acts.
readywaits 0.6 s so the button held when dying doesn’t skip the screen. - In Bash spaces, a Share button uses
bash.share(sharing-results guide); a board for the space goes through a route. Outside Bash, use leaderboard-system.
Tested
Node tests: new best for “max” and “min” stats, first runs, worse runs, grades, rows counting in turn, skip finishing first, the input delay, share text, restart option order. Used in the UI kit demo (count-up, grade, new best, retry).
Pitfalls
A slow results animation on every death, Retry not focused, pressing jump while dying skipping the screen, records that compare against the wrong direction (times), and no way to see the best score.