From a19049d7a6bed9b236c5e714dde844925750e39d Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sat, 19 Jul 2025 13:23:29 -0700 Subject: Implement camera pan --- demos/isomap/isomap.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'demos/isomap') diff --git a/demos/isomap/isomap.c b/demos/isomap/isomap.c index efae7fd..a940535 100644 --- a/demos/isomap/isomap.c +++ b/demos/isomap/isomap.c @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -15,6 +16,8 @@ static const int MAX_FPS = 60; static const int SCREEN_WIDTH = 704; static const int SCREEN_HEIGHT = 480; +static const R CAMERA_SPEED = 400; + #define MEMORY_SIZE (2 * 1024 * 1024) uint8_t MEMORY[MEMORY_SIZE]; @@ -23,6 +26,7 @@ typedef struct GfxAppState { IsoGfx* iso; int xpick; int ypick; + vec2 camera; SpriteSheet stag_sheet; Sprite stag; } GfxAppState; @@ -67,11 +71,33 @@ static void shutdown(GfxAppState* state) { // } +static vec2 get_camera_movement(R dt) { + vec2 offset = {0}; + if (gfx_app_is_key_pressed(KeyA)) { + offset.x -= 1; + } + if (gfx_app_is_key_pressed(KeyD)) { + offset.x += 1; + } + if (gfx_app_is_key_pressed(KeyW)) { + offset.y -= 1; + } + if (gfx_app_is_key_pressed(KeyS)) { + offset.y += 1; + } + if ((offset.x != 0) || (offset.y != 0)) { + offset = vec2_scale(vec2_normalize(offset), dt * CAMERA_SPEED); + } + return offset; +} + static void update(GfxAppState* state, double t, double dt) { assert(state); - (void)dt; + + state->camera = vec2_add(state->camera, get_camera_movement((R)dt)); IsoGfx* iso = state->iso; + isogfx_set_camera(iso, (int)state->camera.x, (int)state->camera.y); isogfx_update(iso, t); } -- cgit v1.2.3