diff options
| author | 3gg <3gg@shellblade.net> | 2025-06-27 10:17:41 -0700 |
|---|---|---|
| committer | 3gg <3gg@shellblade.net> | 2025-06-27 10:17:41 -0700 |
| commit | 4ffa1895390066f2bbd347c0689a1b667a21fd24 (patch) | |
| tree | eed5f00b9d5e43c9d15863441736f8262be314d8 /demos/isomap | |
Initial commit
Diffstat (limited to 'demos/isomap')
| -rw-r--r-- | demos/isomap/CMakeLists.txt | 16 | ||||
| -rw-r--r-- | demos/isomap/isomap.c | 105 |
2 files changed, 121 insertions, 0 deletions
diff --git a/demos/isomap/CMakeLists.txt b/demos/isomap/CMakeLists.txt new file mode 100644 index 0000000..2dbfd32 --- /dev/null +++ b/demos/isomap/CMakeLists.txt | |||
| @@ -0,0 +1,16 @@ | |||
| 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 | gfx-app | ||
| 14 | isogfx-backend) | ||
| 15 | |||
| 16 | target_compile_options(isomap PRIVATE -Wall -Wextra -Wpedantic) | ||
diff --git a/demos/isomap/isomap.c b/demos/isomap/isomap.c new file mode 100644 index 0000000..a233659 --- /dev/null +++ b/demos/isomap/isomap.c | |||
| @@ -0,0 +1,105 @@ | |||
| 1 | #include <isogfx/backend.h> | ||
| 2 | #include <isogfx/isogfx.h> | ||
| 3 | |||
| 4 | #include <gfx/app.h> | ||
| 5 | |||
| 6 | #include <assert.h> | ||
| 7 | #include <stdbool.h> | ||
| 8 | |||
| 9 | static const int WINDOW_WIDTH = 1408; | ||
| 10 | static const int WINDOW_HEIGHT = 960; | ||
| 11 | static const int MAX_FPS = 60; | ||
| 12 | |||
| 13 | // Virtual screen dimensions. | ||
| 14 | static const int SCREEN_WIDTH = 704; | ||
| 15 | static const int SCREEN_HEIGHT = 480; | ||
| 16 | |||
| 17 | typedef struct GfxAppState { | ||
| 18 | IsoBackend* backend; | ||
| 19 | IsoGfx* iso; | ||
| 20 | int xpick; | ||
| 21 | int ypick; | ||
| 22 | SpriteSheet stag_sheet; | ||
| 23 | Sprite stag; | ||
| 24 | } GfxAppState; | ||
| 25 | |||
| 26 | static bool init(GfxAppState* state, int argc, const char** argv) { | ||
| 27 | assert(state); | ||
| 28 | (void)argc; | ||
| 29 | (void)argv; | ||
| 30 | |||
| 31 | if (!(state->iso = isogfx_new(&(IsoGfxDesc){ | ||
| 32 | .screen_width = SCREEN_WIDTH, .screen_height = SCREEN_HEIGHT}))) { | ||
| 33 | return false; | ||
| 34 | } | ||
| 35 | IsoGfx* iso = state->iso; | ||
| 36 | |||
| 37 | isogfx_resize(iso, SCREEN_WIDTH, SCREEN_HEIGHT); | ||
| 38 | |||
| 39 | if (!isogfx_load_world(iso, "/home/jeanne/assets/tilemaps/demo1.tm")) { | ||
| 40 | return false; | ||
| 41 | } | ||
| 42 | |||
| 43 | if (!isogfx_load_sprite_sheet( | ||
| 44 | iso, "/home/jeanne/assets/tilesets/scrabling/critters/stag/stag.ss", | ||
| 45 | &state->stag_sheet)) { | ||
| 46 | return false; | ||
| 47 | } | ||
| 48 | |||
| 49 | state->stag = isogfx_make_sprite(iso, state->stag_sheet); | ||
| 50 | isogfx_set_sprite_position(iso, state->stag, 5, 4); | ||
| 51 | |||
| 52 | if (!(state->backend = IsoBackendInit(iso))) { | ||
| 53 | return false; | ||
| 54 | } | ||
| 55 | |||
| 56 | return true; | ||
| 57 | } | ||
| 58 | |||
| 59 | static void shutdown(GfxAppState* state) { | ||
| 60 | assert(state); | ||
| 61 | // | ||
| 62 | } | ||
| 63 | |||
| 64 | static void update(GfxAppState* state, double t, double dt) { | ||
| 65 | assert(state); | ||
| 66 | (void)dt; | ||
| 67 | |||
| 68 | IsoGfx* iso = state->iso; | ||
| 69 | isogfx_update(iso, t); | ||
| 70 | } | ||
| 71 | |||
| 72 | static void render(GfxAppState* state) { | ||
| 73 | assert(state); | ||
| 74 | |||
| 75 | IsoGfx* iso = state->iso; | ||
| 76 | isogfx_render(iso); | ||
| 77 | IsoBackendRender(state->backend, iso); | ||
| 78 | } | ||
| 79 | |||
| 80 | static void resize(GfxAppState* state, int width, int height) { | ||
| 81 | assert(state); | ||
| 82 | |||
| 83 | IsoBackendResizeWindow(state->backend, state->iso, width, height); | ||
| 84 | } | ||
| 85 | |||
| 86 | int main(int argc, const char** argv) { | ||
| 87 | GfxAppState state = {0}; | ||
| 88 | gfx_app_run( | ||
| 89 | &(GfxAppDesc){ | ||
| 90 | .argc = argc, | ||
| 91 | .argv = argv, | ||
| 92 | .width = WINDOW_WIDTH, | ||
| 93 | .height = WINDOW_HEIGHT, | ||
| 94 | .max_fps = MAX_FPS, | ||
| 95 | .update_delta_time = MAX_FPS > 0 ? 1.0 / (double)MAX_FPS : 0.0, | ||
| 96 | .title = "Isometric Renderer", | ||
| 97 | .app_state = &state}, | ||
| 98 | &(GfxAppCallbacks){ | ||
| 99 | .init = init, | ||
| 100 | .update = update, | ||
| 101 | .render = render, | ||
| 102 | .resize = resize, | ||
| 103 | .shutdown = shutdown}); | ||
| 104 | return 0; | ||
| 105 | } | ||
