summaryrefslogtreecommitdiff
path: root/demos
diff options
context:
space:
mode:
Diffstat (limited to 'demos')
-rw-r--r--demos/isomap/isomap.c28
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;
15static const int SCREEN_WIDTH = 704; 16static const int SCREEN_WIDTH = 704;
16static const int SCREEN_HEIGHT = 480; 17static const int SCREEN_HEIGHT = 480;
17 18
19static const R CAMERA_SPEED = 400;
20
18#define MEMORY_SIZE (2 * 1024 * 1024) 21#define MEMORY_SIZE (2 * 1024 * 1024)
19uint8_t MEMORY[MEMORY_SIZE]; 22uint8_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
74static 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
70static void update(GfxAppState* state, double t, double dt) { 94static 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