|
| static void | draw_hud_labels (void) |
| | Print the fixed HUD labels once (numbers refreshed as they change).
|
| static void | draw_score (void) |
| | Refresh the SCORE number (clear the field first so it never smears).
|
| static void | draw_sprites (void) |
| | Draw the two gameplay sprites into the OAM buffer.
|
| static void | draw_time (void) |
| | Refresh the TIME number.
|
| static u16 | kit_tile (u16 f) |
| | The OAM tile of Kit's frame f: 32x32 frames are 4x4 tiles, and a row of OBJ tiles is 16 wide, so frame f starts at column (f % 4) * 4 of tile row (f / 4) * 4.
|
| static void | logo_screen (void) |
| | Show the logo screen: BG2 and the text, no square, no sprites.
|
| int | main (void) |
| static void | show_over (void) |
| | Game-over screen.
|
| static void | show_title (void) |
| | Title screen: the logo, the game's name and the prompt.
|
| static void | spawn_shard (void) |
| | Move the shard to a fresh pseudo-random spot.
|
| static void | start_game (void) |
| | Enter the play state: reset score/timer, centre the player.
|
| static void | update_play (u16 held) |
| | One frame of gameplay.
|
Game skeleton — the smallest complete game: title -> play -> over.
The capstone the curriculum was missing: not a feature demo but the shape of a whole game, small enough to read in one sitting and fork for your own. It recombines the rungs you've climbed — input drives a sprite, a second sprite is a goal, a bounding-box test scores it, text is the HUD, and a hand-rolled state machine ties title, play and game-over together.
The one structural idea: a game is a state machine around one loop. Every frame you WaitForVBlank(), read the pad, then switch
(game_state) to the code for the screen you're on. Transitions are just assignments to game_state plus a one-time setup for the new screen. That is the skeleton under every SNES game; basics/scene_stack shows the same idea lifted into the opt-in scene framework once the enum + switch starts to sprawl.
The game: walk Kit across a square of the Rue basse with the D-pad and pick up the data shard before the timer runs out; each one picked up respawns elsewhere. The title and the game-over screens show the logo.
ROM mode: LoROM (project default).
- Controls
- Title / Game over: START to begin / play again
- Play: D-pad to walk; reach the shard to score
- SNES Concepts
- The frame loop: WaitForVBlank -> read input -> update -> the NMI flushes
- A plain enum + switch state machine (title / play / over)
- Mode 1: BG1 the play square, BG2 the logo, BG3 the text in front; each screen picks its layers with setMainScreen()
- Sprites (Kit + the shard) via the OAM buffer; text HUD via the auto-flush
- Bounding-box collision on a pickup box smaller than the sprites; rngNext()/rngSeed() seeded for varied shard spawns
- What to Observe
- Title shows the logo and "PRESS START". In play, Kit faces the way he walks; reaching the turning shard bumps SCORE and respawns it; TIME counts down; at zero the game-over screen shows the final score. game_state, score, time_left are the probe oracles.
- Modules Used
- console, dma, background, sprite, text, input
- See also
- examples/basics/scene_stack — the same idea via the scene Framework