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

Scrolling platformer with object engine and enemy AI. More...

#include <snes.h>
#include <snes/map.h>
#include <snes/object.h>
#include "kit.h"
#include "insect.h"
#include "automaton.h"
#include "res/tiles.inc"
#include "res/kit.inc"
#include "res/insect.inc"
#include "res/automaton.inc"
#include "res/skyline.inc"

Functions

int main (void)
 Main entry point – scrolling platformer with map and object engines.

Variables

u8 maplevel
 Map data (tile indices for the scrolling level layout).
u16 nbobjects
 Shared sprite palette for all entity types (BGR555).
u8 objlevel
 Object layer data (spawn positions and type IDs for entities).
u8 tilesetatt
 Tile attribute table (collision flags per tile index).
u8 tilesetdef
 BG1 tileset tile data (4bpp) – start label.

Detailed Description

Scrolling platformer with object engine and enemy AI.

Demonstrates the OpenSNES map engine and object engine working together to create a scrolling platformer with multiple entity types. The map engine handles tile-based scrolling and VRAM streaming, while the object engine manages entity lifecycle, physics, collision callbacks, and per-frame update dispatch.

Three object types are registered from C: Kit (player-controlled, slope collision), the robot insect and the patrol automaton (both patrol between two x read from the map's object layer, and turn at each end). Object spawn positions are loaded from the map's object layer. The level is roofs with ramps at 45 and 22.5 degrees and vents to jump over, the far towers behind on BG2.

The dynamic sprite engine handles animated 32x32 sprites with automatic VRAM tile management, freeing the game logic from manual tile uploads.

This began as the PVSnesLib mapandobjects example by Alekmaul; the level, its tiles and the three characters are ours (devtools/art_assets/build.py writes the level from assets/neo-lumen/).

SNES Concepts
  • Map engine: tile scrolling with mapLoad/mapUpdate/mapVblank pipeline
  • Object engine: entity registration, spawn from map data, update callbacks
  • Dynamic sprite engine: automatic VRAM tile allocation for animated sprites
  • Multiple sprite palettes via CGRAM bank indexing
  • SC_64x32 tilemap for horizontal scrolling levels
  • Assembly bank byte resolution for cross-bank function pointers
What to Observe
  • Kit walks up and down the ramps and jumps over the vents
  • Robot insects and automatons patrol back and forth on the roofs
  • The far towers behind scroll at a quarter of the camera's speed
  • Camera scrolls to follow Kit's position
  • All entities animate independently with the dynamic sprite engine
Modules Used
console, sprite, sprite_dynamic, sprite_lut, dma, input, background, map, object
See also
map.h, object.h, sprite.h, background.h, input.h

Function Documentation

◆ main()

int main ( void )

Main entry point – scrolling platformer with map and object engines.

Initializes the map engine (BG1 tileset + tilemap), object engine (entity registration and spawning), and dynamic sprite engine (animated 32x32 sprites). The main loop follows the standard OpenSNES game pipeline:

Active display: mapUpdate() + objUpdateAll() + sprite end-frame VBlank: mapVblank() + oamVramQueueUpdate()

Object callbacks (Kit, the insect, the automaton) handle their own physics, collision, animation, and sprite drawing within objUpdateAll().

Returns
0 (never reached – infinite game loop)

Variable Documentation

◆ maplevel

u8 maplevel
extern

Map data (tile indices for the scrolling level layout).

◆ nbobjects

u16 nbobjects

Shared sprite palette for all entity types (BGR555).

Running count of active objects in the level.

Initialized to 1 (Kit is always object 0) and incremented as enemies are loaded from the map's object layer by objLoadObjects().

◆ objlevel

u8 objlevel
extern

Object layer data (spawn positions and type IDs for entities).

◆ tilesetatt

u8 tilesetatt
extern

Tile attribute table (collision flags per tile index).

◆ tilesetdef

u8 tilesetdef
extern

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

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

BG1 tileset palette (BGR555, 16 colors)

Tile definition table (visual properties per tile index)