summaryrefslogtreecommitdiff
path: root/gfx-iso/demos
diff options
context:
space:
mode:
Diffstat (limited to 'gfx-iso/demos')
-rw-r--r--gfx-iso/demos/CMakeLists.txt2
-rw-r--r--gfx-iso/demos/checkerboard/CMakeLists.txt15
-rw-r--r--gfx-iso/demos/checkerboard/checkerboard.c114
-rw-r--r--gfx-iso/demos/isomap/CMakeLists.txt15
-rw-r--r--gfx-iso/demos/isomap/isomap.c72
5 files changed, 218 insertions, 0 deletions
diff --git a/gfx-iso/demos/CMakeLists.txt b/gfx-iso/demos/CMakeLists.txt
new file mode 100644
index 0000000..c0a4101
--- /dev/null
+++ b/gfx-iso/demos/CMakeLists.txt
@@ -0,0 +1,2 @@
1add_subdirectory(checkerboard)
2add_subdirectory(isomap)
diff --git a/gfx-iso/demos/checkerboard/CMakeLists.txt b/gfx-iso/demos/checkerboard/CMakeLists.txt
new file mode 100644
index 0000000..f178262
--- /dev/null
+++ b/gfx-iso/demos/checkerboard/CMakeLists.txt
@@ -0,0 +1,15 @@
1cmake_minimum_required(VERSION 3.0)
2
3project(checkerboard)
4
5set(CMAKE_C_STANDARD 17)
6set(CMAKE_C_STANDARD_REQUIRED On)
7set(CMAKE_C_EXTENSIONS Off)
8
9add_executable(checkerboard
10 checkerboard.c)
11
12target_link_libraries(checkerboard PRIVATE
13 isogfx-app)
14
15target_compile_options(checkerboard PRIVATE -Wall -Wextra -Wpedantic)
diff --git a/gfx-iso/demos/checkerboard/checkerboard.c b/gfx-iso/demos/checkerboard/checkerboard.c
new file mode 100644
index 0000000..9730aea
--- /dev/null
+++ b/gfx-iso/demos/checkerboard/checkerboard.c
@@ -0,0 +1,114 @@
1#include <isogfx/app.h>
2#include <isogfx/isogfx.h>
3
4#include <assert.h>
5#include <stdbool.h>
6#include <stdio.h>
7
8static const int TILE_WIDTH = 64;
9static const int TILE_HEIGHT = TILE_WIDTH / 2;
10static const int WORLD_WIDTH = 20;
11static const int WORLD_HEIGHT = 20;
12
13static const TileDesc tile_set[] = {
14 {.type = TileFromColour,
15 .width = TILE_WIDTH,
16 .height = TILE_HEIGHT,
17 .colour = (Pixel){.r = 0x38, .g = 0x3b, .b = 0x46, .a = 0xff}},
18 {.type = TileFromColour,
19 .width = TILE_WIDTH,
20 .height = TILE_HEIGHT,
21 .colour = (Pixel){.r = 0xA5, .g = 0xb3, .b = 0xc0, .a = 0xff}},
22 {.type = TileFromColour,
23 .width = TILE_WIDTH,
24 .height = TILE_HEIGHT,
25 .colour = (Pixel){.r = 0xdc, .g = 0x76, .b = 0x84, .a = 0xff}},
26};
27
28typedef enum Colour {
29 Black,
30 White,
31 Red,
32} Colour;
33
34typedef struct IsoGfxAppState {
35 Tile red;
36 int xpick;
37 int ypick;
38} IsoGfxAppState;
39
40static void make_checkerboard(IsoGfx* iso, Tile black, Tile white) {
41 assert(iso);
42 for (int y = 0; y < isogfx_world_height(iso); ++y) {
43 for (int x = 0; x < isogfx_world_width(iso); ++x) {
44 const int odd_col = x & 1;
45 const int odd_row = y & 1;
46 const Tile value = (odd_row ^ odd_col) == 0 ? black : white;
47 isogfx_set_tile(iso, x, y, value);
48 }
49 }
50}
51
52static bool init(
53 IsoGfxAppState* state, IsoGfx* iso, int argc, const char** argv) {
54 assert(state);
55 assert(iso);
56
57 if (!isogfx_make_world(
58 iso, &(WorldDesc){
59 .tile_width = TILE_WIDTH,
60 .tile_height = TILE_HEIGHT,
61 .world_width = WORLD_WIDTH,
62 .world_height = WORLD_HEIGHT})) {
63 return false;
64 }
65
66 const Tile black = isogfx_make_tile(iso, &tile_set[Black]);
67 const Tile white = isogfx_make_tile(iso, &tile_set[White]);
68 state->red = isogfx_make_tile(iso, &tile_set[Red]);
69 make_checkerboard(iso, black, white);
70
71 return true;
72}
73
74static void shutdown(IsoGfxAppState* state, IsoGfx* iso) {
75 assert(state);
76 assert(iso);
77}
78
79static void update(IsoGfxAppState* state, IsoGfx* iso, double t, double dt) {
80 assert(state);
81 assert(iso);
82
83 double mouse_x, mouse_y;
84 gfx_app_get_mouse_position(&mouse_x, &mouse_y);
85
86 isogfx_pick_tile(iso, mouse_x, mouse_y, &state->xpick, &state->ypick);
87
88 printf("Picked tile: (%d, %d)\n", state->xpick, state->ypick);
89}
90
91static void render(IsoGfxAppState* state, IsoGfx* iso) {
92 assert(state);
93 assert(iso);
94
95 isogfx_render(iso);
96
97 if ((state->xpick != -1) && (state->ypick != -1)) {
98 isogfx_draw_tile(iso, state->xpick, state->ypick, state->red);
99 }
100}
101
102int main(int argc, const char** argv) {
103 IsoGfxAppState state = {0};
104 iso_run(
105 argc, argv,
106 &(IsoGfxApp){
107 .state = &state,
108 .init = init,
109 .shutdown = shutdown,
110 .update = update,
111 .render = render,
112 });
113 return 0;
114}
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 @@
1cmake_minimum_required(VERSION 3.0)
2
3project(isomap)
4
5set(CMAKE_C_STANDARD 17)
6set(CMAKE_C_STANDARD_REQUIRED On)
7set(CMAKE_C_EXTENSIONS Off)
8
9add_executable(isomap
10 isomap.c)
11
12target_link_libraries(isomap PRIVATE
13 isogfx-app)
14
15target_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
7typedef struct IsoGfxAppState {
8 int xpick;
9 int ypick;
10 SpriteSheet stag_sheet;
11 Sprite stag;
12} IsoGfxAppState;
13
14static 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
35static void shutdown(IsoGfxAppState* state, IsoGfx* iso) {
36 assert(state);
37 assert(iso);
38}
39
40static 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
52static void render(IsoGfxAppState* state, IsoGfx* iso) {
53 assert(state);
54 assert(iso);
55
56 isogfx_render(iso);
57}
58
59int 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}