shard_dash: a small game in several files, with a test for each screen More...
#include <snes.h>#include <snes/text.h>#include <snes/sprite.h>#include "res/field.inc"#include "res/logo.inc"#include "res/cast.inc"#include "game.h"#include "screen.h"#include "save.h"Functions | |
| static void | boot (void) |
| Load what every screen shares, once, with the display off. The maps come per screen. | |
| static void | gamePump (void) |
| The pump: what the game does on every image, in every screen, fades and loads included. | |
| int | main (void) |
Variables | |
| u8 | game_screen |
| Which screen runs (the tests read it by name). | |
| u16 | pump_frames |
| Frames the pump ran since power-on: it runs in fades, waits and loads too. | |
| u8 | run_new_best |
| The last round: 1 if it beat the saved best. | |
| u16 | run_time |
| The last round: frames from the start to the last shard (or TIME_LIMIT). | |
| u8 | run_won |
| The last round: 1 if the goal was reached before the clock. | |
shard_dash: a small game in several files, with a test for each screen
The other examples are one file because they teach one thing. This one shows how a game is put together so that it stays readable and testable:
| File | Role |
|---|---|
| main.c | boot, the pump, and the sequence: title, round, result, again |
| screen.c/h | the screen layer: VBlank, queue flush, fades, pad edges, pump |
| title.c | the title screen, one function |
| play.c | the round, one function |
| result.c | the result screen, one function |
| save.c/h | the save: a versioned, checksummed record, defaults when it is off |
| ui.c/h | text helpers the screens share |
The game: grab five shards in thirty seconds. A win is saved if it is the best time; the result screen shows it and the title returns.
Design rules shown here (each is commented where it is applied):
|
static |
Load what every screen shares, once, with the display off. The maps come per screen.
< the play square
< the logo
< the text
< the text
< sprite tiles
|
static |
The pump: what the game does on every image, in every screen, fades and loads included.
| int main | ( | void | ) |
| u8 game_screen |
Which screen runs (the tests read it by name).
| u16 pump_frames |
Frames the pump ran since power-on: it runs in fades, waits and loads too.
| u8 run_new_best |
The last round: 1 if it beat the saved best.
| u16 run_time |
The last round: frames from the start to the last shard (or TIME_LIMIT).
| u8 run_won |
The last round: 1 if the goal was reached before the clock.