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)
40 lines
1.6 KiB
C
40 lines
1.6 KiB
C
#ifndef JNR_CAMERA_H
|
|
#define JNR_CAMERA_H
|
|
|
|
#include "util/vec2.h"
|
|
#include "config.h"
|
|
|
|
typedef struct Camera {
|
|
Vec2 pos; /* world position of top-left corner */
|
|
Vec2 viewport; /* screen dimensions in game pixels */
|
|
Vec2 bounds_min; /* level bounds (top-left) */
|
|
Vec2 bounds_max; /* level bounds (bottom-right) */
|
|
float smoothing; /* higher = slower follow (0=instant) */
|
|
Vec2 deadzone; /* half-size of deadzone rect */
|
|
Vec2 look_ahead; /* pixels to lead in move direction */
|
|
/* Zoom (used by editor; gameplay keeps 1.0) */
|
|
float zoom; /* 1.0 = normal, <1 = zoomed out */
|
|
/* Screen shake */
|
|
float shake_timer; /* remaining shake time */
|
|
float shake_intensity; /* current max pixel offset */
|
|
Vec2 shake_offset; /* current frame shake displacement */
|
|
} Camera;
|
|
|
|
void camera_init(Camera *c, float vp_w, float vp_h);
|
|
void camera_set_bounds(Camera *c, float world_w, float world_h);
|
|
void camera_follow(Camera *c, Vec2 target, Vec2 velocity, float dt);
|
|
|
|
/* Convert world position to screen position */
|
|
Vec2 camera_world_to_screen(const Camera *c, Vec2 world_pos);
|
|
|
|
/* Convert screen position to world position */
|
|
Vec2 camera_screen_to_world(const Camera *c, Vec2 screen_pos);
|
|
|
|
/* Trigger screen shake (intensity in pixels, duration in seconds) */
|
|
void camera_shake(Camera *c, float intensity, float duration);
|
|
|
|
/* Update shake (call once per frame, after camera_follow) */
|
|
void camera_update_shake(Camera *c, float dt);
|
|
|
|
#endif /* JNR_CAMERA_H */
|