Loading...
Searching...
No Matches
GameState Struct Reference

Centralized game state structure. More...

Public Attributes

s16 bg1_scroll_x
 
s16 bg1_scroll_y
 
s16 bg2_scroll_x
 
s16 bg2_scroll_y
 
s16 player_x
 
s16 player_y
 

Detailed Description

Centralized game state structure.

Note
IMPORTANT COMPILER PATTERN: Using a global struct with s16 types is the REQUIRED pattern for sprite coordinates in OpenSNES. The following patterns FAIL:
// BAD - causes LEFT/RIGHT movement to fail while UP/DOWN works:
static u16 player_x;
static u16 player_y;
// GOOD - all movement directions work correctly:
typedef struct { s16 x, y; } Player;
Player player = {100, 100};
static u16 bx
Definition main.c:159
signed short s16
16-bit signed integer (-32768 to 32767)
Definition types.h:49
unsigned short u16
16-bit unsigned integer (0 to 65535)
Definition types.h:52
s16 player_y
Definition main.c:95
s16 player_x
Definition main.c:94
Per-player position state.
Definition main.c:95

This is due to a compiler quirk where separate static u16 variables generate different (broken) code compared to struct member access. See .claude/KNOWLEDGE.md for detailed documentation.

See also
animated_sprite example for reference implementation

Member Data Documentation

◆ bg1_scroll_x

s16 GameState::bg1_scroll_x

BG1 horizontal scroll offset

◆ bg1_scroll_y

s16 GameState::bg1_scroll_y

BG1 vertical scroll offset

◆ bg2_scroll_x

s16 GameState::bg2_scroll_x

BG2 horizontal scroll offset (parallax)

◆ bg2_scroll_y

s16 GameState::bg2_scroll_y

BG2 vertical scroll offset

◆ player_x

s16 GameState::player_x

Player X position (screen coords) - MUST be s16

◆ player_y

s16 GameState::player_y

Player Y position (screen coords) - MUST be s16


The documentation for this struct was generated from the following file: