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:
Thomas
2026-02-28 20:24:43 +00:00
parent c66c12ae68
commit ea6e16358f
30 changed files with 4959 additions and 51 deletions

View File

@@ -129,10 +129,11 @@ void tilemap_render_layer(const Tilemap *map, const uint16_t *layer,
int end_x = map->width, end_y = map->height;
if (cam) {
float inv_zoom = (cam->zoom > 0.0f) ? (1.0f / cam->zoom) : 1.0f;
start_x = (int)(cam->pos.x / TILE_SIZE) - 1;
start_y = (int)(cam->pos.y / TILE_SIZE) - 1;
end_x = start_x + (int)(cam->viewport.x / TILE_SIZE) + 3;
end_y = start_y + (int)(cam->viewport.y / TILE_SIZE) + 3;
end_x = start_x + (int)(cam->viewport.x * inv_zoom / TILE_SIZE) + 3;
end_y = start_y + (int)(cam->viewport.y * inv_zoom / TILE_SIZE) + 3;
if (start_x < 0) start_x = 0;
if (start_y < 0) start_y = 0;
@@ -163,11 +164,16 @@ void tilemap_render_layer(const Tilemap *map, const uint16_t *layer,
Vec2 world_pos = vec2(tile_to_world(x), tile_to_world(y));
Vec2 screen_pos = cam ? camera_world_to_screen(cam, world_pos) : world_pos;
float tile_draw_size = TILE_SIZE;
if (cam && cam->zoom != 1.0f && cam->zoom > 0.0f) {
tile_draw_size = TILE_SIZE * cam->zoom;
}
SDL_Rect dst = {
(int)screen_pos.x,
(int)screen_pos.y,
TILE_SIZE,
TILE_SIZE
(int)(tile_draw_size + 0.5f),
(int)(tile_draw_size + 0.5f)
};
SDL_RenderCopy(renderer, map->tileset, &src, &dst);