1
0
Fork 0
mirror of https://github.com/imjasonh/nescript synced 2026-07-08 17:06:04 +00:00

platformer: sprite-based status bar with score + lives

Upgrades the platformer's "live coin count" into a proper heads-up
display that stays pinned to the top of the viewport while the
nametable scrolls. Left side: coin icon + two-digit stomp tally.
Right side: red heart icon + single-digit lives counter. Both ride
through the GameOver screen without jumping position, so the death
banner reads as a continuation of the same run.

Wire-up: three new cross-state bits — score now accumulates across
lives, `lives` starts at 3 and decrements in `GameOver.on_enter`,
and the GameOver → Playing retry bounces to Title instead when the
last heart is spent (Title's `on_enter` refills both).

Tile pipeline: ten decimal digits + a heart glyph added to the
committed Tileset (generator source in `scripts/gen_platformer_tiles.rs`
kept in sync). Digits use `c` (white) so they read against the
sky; the heart uses `a` (red) to match the cap/brick palette.

Division workaround: the obvious `stomp_count / 10` / `% 10` pair
miscompiles near state transitions — the built ROM cycles
Title → Playing → Title once per blink period with Playing
surviving exactly one frame. Swapping both calls for repeated
`while r >= 10 { r -= 10 }` helpers fixes it. Documented as a
new entry in `docs/future-work.md` so the next person reaching
for `/` or `%` knows to check there first.

Goldens, docs/platformer.gif, and the top-level + examples README
entries all refreshed in the same commit.
This commit is contained in:
Claude 2026-04-20 13:59:14 +00:00
parent 6b1cc98267
commit b83b944570
No known key found for this signature in database
9 changed files with 374 additions and 39 deletions

View file

@ -226,6 +226,145 @@ cccccccc",
........
........
........
........",
},
// ── HUD glyphs (sprite-only; palette sp0: a=red, c=white) ──
// Each digit is a 4-wide outline centred in an 8×8 cell and
// drawn in white ('c') so it reads crisply over the sky
// backdrop at the top of the playfield. The compiler treats
// '.' as transparent for sprites, so the sky shows through.
Tile {
name: "Digit 0",
art: "\
........
..cccc..
..c..c..
..c..c..
..c..c..
..c..c..
..cccc..
........",
},
Tile {
name: "Digit 1",
art: "\
........
...cc...
..ccc...
...cc...
...cc...
...cc...
..cccc..
........",
},
Tile {
name: "Digit 2",
art: "\
........
..cccc..
.....c..
....cc..
...cc...
..cc....
..cccc..
........",
},
Tile {
name: "Digit 3",
art: "\
........
..cccc..
.....c..
...ccc..
.....c..
.....c..
..cccc..
........",
},
Tile {
name: "Digit 4",
art: "\
........
..c..c..
..c..c..
..cccc..
.....c..
.....c..
.....c..
........",
},
Tile {
name: "Digit 5",
art: "\
........
..cccc..
..c.....
..cccc..
.....c..
..c..c..
..cccc..
........",
},
Tile {
name: "Digit 6",
art: "\
........
..cccc..
..c.....
..cccc..
..c..c..
..c..c..
..cccc..
........",
},
Tile {
name: "Digit 7",
art: "\
........
..cccc..
.....c..
....c...
...c....
..c.....
..c.....
........",
},
Tile {
name: "Digit 8",
art: "\
........
..cccc..
..c..c..
..cccc..
..c..c..
..c..c..
..cccc..
........",
},
Tile {
name: "Digit 9",
art: "\
........
..cccc..
..c..c..
..cccc..
.....c..
.....c..
..cccc..
........",
},
// Small red heart for the lives readout. Uses 'a' (red) so the
// shape pops against the sky and matches the cap/brick red.
Tile {
name: "Heart",
art: "\
........
.aa..aa.
aaaaaaaa
aaaaaaaa
.aaaaaa.
..aaaa..
...aa...
........",
},
];