OpenSNES
Modern Open-Source SNES Development SDK
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
Entity bullets [8]
Entity enemies [8]
u8 fire_cd
u16 frame
s16 player_x
s16 player_y
u16 prng
u16 scroll_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};
signed short s16
16-bit signed integer (-32768 to 32767)
Definition types.h:50
unsigned short u16
16-bit unsigned integer (0 to 65535)
Definition types.h:53
s16 player_y
Definition main.c:103
s16 player_x
Definition main.c:102
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

◆ bullets

Entity GameState::bullets[8]

◆ enemies

Entity GameState::enemies[8]

◆ fire_cd

u8 GameState::fire_cd

◆ frame

u16 GameState::frame

◆ 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

◆ prng

u16 GameState::prng

◆ scroll_y

u16 GameState::scroll_y

The documentation for this struct was generated from the following files:
  • /home/runner/work/opensnes/opensnes/examples/games/shmup_1942/main.c
  • /home/runner/work/opensnes/opensnes/examples/scrolling/continuous_scroll/main.c