Scrolling map with animated sprite character. More...
#include <snes.h>#include <snes/map.h>#include "res/roofs.inc"#include "res/kit.inc"#include "res/rooftops.inc"Macros | |
| #define | FRAME_WALK 4 |
| The roofs' 802 tiles, Kit's 32x32 frames. | |
| #define | ROOF_Y (22 * 8) |
| The roofs' surface: row 22 of the map. | |
Functions | |
| static u16 | kit_tile (u16 f) |
| OAM tile number of frame f of Kit's sheet. | |
| int | main (void) |
| Entry point — scrolling map with Kit walking on it. | |
Variables | |
| u16 | flip |
| Animation counter (one walk frame every 4 frames of movement). | |
| u16 | flipx |
| Horizontal flip flag (1 = facing left). | |
| u16 | frame |
| Current sprite tile number. | |
| u16 | frameidx |
| Current walk frame index (0-7). | |
| u16 | xloc |
| Kit X position in map pixels. | |
| u16 | yloc |
| Kit Y position in map pixels (the top of his 32x32 frame). | |
Scrolling map with animated sprite character.
A large Tiled map scrolls as Kit, the fox-kit courier, walks left and right along a row of rooftops at night. The map engine streams only the visible tiles to VRAM, so the map can be much wider than the screen. The sprite cycles through 8 walk frames and flips horizontally based on direction.
This is the stepping stone between "static background" and "continuous_scroll" — it teaches the map engine basics with a simple player character.
This began as the PVSnesLib "mapscroll" example by alekmaul; the map, its tiles and Kit are ours (devtools/art_assets/build.py writes the Tiled map and its tile sheet from assets/neo-lumen/).
| #define FRAME_WALK 4 |
The roofs' 802 tiles, Kit's 32x32 frames.
The level's tilemap, tile definitions and objects (opensnes-level)
First walk frame in Kit's sheet (frames 4-11, four 32x32 frames a row)
| #define ROOF_Y (22 * 8) |
The roofs' surface: row 22 of the map.
OAM tile number of frame f of Kit's sheet.
The converter lays the sheet's 32x32 blocks out four to a 128-pixel row of OBJ VRAM: block f starts at tile (f % 4) * 4 + (f / 4) * 64.
| int main | ( | void | ) |
Entry point — scrolling map with Kit walking on it.
| u16 flip |
Animation counter (one walk frame every 4 frames of movement).
| u16 flipx |
Horizontal flip flag (1 = facing left).
| u16 frame |
Current sprite tile number.
| u16 frameidx |
Current walk frame index (0-7).
| u16 xloc |
Kit X position in map pixels.
| u16 yloc |
Kit Y position in map pixels (the top of his 32x32 frame).