A threshold camera over two layers in parallax: Kit runs on the roofs. More...
Classes | |
| struct | GameState |
| Centralized game state structure. More... | |
Macros | |
| #define | FRAME_IDLE 0 |
| The frames in res/kit.png, 32x32, four a row: idle 0-3, run 4-11. | |
| #define | FRAME_RUN 4 |
| #define | KIT_Y 105 |
| Kit's sprite y: his feet (row 30 of the frame) on the roofs (picture row 144, scrolled by 8). | |
Scroll Configuration | |
Constants controlling the camera | |
| #define | MAX_SCROLL_X 256 |
| #define | SCROLL_THRESHOLD_LEFT 80 |
| #define | SCROLL_THRESHOLD_RIGHT 140 |
Functions | |
| static u16 | frame_tile (u16 f) |
The OAM tile number of frame f of the sheet. | |
| int | main (void) |
| Entry point – a threshold camera over two layers in parallax. | |
Variables | |
| static u8 | facing_left |
| Kit faces left (his frames face right; the sprite is mirrored). | |
| GameState | game = {20, 105 , 0, 8, 0, 240} |
| Global game state instance with initial values. | |
A threshold camera over two layers in parallax: Kit runs on the roofs.
Kit runs along a stretch of roofs 512 px wide (BG1, a 64x32 map) in front of the far towers (BG2). The camera follows him without a map engine: while he is between two thresholds of the screen he moves and the world stays; what he goes past one, the world scrolls instead and he is put back on it, so he keeps his place on screen while the roofs go by. BG2 scrolls at half BG1's speed, which is what makes the towers look far away. Scroll registers are written via bgSetScroll(), which defers the actual PPU register write to the NMI handler via a dirty flag.
| #define FRAME_IDLE 0 |
The frames in res/kit.png, 32x32, four a row: idle 0-3, run 4-11.
| #define FRAME_RUN 4 |
| #define KIT_Y 105 |
Kit's sprite y: his feet (row 30 of the frame) on the roofs (picture row 144, scrolled by 8).
| #define MAX_SCROLL_X 256 |
BG1's last scroll: 512 px of roofs minus one 256 px screen
| #define SCROLL_THRESHOLD_LEFT 80 |
When Kit's x < this, scroll left
| #define SCROLL_THRESHOLD_RIGHT 140 |
When Kit's x > this, scroll right
The OAM tile number of frame f of the sheet.
A 32x32 frame is 4x4 tiles. VRAM rows of sprite tiles are 16 tiles wide, so a frame row of four is one VRAM row of tiles: frame f starts at column (f % 4) * 4 of tile row (f / 4) * 4.
| int main | ( | void | ) |
Entry point – a threshold camera over two layers in parallax.
Loads the roofs (BG1, 64x32), the far towers (BG2, 64x32) and Kit's frames, each in its own VRAM and CGRAM slot. Each frame, the D-pad moves Kit; past a threshold the camera scrolls instead, BG2 at half speed.
< Current joypad button state (read from hardware)
< Kit's current frame
< Frames since the animation started
< How far past a threshold Kit went this frame
< When Kit's x > this, scroll right
< BG1's last scroll: 512 px of roofs minus one 256 px screen
< When Kit's x > this, scroll right
< BG1's last scroll: 512 px of roofs minus one 256 px screen
< BG1's last scroll: 512 px of roofs minus one 256 px screen
< When Kit's x < this, scroll left
< When Kit's x < this, scroll left
|
static |
Kit faces left (his frames face right; the sprite is mirrored).
| GameState game = {20, 105 , 0, 8, 0, 240} |
Global game state instance with initial values.