summaryrefslogtreecommitdiff
path: root/gfx-iso/demos/isomap/isomap.c
diff options
context:
space:
mode:
Diffstat (limited to 'gfx-iso/demos/isomap/isomap.c')
-rw-r--r--gfx-iso/demos/isomap/isomap.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/gfx-iso/demos/isomap/isomap.c b/gfx-iso/demos/isomap/isomap.c
new file mode 100644
index 0000000..d204d28
--- /dev/null
+++ b/gfx-iso/demos/isomap/isomap.c
@@ -0,0 +1,72 @@
1#include <isogfx/app.h>
2#include <isogfx/isogfx.h>
3
4#include <assert.h>
5#include <stdbool.h>
6
7typedef struct IsoGfxAppState {
8 int xpick;
9 int ypick;
10 SpriteSheet stag_sheet;
11 Sprite stag;
12} IsoGfxAppState;
13
14static bool init(
15 IsoGfxAppState* state, IsoGfx* iso, int argc, const char** argv) {
16 assert(state);
17 assert(iso);
18
19 if (!isogfx_load_world(iso, "/home/jeanne/assets/tilemaps/demo1.tm")) {
20 return false;
21 }
22
23 if (!isogfx_load_sprite_sheet(
24 iso, "/home/jeanne/assets/tilesets/scrabling/critters/stag/stag.ss",
25 &state->stag_sheet)) {
26 return false;
27 }
28
29 state->stag = isogfx_make_sprite(iso, state->stag_sheet);
30 isogfx_set_sprite_position(iso, state->stag, 5, 4);
31
32 return true;
33}
34
35static void shutdown(IsoGfxAppState* state, IsoGfx* iso) {
36 assert(state);
37 assert(iso);
38}
39
40static void update(IsoGfxAppState* state, IsoGfx* iso, double t, double dt) {
41 assert(state);
42 assert(iso);
43
44 double mouse_x, mouse_y;
45 gfx_app_get_mouse_position(&mouse_x, &mouse_y);
46
47 isogfx_pick_tile(iso, mouse_x, mouse_y, &state->xpick, &state->ypick);
48
49 // printf("Picked tile: (%d, %d)\n", state->xpick, state->ypick);
50}
51
52static void render(IsoGfxAppState* state, IsoGfx* iso) {
53 assert(state);
54 assert(iso);
55
56 isogfx_render(iso);
57}
58
59int main(int argc, const char** argv) {
60 IsoGfxAppState state = {0};
61 iso_run(
62 argc, argv,
63 &(IsoGfxApp){
64 .pixel_scale = 2,
65 .state = &state,
66 .init = init,
67 .shutdown = shutdown,
68 .update = update,
69 .render = render,
70 });
71 return 0;
72}