From 21a0d0c1c424f7db90c3282aad4bf6ad4ef809b7 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sat, 8 Jul 2023 14:37:29 -0700 Subject: Load tile maps and tile sets from files. --- gfx-iso/app/isogfx-demo.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 gfx-iso/app/isogfx-demo.c (limited to 'gfx-iso/app/isogfx-demo.c') 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 @@ +#include "isogfx-demo.h" + +#include +#include + +#include +#include +#include +#include + +typedef struct State { + int xpick; + int ypick; +} State; + +static void shutdown(IsoGfx* iso, void* app_state) { + assert(iso); + if (app_state) { + free(app_state); + } +} + +static void update(IsoGfx* iso, void* app_state, double t, double dt) { + assert(iso); + assert(app_state); + State* state = (State*)(app_state); + + double mouse_x, mouse_y; + gfx_app_get_mouse_position(&mouse_x, &mouse_y); + + isogfx_pick_tile(iso, mouse_x, mouse_y, &state->xpick, &state->ypick); + + // printf("Picked tile: (%d, %d)\n", state->xpick, state->ypick); +} + +static void render(IsoGfx* iso, void* app_state) { + assert(iso); + assert(app_state); + State* state = (State*)(app_state); + + isogfx_render(iso); +} + +bool make_demo_app(IsoGfx* iso, IsoGfxApp* app) { + assert(iso); + assert(app); + + State* state = calloc(1, sizeof(State)); + if (!state) { + return false; + } + + if (!isogfx_load_world(iso, "/home/jeanne/assets/tilemaps/demo1.tm")) { + goto cleanup; + } + + app->state = state; + app->shutdown = shutdown; + app->update = update; + app->render = render; + + return true; + +cleanup: + free(state); + return false; +} -- cgit v1.2.3