Files
major_tom/src/game/spacecraft.h
Thomas 49ed2d6f7b Add spatial audio, spacecraft entity, and level intro sequence
Distance-based sound effects with stereo panning for explosions, impacts,
and pickups. Spacecraft entity with full state machine (fly-in, land, take
off, fly-out), engine/synth sound loops, thruster particles, and PNG
spritesheet. Moon level intro defers player spawn until ship lands.

Also untrack build/ objects that were committed by mistake.
2026-03-01 11:00:51 +00:00

71 lines
2.9 KiB
C

#ifndef JNR_SPACECRAFT_H
#define JNR_SPACECRAFT_H
#include "engine/entity.h"
#include "engine/animation.h"
/* ═══════════════════════════════════════════════════
* Spacecraft
*
* The player's ship. Appears at level start (fly-in
* and landing sequence) and at exit zones (landing
* and fly-out when the player reaches the exit).
*
* Spritesheet: assets/sprites/spacecraft.png
* Layout: 5 frames at 80x48, horizontal strip
* 0 = landed/idle
* 1 = landing frame 1 (high, bright thrusters)
* 2 = landing frame 2 (mid, medium thrusters)
* 3 = landing frame 3 (low, dim thrusters)
* 4 = landing frame 4 (touchdown)
* ═══════════════════════════════════════════════════ */
/* Source sprite dimensions (pixels in PNG) */
#define SPACECRAFT_SRC_W 80
#define SPACECRAFT_SRC_H 48
/* Render scale — drawn larger than the source art */
#define SPACECRAFT_SCALE 2.0f
/* Rendered dimensions (used for hitbox/positioning) */
#define SPACECRAFT_WIDTH ((int)(SPACECRAFT_SRC_W * SPACECRAFT_SCALE))
#define SPACECRAFT_HEIGHT ((int)(SPACECRAFT_SRC_H * SPACECRAFT_SCALE))
/* State machine */
typedef enum SpacecraftState {
SC_FLYING_IN, /* approaching from off-screen */
SC_LANDING, /* playing landing animation */
SC_LANDED, /* on the ground, idle */
SC_TAKEOFF, /* playing takeoff animation (reverse landing) */
SC_FLYING_OUT, /* departing off-screen */
SC_DONE /* sequence complete, can be removed */
} SpacecraftState;
typedef struct SpacecraftData {
SpacecraftState state;
float state_timer; /* time spent in current state */
Vec2 target_pos; /* where to land (ground level) */
Vec2 start_pos; /* fly-in origin (off-screen) */
float fly_speed; /* pixels/s during fly in/out */
bool is_exit_ship; /* true = exit ship, false = intro ship */
int engine_channel; /* SDL_mixer channel for engine loop, -1 = none */
} SpacecraftData;
/* Register the spacecraft entity type */
void spacecraft_register(EntityManager *em);
/* Spawn a spacecraft that will fly in and land at the given position.
* The position is the bottom-center of where the ship should land. */
Entity *spacecraft_spawn(EntityManager *em, Vec2 land_pos);
/* Trigger takeoff on an existing landed spacecraft */
void spacecraft_takeoff(Entity *ship);
/* Check if the spacecraft has finished its full sequence */
bool spacecraft_is_done(const Entity *ship);
/* Check if the spacecraft is in the landed state */
bool spacecraft_is_landed(const Entity *ship);
#endif /* JNR_SPACECRAFT_H */