Files
major_tom/src/engine/parallax.h
Thomas fac7085056 Add moon surface intro level with asteroid hazards and unarmed mechanics
Introduce moon01.lvl as the starting level — a pure jump-and-run intro
with no gun and no enemies, just platforming over gaps and dodging falling
asteroids. The player picks up their gun upon transitioning to level01.

New features:
- Moon tileset and PARALLAX_STYLE_MOON with crater terrain backgrounds
- Asteroid entity (ENT_ASTEROID): falls from sky, damages on contact,
  explodes on ground with particles, respawns after delay
- PLAYER_UNARMED directive disables gun for the level
- Pit rescue mechanic: falling costs 1 HP and auto-dashes upward
- Gun powerup entity type for future armed-pickup levels
- Segment-based procedural level generator with themed rooms
- Extended editor with entity palette and improved tile cycling
- Web shell improvements for Emscripten builds
2026-03-01 09:20:49 +00:00

59 lines
2.4 KiB
C

#ifndef JNR_PARALLAX_H
#define JNR_PARALLAX_H
#include <SDL2/SDL.h>
#include <stdbool.h>
#include "config.h"
/* Forward declarations */
typedef struct Camera Camera;
/* A single parallax layer */
typedef struct ParallaxLayer {
SDL_Texture *texture; /* the background image */
int tex_w, tex_h; /* texture dimensions in pixels */
float scroll_x; /* horizontal scroll factor (0=fixed, 1=full) */
float scroll_y; /* vertical scroll factor */
bool active; /* whether this layer is in use */
bool owns_texture; /* true if we generated it (must free) */
} ParallaxLayer;
/* Parallax background system — up to two layers */
typedef struct Parallax {
ParallaxLayer far_layer; /* distant background (stars) */
ParallaxLayer near_layer; /* mid-ground background (nebula) */
} Parallax;
/* Initialize parallax (zeroes everything) */
void parallax_init(Parallax *p);
/* Set a layer from an existing texture (loaded via assets) */
void parallax_set_far(Parallax *p, SDL_Texture *tex, float scroll_x, float scroll_y);
void parallax_set_near(Parallax *p, SDL_Texture *tex, float scroll_x, float scroll_y);
/* Generate procedural starfield texture (far layer) */
void parallax_generate_stars(Parallax *p, SDL_Renderer *renderer);
/* Generate procedural nebula/dust texture (near layer) */
void parallax_generate_nebula(Parallax *p, SDL_Renderer *renderer);
/* Themed parallax generation styles */
typedef enum ParallaxStyle {
PARALLAX_STYLE_DEFAULT, /* generic space (same as stars+nebula) */
PARALLAX_STYLE_ALIEN_SKY, /* alien planet surface: dusty, hazy */
PARALLAX_STYLE_INTERIOR, /* indoor base: panels, pipes, structural */
PARALLAX_STYLE_DEEP_SPACE, /* space station windows: vivid stars */
PARALLAX_STYLE_MOON, /* moon surface: craters, grey terrain */
} ParallaxStyle;
/* Generate both layers with a unified style */
void parallax_generate_themed(Parallax *p, SDL_Renderer *renderer, ParallaxStyle style);
/* Render both layers (call before tile/entity rendering) */
void parallax_render(const Parallax *p, const Camera *cam, SDL_Renderer *renderer);
/* Free generated textures (not file-loaded ones — asset manager owns those) */
void parallax_free(Parallax *p);
#endif /* JNR_PARALLAX_H */