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

Platformer with diagonal slope collision detection. More...

#include <snes.h>
#include <snes/map.h>
#include <snes/object.h>
#include "mario.h"

Functions

int main (void)
 Main entry point – slope collision platformer demo.
 
void objRegisterTypes (void)
 Register Mario's object type callback with correct bank byte.
 

Variables

u8 mapmario
 Map data (tile indices for the level layout)
 
u8 objmario
 Object layer data (entity spawn positions and types within the map)
 
u8 tilepal
 BG1 tileset palette (BGR555, 16 colors)
 
u8 tileset
 BG1 tileset tile data (4bpp) – start label.
 
u8 tilesetatt
 Tile attribute table (encodes slope angles and collision flags per tile)
 
u8 tilesetdef
 Tile definition table (maps tile index to visual properties)
 
u8 tilesetend
 BG1 tileset tile data – end label (for size calculation)
 

Detailed Description

Platformer with diagonal slope collision detection.

Demonstrates the object engine's objCollidMapWithSlopes() function for handling diagonal terrain in a tile-based platformer. The SNES has no hardware support for collision, so slope detection is done in software by reading tile attribute tables that encode slope angles per tile (flat, 45-degree, half-slopes).

Uses the full OpenSNES game stack: map engine for scrolling, object engine for entity management, and dynamic sprite engine for animated character rendering. Mario walks, jumps, and slides on slopes with gravity-based physics.

Port of the PVSnesLib slopemario example by Nub1604.

SNES Concepts
  • Mode 1 with BG1 (tileset) and OBJ (sprites)
  • Map engine with tile attribute tables (collision properties per tile)
  • Slope collision: objCollidMapWithSlopes() for diagonal terrain
  • Object engine: entity lifecycle, update callbacks, physics
  • Dynamic sprite engine: animated 16x16 sprite with frame management
  • SC_64x32 tilemap for horizontally-scrolling levels
What to Observe
  • Mario walks and jumps across terrain with diagonal slopes
  • Character follows slope surfaces smoothly (no stair-stepping)
  • Camera tracks Mario's position with map scrolling
  • Gravity pulls Mario down when airborne
Modules Used
console, sprite, sprite_dynamic, sprite_lut, dma, input, background, map, object
See also
map.h, object.h, sprite.h, background.h

Function Documentation

◆ main()

int main ( void  )

Main entry point – slope collision platformer demo.

Initializes the map engine with slope-aware collision data, registers the Mario object type, loads map and object layers, and enters the game loop. The main loop pipeline is:

  1. mapUpdate() – prepare new tile columns during active display
  2. objUpdateAll() – run physics and collision for all entities
  3. oamInitDynamicSpriteEndFrame() – finalize sprite tile queue
  4. WaitForVBlank + mapVblank + oamVramQueueUpdate – flush to VRAM

objCollidMapWithSlopes() is called internally by Mario's update callback to handle diagonal terrain traversal.

Returns
0 (never reached – infinite game loop)

◆ objRegisterTypes()

void objRegisterTypes ( void  )
extern

Register Mario's object type callback with correct bank byte.

Implemented in assembly because the object engine stores function pointers with bank bytes for cross-bank calls. C cannot express the :label bank-byte operator, so an ASM wrapper is required.

Variable Documentation

◆ mapmario

u8 mapmario
extern

Map data (tile indices for the level layout)

◆ objmario

u8 objmario
extern

Object layer data (entity spawn positions and types within the map)

◆ tilepal

u8 tilepal
extern

BG1 tileset palette (BGR555, 16 colors)

◆ tileset

u8 tileset
extern

BG1 tileset tile data (4bpp) – start label.

◆ tilesetatt

u8 tilesetatt
extern

Tile attribute table (encodes slope angles and collision flags per tile)

◆ tilesetdef

u8 tilesetdef
extern

Tile definition table (maps tile index to visual properties)

◆ tilesetend

u8 tilesetend
extern

BG1 tileset tile data – end label (for size calculation)