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

The round: walk Kit to GOAL shards before the clock runs out. More...

#include <snes.h>
#include <snes/input.h>
#include <snes/text.h>
#include <snes/vramqueue.h>
#include <snes/debug.h>
#include "res/field.inc"
#include "res/cast.inc"
#include "game.h"
#include "screen.h"

Macros

#define PLAYER_SPEED   2
Frames of res/cast.png: Kit 32x32 four a row, then the shard 16x16
#define FRAME_DOWN   0
#define FRAME_RIGHT   10
#define FRAME_UP   5
#define TILE_SHARD   256
The field Kit's box may cover (inside the kerb, under the HUD)
#define PX_MAX   232
#define PX_MIN   16
#define PY_MAX   200
#define PY_MIN   32

Functions

static void drawHud (void)
 Refresh the two HUD numbers (clear the field first so a shorter number never smears).
static void drawSprites (void)
 Draw Kit and the shard; the box sits at Kit's feet.
static u16 kit_tile (u16 f)
 The OAM tile of Kit's frame f (32x32 frames are 4x4 tiles, rows 16 tiles wide).
static void placeShard (void)
 Put the next shard of the table on the field.
static void playClose (void)
 Close hook: the sprites and the HUD do not outlive the round.
void playRun (void)
 One round: returns when the goal is reached or the clock is out.
static void update (u16 held)
 One image of play. Flat u8/u16 only: no call through a pointer in the hot loop.

Variables

static u8 facing
static u8 facing_left
static u8 moving
u8 play_px
 Kit's pickup box (top-left corner). Named globals: the tests read them.
u8 play_py
u8 play_secs
 Seconds left, for the HUD.
u8 play_shards
 Shards collected this round.
u8 play_sx
 The current shard's box.
u8 play_sy
u16 play_time
 Frames since the round began.
static const u8 shard_pos [5 *2]
 Where the shards appear, in order: x, y of the 8x8 pickup box.
static u8 tick

Detailed Description

The round: walk Kit to GOAL shards before the clock runs out.

The shards come in a fixed order (a table), not at random: a round is the same every time, which is what lets a test play it with a scripted pad.

Macro Definition Documentation

◆ FRAME_DOWN

#define FRAME_DOWN   0

Kit walking down: frames 0-4

◆ FRAME_RIGHT

#define FRAME_RIGHT   10

walking right: 10-14; left mirrored

◆ FRAME_UP

#define FRAME_UP   5

walking up: 5-9

◆ PLAYER_SPEED

#define PLAYER_SPEED   2

◆ PX_MAX

#define PX_MAX   232

◆ PX_MIN

#define PX_MIN   16

◆ PY_MAX

#define PY_MAX   200

◆ PY_MIN

#define PY_MIN   32

◆ TILE_SHARD

#define TILE_SHARD   256

the shard's frame k is tile 256 + 2k

Function Documentation

◆ drawHud()

void drawHud ( void )
static

Refresh the two HUD numbers (clear the field first so a shorter number never smears).

◆ drawSprites()

void drawSprites ( void )
static

Draw Kit and the shard; the box sits at Kit's feet.

< the shard's frame k is tile 256 + 2k

◆ kit_tile()

u16 kit_tile ( u16 f)
static

The OAM tile of Kit's frame f (32x32 frames are 4x4 tiles, rows 16 tiles wide).

◆ placeShard()

void placeShard ( void )
static

Put the next shard of the table on the field.

◆ playClose()

void playClose ( void )
static

Close hook: the sprites and the HUD do not outlive the round.

◆ playRun()

void playRun ( void )

One round: returns when the goal is reached or the clock is out.

< the play square

< frames on the clock: 30 s at 60 Hz

< Kit walking down: frames 0-4

< shards to collect

< frames on the clock: 30 s at 60 Hz

< shards to collect

◆ update()

void update ( u16 held)
static

One image of play. Flat u8/u16 only: no call through a pointer in the hot loop.

< walking right: 10-14; left mirrored

< walking right: 10-14; left mirrored

< walking up: 5-9

< Kit walking down: frames 0-4

< shards to collect

< shards to collect

Variable Documentation

◆ facing

u8 facing
static

◆ facing_left

u8 facing_left
static

◆ moving

u8 moving
static

◆ play_px

u8 play_px

Kit's pickup box (top-left corner). Named globals: the tests read them.

◆ play_py

u8 play_py

◆ play_secs

u8 play_secs

Seconds left, for the HUD.

◆ play_shards

u8 play_shards

Shards collected this round.

◆ play_sx

u8 play_sx

The current shard's box.

◆ play_sy

u8 play_sy

◆ play_time

u16 play_time

Frames since the round began.

◆ shard_pos

const u8 shard_pos[5 *2]
static
Initial value:
= {
152, 112,
152, 80,
120, 80,
120, 144,
168, 144
}

Where the shards appear, in order: x, y of the 8x8 pickup box.

◆ tick

u8 tick
static