From 4ffa1895390066f2bbd347c0689a1b667a21fd24 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Fri, 27 Jun 2025 10:17:41 -0700 Subject: Initial commit --- demos/isomap/isomap.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 demos/isomap/isomap.c (limited to 'demos/isomap/isomap.c') 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 @@ +#include +#include + +#include + +#include +#include + +static const int WINDOW_WIDTH = 1408; +static const int WINDOW_HEIGHT = 960; +static const int MAX_FPS = 60; + +// Virtual screen dimensions. +static const int SCREEN_WIDTH = 704; +static const int SCREEN_HEIGHT = 480; + +typedef struct GfxAppState { + IsoBackend* backend; + IsoGfx* iso; + int xpick; + int ypick; + SpriteSheet stag_sheet; + Sprite stag; +} GfxAppState; + +static bool init(GfxAppState* state, int argc, const char** argv) { + assert(state); + (void)argc; + (void)argv; + + if (!(state->iso = isogfx_new(&(IsoGfxDesc){ + .screen_width = SCREEN_WIDTH, .screen_height = SCREEN_HEIGHT}))) { + return false; + } + IsoGfx* iso = state->iso; + + isogfx_resize(iso, SCREEN_WIDTH, SCREEN_HEIGHT); + + 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); + + if (!(state->backend = IsoBackendInit(iso))) { + return false; + } + + return true; +} + +static void shutdown(GfxAppState* state) { + assert(state); + // +} + +static void update(GfxAppState* state, double t, double dt) { + assert(state); + (void)dt; + + IsoGfx* iso = state->iso; + isogfx_update(iso, t); +} + +static void render(GfxAppState* state) { + assert(state); + + IsoGfx* iso = state->iso; + isogfx_render(iso); + IsoBackendRender(state->backend, iso); +} + +static void resize(GfxAppState* state, int width, int height) { + assert(state); + + IsoBackendResizeWindow(state->backend, state->iso, width, height); +} + +int main(int argc, const char** argv) { + GfxAppState state = {0}; + gfx_app_run( + &(GfxAppDesc){ + .argc = argc, + .argv = argv, + .width = WINDOW_WIDTH, + .height = WINDOW_HEIGHT, + .max_fps = MAX_FPS, + .update_delta_time = MAX_FPS > 0 ? 1.0 / (double)MAX_FPS : 0.0, + .title = "Isometric Renderer", + .app_state = &state}, + &(GfxAppCallbacks){ + .init = init, + .update = update, + .render = render, + .resize = resize, + .shutdown = shutdown}); + return 0; +} -- cgit v1.2.3