summaryrefslogtreecommitdiff
path: root/gfx-iso/app/isogfx-demo.c
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2023-07-08 14:37:29 -0700
committer3gg <3gg@shellblade.net>2023-07-08 14:37:29 -0700
commit21a0d0c1c424f7db90c3282aad4bf6ad4ef809b7 (patch)
treea6ae8a8cb4108cd33713178e67d3b482fc1fd5ee /gfx-iso/app/isogfx-demo.c
parent303f5dc58dd8e8266df3c62fc84d9799db8047b9 (diff)
Load tile maps and tile sets from files.
Diffstat (limited to 'gfx-iso/app/isogfx-demo.c')
-rw-r--r--gfx-iso/app/isogfx-demo.c67
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
11typedef struct State {
12 int xpick;
13 int ypick;
14} State;
15
16static void shutdown(IsoGfx* iso, void* app_state) {
17 assert(iso);
18 if (app_state) {
19 free(app_state);
20 }
21}
22
23static 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
36static 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
44bool 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
64cleanup:
65 free(state);
66 return false;
67}