OpenSNES
Modern Open-Source SNES Development SDK
Loading...
Searching...
No Matches
main.c File Reference

Scrolling map with animated sprite character. More...

#include <snes.h>
#include <snes/map.h>
#include "res/tilesMario.inc"
#include "res/mario.inc"
#include "res/tiledMario.inc"

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).
static const u8 sprTiles [4] = {0, 2, 4, 6}
 4bpp tilesMario_tiles graphics
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
  • mapGetCameraX() / mapGetCameraY() 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).

◆ sprTiles

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

4bpp tilesMario_tiles graphics

Tileset palette (3 banks x 16 colors)

Full level tilemap from tmx2snes

Metatile definitions

Tile collision attributes

16x16 Mario sprite tiles (4 animation frames)

Mario sprite palette

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

◆ xloc

u16 xloc

Mario X position in map pixels.

◆ yloc

u16 yloc

Mario Y position in map pixels.