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

Mode 7 flying — a Pilotwings-style demo (#4, part 2). More...

#include <snes.h>
#include <snes/mode7.h>
#include <snes/math.h>
#include <snes/input.h>

Macros

#define CLIMB_STEP   6
#define LAND_SPEED   0x00E0 /* max speed for a good landing */
#define MAX_ALT   0x0480
#define MAX_SPEED   0x0280
#define MIN_FLY_SPEED   0x0080 /* below this the plane sinks */
#define PLANE_SCREEN_X   120
 Screen position of the plane (and its shadow's origin).
#define PLANE_SCREEN_Y   140
#define THROTTLE_STEP   4
 Flight model tuning (8.8 fixed).

Functions

static void build_plane (void)
 Draw the plane silhouette (index 1 body, 2 canopy).
static void encode_16x16 (u8 pix[16][16])
 Encode a 16x16 palette-index grid into 4bpp OBJ quadrants.
int main (void)
u8 terrain_class_at (u16 idx)
 Banked-data accessor (data.asm) for the class map.

Variables

u8 airborne
u8 landings
u16 plane_alt
u8 plane_heading
u16 plane_speed
u16 plane_x
 Probe oracles / game state.
u16 plane_y
static u8 shape_tiles [128]
 4 8x8 4bpp tiles = one 16x16 shape (built at init)
u8 surface
u8 terrain_map []
u8 terrain_map_end []
u8 terrain_pal []
u8 terrain_pal_end []
u8 terrain_til []
u8 terrain_til_end []

Detailed Description

Mode 7 flying — a Pilotwings-style demo (#4, part 2).

A plane over a Mode 7 landscape. The core trick: altitude drives the Mode 7 scale — climbing zooms the plane texture out (you see more terrain), diving zooms in, and a shadow sprite slides away from the plane as you climb: the two classic SNES depth cues, from two register writes per frame.

  • D-pad left/right: turn — up: climb — down: dive
  • A: throttle up — B: throttle down
  • Objective: land on the three striped pads (slow + low over a pad). The backdrop flashes green on a good landing; water is a splash (respawn); fields bounce you back up.

ROM mode: LoROM (project default).

SNES Concepts
  • Altitude as Mode 7 scale: mode7SetScale(0x0100 + alt) then SetAngle (the scale feeds the matrix at SetAngle time)
  • The shadow depth cue: same sprite shape, dark palette, screen offset proportional to altitude
  • Surface classes read through a banked-data ASM accessor (B2 — same pattern as mode7_racing)
  • Fixed-point flight model: heading/speed/altitude in 8.8, the math module's shared 0-255 angle unit
What to Observe
Take off (hold A, then Up): the fields shrink and the shadow drifts down-screen. Line up a pad, throttle down, descend — a green flash counts the landing. Ditch in the river to see the respawn.
Modules Used
console, dma, background, sprite, math, mode7, input
See also
gen_terrain.py — the reproducible terrain generator

Macro Definition Documentation

◆ CLIMB_STEP

#define CLIMB_STEP   6

◆ LAND_SPEED

#define LAND_SPEED   0x00E0 /* max speed for a good landing */

◆ MAX_ALT

#define MAX_ALT   0x0480

◆ MAX_SPEED

#define MAX_SPEED   0x0280

◆ MIN_FLY_SPEED

#define MIN_FLY_SPEED   0x0080 /* below this the plane sinks */

◆ PLANE_SCREEN_X

#define PLANE_SCREEN_X   120

Screen position of the plane (and its shadow's origin).

◆ PLANE_SCREEN_Y

#define PLANE_SCREEN_Y   140

◆ THROTTLE_STEP

#define THROTTLE_STEP   4

Flight model tuning (8.8 fixed).

Function Documentation

◆ build_plane()

void build_plane ( void )
static

Draw the plane silhouette (index 1 body, 2 canopy).

◆ encode_16x16()

void encode_16x16 ( u8 pix[16][16])
static

Encode a 16x16 palette-index grid into 4bpp OBJ quadrants.

◆ main()

int main ( void )

◆ terrain_class_at()

u8 terrain_class_at ( u16 idx)
extern

Banked-data accessor (data.asm) for the class map.

Variable Documentation

◆ airborne

u8 airborne

◆ landings

u8 landings

◆ plane_alt

u16 plane_alt

◆ plane_heading

u8 plane_heading

◆ plane_speed

u16 plane_speed

◆ plane_x

u16 plane_x

Probe oracles / game state.

◆ plane_y

u16 plane_y

◆ shape_tiles

u8 shape_tiles[128]
static

4 8x8 4bpp tiles = one 16x16 shape (built at init)

◆ surface

u8 surface

◆ terrain_map

u8 terrain_map[]
extern

◆ terrain_map_end

u8 terrain_map_end[]

◆ terrain_pal

u8 terrain_pal[]
extern

◆ terrain_pal_end

u8 terrain_pal_end[]

◆ terrain_til

u8 terrain_til[]
extern

◆ terrain_til_end

u8 terrain_til_end[]