Loading...
Searching...
No Matches
main.c File Reference

Scrolling map with animated sprite character. More...

#include <snes.h>
#include <snes/map.h>

Functions

int main (void)
 Entry point — scrolling map with animated Mario.
 

Variables

u16 flip
 Animation toggle (advance every other input frame)
 
u16 flipx
 Horizontal flip flag (1 = facing left)
 
u16 frame
 Current sprite tile number.
 
u16 frameidx
 Current animation frame index (0-3)
 
u8 gfxsprite []
 16x16 Mario sprite tiles (4 animation frames)
 
u8 gfxsprite_end []
 
u8 mapdata []
 Full level tilemap from tmx2snes.
 
u8 palsprite []
 Mario sprite palette.
 
u8 palsprite_end []
 
static const u8 sprTiles [4] = {0, 2, 4, 6}
 Walk frame tile offsets: each 16x16 sprite = 2 tiles in VRAM.
 
u8 tileset []
 4bpp tileset graphics
 
u8 tileset_end []
 
u8 tilesetatt []
 Tile collision attributes.
 
u8 tilesetdef []
 Metatile definitions.
 
u8 tilesetpal []
 Tileset palette (3 banks x 16 colors)
 
u8 tilesetpal_end []
 
u16 xloc
 Mario X position in map pixels.
 
u16 yloc
 Mario Y position in map pixels.
 

Detailed Description

Scrolling map with animated sprite character.

A large Tiled map scrolls as a Mario sprite moves left and right. The map engine streams only the visible tiles to VRAM, so the map can be much wider than the screen. The sprite animates between 4 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.

Ported from PVSnesLib "mapscroll" example by alekmaul.

SNES Concepts
  • Map engine: mapLoad / mapUpdate / mapUpdateCamera / mapVblank
  • Camera-follow: sprite position drives the viewport
  • Sprite animation: 4-frame walk cycle with horizontal flip
  • oamSet for simple single-sprite rendering
  • x_pos / y_pos camera exports for screen-relative sprite positioning
What to Observe
  • Press LEFT/RIGHT to move Mario through the level
  • The background scrolls to follow the character
  • Mario's walk animation cycles every 2 frames of movement
  • Mario flips horizontally when changing direction
Modules Used
console, sprite, dma, input, background, map
See also
map.h, sprite.h, input.h

Function Documentation

◆ main()

int main ( void  )

Entry point — scrolling map with animated Mario.

Returns
Never returns (infinite game loop)

Variable Documentation

◆ flip

u16 flip

Animation toggle (advance every other input frame)

◆ flipx

u16 flipx

Horizontal flip flag (1 = facing left)

◆ frame

u16 frame

Current sprite tile number.

◆ frameidx

u16 frameidx

Current animation frame index (0-3)

◆ gfxsprite

u8 gfxsprite[]
extern

16x16 Mario sprite tiles (4 animation frames)

◆ gfxsprite_end

u8 gfxsprite_end[]

◆ mapdata

u8 mapdata[]
extern

Full level tilemap from tmx2snes.

◆ palsprite

u8 palsprite[]
extern

Mario sprite palette.

◆ palsprite_end

u8 palsprite_end[]

◆ sprTiles

const u8 sprTiles[4] = {0, 2, 4, 6}
static

Walk frame tile offsets: each 16x16 sprite = 2 tiles in VRAM.

◆ tileset

u8 tileset[]
extern

4bpp tileset graphics

◆ tileset_end

u8 tileset_end[]

◆ tilesetatt

u8 tilesetatt[]
extern

Tile collision attributes.

◆ tilesetdef

u8 tilesetdef[]
extern

Metatile definitions.

◆ tilesetpal

u8 tilesetpal[]
extern

Tileset palette (3 banks x 16 colors)

◆ tilesetpal_end

u8 tilesetpal_end[]

◆ xloc

u16 xloc

Mario X position in map pixels.

◆ yloc

u16 yloc

Mario Y position in map pixels.