forked from tas/major_tom
Add in-game level editor with auto-discovered tile/entity palettes
Implements a full level editor that runs inside the game engine as an alternative mode, accessible via --edit flag or E key during gameplay. The editor auto-discovers available tiles from the tileset texture and entities from a new central registry, so adding new game content automatically appears in the editor without any editor-specific changes. Editor features: tile painting (pencil/eraser/flood fill) across 3 layers, entity placement with drag-to-move, player spawn point tool, camera pan/zoom, grid overlay, .lvl save/load, map resize, and test play (P to play, ESC to return to editor). Supporting changes: - Entity registry centralizes spawn functions (replaces strcmp chain) - Mouse input + raw keyboard access added to input system - Camera zoom support for editor overview - Zoom-aware rendering in tilemap, renderer, and sprite systems - Powerup and drone sprites/animations wired up (were defined but unused) - Bitmap font renderer for editor UI (4x6 pixel glyphs, no dependencies)
This commit is contained in:
61
src/game/levelgen.h
Normal file
61
src/game/levelgen.h
Normal file
@@ -0,0 +1,61 @@
|
||||
#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_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);
|
||||
|
||||
/* 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);
|
||||
|
||||
/* 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 */
|
||||
Reference in New Issue
Block a user