forked from tas/major_tom
Implement four feature phases: Phase 1 - Pause menu: extract bitmap font into shared engine/font module, add MODE_PAUSED with Resume/Restart/Quit overlay. Phase 2 - Laser turret hazard: ENT_LASER_TURRET with charge/fire/ cooldown state machine, per-pixel beam raycast, two variants (fixed and tracking). Registered in entity registry with editor icons. Phase 3 - Charger and Spawner enemies: charger ground patrol with detect/telegraph/charge/stun cycle (2s charge timeout), spawner that periodically creates grunts up to a global cap of 3. Phase 4 - Mars campaign: two handcrafted levels (mars01 surface, mars02 base), mars_tileset.png, PARALLAX_STYLE_MARS with salmon sky and red mesas, THEME_MARS_SURFACE/THEME_MARS_BASE for the procedural generator with per-theme gravity/tileset/parallax. Moon campaign now chains moon03 -> mars01 -> mars02 -> victory. Also fix review findings: deterministic seed on generated level restart, NULL checks on calloc in spawn functions, charge timeout to prevent infinite charge on flat terrain, and stop suppressing stderr in Makefile web-serve target so real errors are visible.
79 lines
3.4 KiB
C
79 lines
3.4 KiB
C
#ifndef JNR_LEVELGEN_H
|
|
#define JNR_LEVELGEN_H
|
|
|
|
#include "engine/tilemap.h"
|
|
#include <stdint.h>
|
|
|
|
/* ═══════════════════════════════════════════════════
|
|
* Procedural Level Generator
|
|
*
|
|
* Generates a Tilemap directly in memory by stitching
|
|
* together segment templates. Supports:
|
|
* - Mixed layouts (horizontal, vertical, arena)
|
|
* - Enemy and hazard placement
|
|
* - Difficulty scaling via seed
|
|
* - Dumping to .lvl format for inspection
|
|
* ═══════════════════════════════════════════════════ */
|
|
|
|
/* Level theme — affects layout, hazards, gravity, atmosphere */
|
|
typedef enum LevelTheme {
|
|
THEME_PLANET_SURFACE, /* alien planet exterior: open terrain, pits,
|
|
flame vents, harsh conditions, high gravity */
|
|
THEME_PLANET_BASE, /* research outpost on a planet: corridors,
|
|
force fields, turrets, medium gravity */
|
|
THEME_SPACE_STATION, /* orbital station: shafts, platforms, low
|
|
gravity, moving platforms, turrets */
|
|
THEME_MARS_SURFACE, /* Mars exterior: red dusty terrain, wind,
|
|
wide-open with charger enemies */
|
|
THEME_MARS_BASE, /* Mars base interior: very vertical, narrow
|
|
corridors, turrets, laser turrets, spawners*/
|
|
THEME_COUNT
|
|
} LevelTheme;
|
|
|
|
#define MAX_THEME_SEQUENCE 10
|
|
|
|
/* Generator configuration */
|
|
typedef struct LevelGenConfig {
|
|
uint32_t seed; /* RNG seed (0 = random from time) */
|
|
int num_segments; /* how many segments to stitch (2-10) */
|
|
float difficulty; /* 0.0 = easy, 1.0 = hard */
|
|
float gravity; /* level gravity override (0 = auto) */
|
|
|
|
/* Theme sequence: one theme per segment.
|
|
* If theme_count == 0, all segments use themes[0].
|
|
* If theme_count > 0, segment i uses themes[min(i, theme_count-1)].
|
|
* Transition segments are auto-inserted at theme boundaries. */
|
|
LevelTheme themes[MAX_THEME_SEQUENCE];
|
|
int theme_count; /* number of entries in themes[] */
|
|
} LevelGenConfig;
|
|
|
|
/* Default config for quick generation */
|
|
LevelGenConfig levelgen_default_config(void);
|
|
|
|
/* Config preset for a space station level:
|
|
* very long horizontally, narrow playable area,
|
|
* near-zero gravity, all THEME_SPACE_STATION.
|
|
* depth (0-based) escalates difficulty and length
|
|
* with each subsequent station level. */
|
|
LevelGenConfig levelgen_station_config(uint32_t seed, int depth);
|
|
|
|
/* Generate a level directly into a Tilemap struct.
|
|
* The Tilemap will have layers allocated, tile defs set,
|
|
* entity spawns populated, and metadata configured.
|
|
* Caller must eventually call tilemap_free() on it.
|
|
* Returns true on success. */
|
|
bool levelgen_generate(Tilemap *map, const LevelGenConfig *config);
|
|
|
|
/* Generate a space-station level: very long, narrow,
|
|
* near-zero gravity. Uses its own segment pool tuned
|
|
* for horizontal layouts in tight corridors.
|
|
* Returns true on success. */
|
|
bool levelgen_generate_station(Tilemap *map, const LevelGenConfig *config);
|
|
|
|
/* Dump a generated (or any) Tilemap to a .lvl file.
|
|
* Useful for inspecting/editing procedural output.
|
|
* Returns true on success. */
|
|
bool levelgen_dump_lvl(const Tilemap *map, const char *path);
|
|
|
|
#endif /* JNR_LEVELGEN_H */
|