diff options
| author | 3gg <3gg@shellblade.net> | 2024-03-09 08:43:26 -0800 |
|---|---|---|
| committer | 3gg <3gg@shellblade.net> | 2024-03-09 08:43:26 -0800 |
| commit | adbd2511beec8f1caa1752bdfd755cc2f62ba425 (patch) | |
| tree | 8fde167e9d9951b43e571a2417ae55f9572bea28 /gfx-iso/demos/isomap | |
| parent | 4bc4ca2796bd434880b77d3c4bcbb56107456777 (diff) | |
Make isogfx a library instead of an executable.
Diffstat (limited to 'gfx-iso/demos/isomap')
| -rw-r--r-- | gfx-iso/demos/isomap/CMakeLists.txt | 15 | ||||
| -rw-r--r-- | gfx-iso/demos/isomap/isomap.c | 72 |
2 files changed, 87 insertions, 0 deletions
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 @@ | |||
| 1 | cmake_minimum_required(VERSION 3.0) | ||
| 2 | |||
| 3 | project(isomap) | ||
| 4 | |||
| 5 | set(CMAKE_C_STANDARD 17) | ||
| 6 | set(CMAKE_C_STANDARD_REQUIRED On) | ||
| 7 | set(CMAKE_C_EXTENSIONS Off) | ||
| 8 | |||
| 9 | add_executable(isomap | ||
| 10 | isomap.c) | ||
| 11 | |||
| 12 | target_link_libraries(isomap PRIVATE | ||
| 13 | isogfx-app) | ||
| 14 | |||
| 15 | 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 @@ | |||
| 1 | #include <isogfx/app.h> | ||
| 2 | #include <isogfx/isogfx.h> | ||
| 3 | |||
| 4 | #include <assert.h> | ||
| 5 | #include <stdbool.h> | ||
| 6 | |||
| 7 | typedef struct IsoGfxAppState { | ||
| 8 | int xpick; | ||
| 9 | int ypick; | ||
| 10 | SpriteSheet stag_sheet; | ||
| 11 | Sprite stag; | ||
| 12 | } IsoGfxAppState; | ||
| 13 | |||
| 14 | static 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 | |||
| 35 | static void shutdown(IsoGfxAppState* state, IsoGfx* iso) { | ||
| 36 | assert(state); | ||
| 37 | assert(iso); | ||
| 38 | } | ||
| 39 | |||
| 40 | static 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 | |||
| 52 | static void render(IsoGfxAppState* state, IsoGfx* iso) { | ||
| 53 | assert(state); | ||
| 54 | assert(iso); | ||
| 55 | |||
| 56 | isogfx_render(iso); | ||
| 57 | } | ||
| 58 | |||
| 59 | int 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 | } | ||
