diff options
author | 3gg <3gg@shellblade.net> | 2025-07-19 13:23:29 -0700 |
---|---|---|
committer | 3gg <3gg@shellblade.net> | 2025-07-19 13:23:29 -0700 |
commit | a19049d7a6bed9b236c5e714dde844925750e39d (patch) | |
tree | 0113934ffe8e94fc2e20c4248886a1b79ae64a55 /demos/isomap | |
parent | 6e0913a3f77354eab2eeceba66db7d1750e22581 (diff) |
Implement camera pan
Diffstat (limited to 'demos/isomap')
-rw-r--r-- | demos/isomap/isomap.c | 28 |
1 files changed, 27 insertions, 1 deletions
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 @@ | |||
2 | #include <isogfx/isogfx.h> | 2 | #include <isogfx/isogfx.h> |
3 | 3 | ||
4 | #include <gfx/app.h> | 4 | #include <gfx/app.h> |
5 | #include <math/vec2.h> | ||
5 | 6 | ||
6 | #include <assert.h> | 7 | #include <assert.h> |
7 | #include <stdbool.h> | 8 | #include <stdbool.h> |
@@ -15,6 +16,8 @@ static const int MAX_FPS = 60; | |||
15 | static const int SCREEN_WIDTH = 704; | 16 | static const int SCREEN_WIDTH = 704; |
16 | static const int SCREEN_HEIGHT = 480; | 17 | static const int SCREEN_HEIGHT = 480; |
17 | 18 | ||
19 | static const R CAMERA_SPEED = 400; | ||
20 | |||
18 | #define MEMORY_SIZE (2 * 1024 * 1024) | 21 | #define MEMORY_SIZE (2 * 1024 * 1024) |
19 | uint8_t MEMORY[MEMORY_SIZE]; | 22 | uint8_t MEMORY[MEMORY_SIZE]; |
20 | 23 | ||
@@ -23,6 +26,7 @@ typedef struct GfxAppState { | |||
23 | IsoGfx* iso; | 26 | IsoGfx* iso; |
24 | int xpick; | 27 | int xpick; |
25 | int ypick; | 28 | int ypick; |
29 | vec2 camera; | ||
26 | SpriteSheet stag_sheet; | 30 | SpriteSheet stag_sheet; |
27 | Sprite stag; | 31 | Sprite stag; |
28 | } GfxAppState; | 32 | } GfxAppState; |
@@ -67,11 +71,33 @@ static void shutdown(GfxAppState* state) { | |||
67 | // | 71 | // |
68 | } | 72 | } |
69 | 73 | ||
74 | static vec2 get_camera_movement(R dt) { | ||
75 | vec2 offset = {0}; | ||
76 | if (gfx_app_is_key_pressed(KeyA)) { | ||
77 | offset.x -= 1; | ||
78 | } | ||
79 | if (gfx_app_is_key_pressed(KeyD)) { | ||
80 | offset.x += 1; | ||
81 | } | ||
82 | if (gfx_app_is_key_pressed(KeyW)) { | ||
83 | offset.y -= 1; | ||
84 | } | ||
85 | if (gfx_app_is_key_pressed(KeyS)) { | ||
86 | offset.y += 1; | ||
87 | } | ||
88 | if ((offset.x != 0) || (offset.y != 0)) { | ||
89 | offset = vec2_scale(vec2_normalize(offset), dt * CAMERA_SPEED); | ||
90 | } | ||
91 | return offset; | ||
92 | } | ||
93 | |||
70 | static void update(GfxAppState* state, double t, double dt) { | 94 | static void update(GfxAppState* state, double t, double dt) { |
71 | assert(state); | 95 | assert(state); |
72 | (void)dt; | 96 | |
97 | state->camera = vec2_add(state->camera, get_camera_movement((R)dt)); | ||
73 | 98 | ||
74 | IsoGfx* iso = state->iso; | 99 | IsoGfx* iso = state->iso; |
100 | isogfx_set_camera(iso, (int)state->camera.x, (int)state->camera.y); | ||
75 | isogfx_update(iso, t); | 101 | isogfx_update(iso, t); |
76 | } | 102 | } |
77 | 103 | ||