From adbd2511beec8f1caa1752bdfd755cc2f62ba425 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sat, 9 Mar 2024 08:43:26 -0800 Subject: Make isogfx a library instead of an executable. --- gfx-iso/demos/isomap/CMakeLists.txt | 15 ++++++++ gfx-iso/demos/isomap/isomap.c | 72 +++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 gfx-iso/demos/isomap/CMakeLists.txt create mode 100644 gfx-iso/demos/isomap/isomap.c (limited to 'gfx-iso/demos/isomap') diff --git a/gfx-iso/demos/isomap/CMakeLists.txt b/gfx-iso/demos/isomap/CMakeLists.txt new file mode 100644 index 0000000..13edcc7 --- /dev/null +++ b/gfx-iso/demos/isomap/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 3.0) + +project(isomap) + +set(CMAKE_C_STANDARD 17) +set(CMAKE_C_STANDARD_REQUIRED On) +set(CMAKE_C_EXTENSIONS Off) + +add_executable(isomap + isomap.c) + +target_link_libraries(isomap PRIVATE + isogfx-app) + +target_compile_options(isomap PRIVATE -Wall -Wextra -Wpedantic) 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 @@ +#include +#include + +#include +#include + +typedef struct IsoGfxAppState { + int xpick; + int ypick; + SpriteSheet stag_sheet; + Sprite stag; +} IsoGfxAppState; + +static bool init( + IsoGfxAppState* state, IsoGfx* iso, int argc, const char** argv) { + assert(state); + assert(iso); + + if (!isogfx_load_world(iso, "/home/jeanne/assets/tilemaps/demo1.tm")) { + return false; + } + + if (!isogfx_load_sprite_sheet( + iso, "/home/jeanne/assets/tilesets/scrabling/critters/stag/stag.ss", + &state->stag_sheet)) { + return false; + } + + state->stag = isogfx_make_sprite(iso, state->stag_sheet); + isogfx_set_sprite_position(iso, state->stag, 5, 4); + + return true; +} + +static void shutdown(IsoGfxAppState* state, IsoGfx* iso) { + assert(state); + assert(iso); +} + +static void update(IsoGfxAppState* state, IsoGfx* iso, double t, double dt) { + assert(state); + assert(iso); + + 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(IsoGfxAppState* state, IsoGfx* iso) { + assert(state); + assert(iso); + + isogfx_render(iso); +} + +int main(int argc, const char** argv) { + IsoGfxAppState state = {0}; + iso_run( + argc, argv, + &(IsoGfxApp){ + .pixel_scale = 2, + .state = &state, + .init = init, + .shutdown = shutdown, + .update = update, + .render = render, + }); + return 0; +} -- cgit v1.2.3