diff options
Diffstat (limited to 'gfx-iso/app/isogfx-demo.c')
-rw-r--r-- | gfx-iso/app/isogfx-demo.c | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/gfx-iso/app/isogfx-demo.c b/gfx-iso/app/isogfx-demo.c new file mode 100644 index 0000000..15ab6be --- /dev/null +++ b/gfx-iso/app/isogfx-demo.c | |||
@@ -0,0 +1,67 @@ | |||
1 | #include "isogfx-demo.h" | ||
2 | |||
3 | #include <gfx/gfx_app.h> | ||
4 | #include <isogfx/isogfx.h> | ||
5 | |||
6 | #include <assert.h> | ||
7 | #include <stdbool.h> | ||
8 | #include <stdio.h> | ||
9 | #include <stdlib.h> | ||
10 | |||
11 | typedef struct State { | ||
12 | int xpick; | ||
13 | int ypick; | ||
14 | } State; | ||
15 | |||
16 | static void shutdown(IsoGfx* iso, void* app_state) { | ||
17 | assert(iso); | ||
18 | if (app_state) { | ||
19 | free(app_state); | ||
20 | } | ||
21 | } | ||
22 | |||
23 | static void update(IsoGfx* iso, void* app_state, double t, double dt) { | ||
24 | assert(iso); | ||
25 | assert(app_state); | ||
26 | State* state = (State*)(app_state); | ||
27 | |||
28 | double mouse_x, mouse_y; | ||
29 | gfx_app_get_mouse_position(&mouse_x, &mouse_y); | ||
30 | |||
31 | isogfx_pick_tile(iso, mouse_x, mouse_y, &state->xpick, &state->ypick); | ||
32 | |||
33 | // printf("Picked tile: (%d, %d)\n", state->xpick, state->ypick); | ||
34 | } | ||
35 | |||
36 | static void render(IsoGfx* iso, void* app_state) { | ||
37 | assert(iso); | ||
38 | assert(app_state); | ||
39 | State* state = (State*)(app_state); | ||
40 | |||
41 | isogfx_render(iso); | ||
42 | } | ||
43 | |||
44 | bool make_demo_app(IsoGfx* iso, IsoGfxApp* app) { | ||
45 | assert(iso); | ||
46 | assert(app); | ||
47 | |||
48 | State* state = calloc(1, sizeof(State)); | ||
49 | if (!state) { | ||
50 | return false; | ||
51 | } | ||
52 | |||
53 | if (!isogfx_load_world(iso, "/home/jeanne/assets/tilemaps/demo1.tm")) { | ||
54 | goto cleanup; | ||
55 | } | ||
56 | |||
57 | app->state = state; | ||
58 | app->shutdown = shutdown; | ||
59 | app->update = update; | ||
60 | app->render = render; | ||
61 | |||
62 | return true; | ||
63 | |||
64 | cleanup: | ||
65 | free(state); | ||
66 | return false; | ||
67 | } | ||