summaryrefslogtreecommitdiff
path: root/demos/checkerboard/checkerboard.c
diff options
context:
space:
mode:
Diffstat (limited to 'demos/checkerboard/checkerboard.c')
-rw-r--r--demos/checkerboard/checkerboard.c79
1 files changed, 40 insertions, 39 deletions
diff --git a/demos/checkerboard/checkerboard.c b/demos/checkerboard/checkerboard.c
index 0c8ff37..243f7a8 100644
--- a/demos/checkerboard/checkerboard.c
+++ b/demos/checkerboard/checkerboard.c
@@ -1,5 +1,5 @@
1#include <isogfx/backend.h> 1#include <isogfx/backend.h>
2#include <isogfx/isogfx.h> 2#include <isogfx/gfx2d.h>
3 3
4#include <gfx/app.h> 4#include <gfx/app.h>
5 5
@@ -47,21 +47,21 @@ typedef enum Colour {
47} Colour; 47} Colour;
48 48
49typedef struct GfxAppState { 49typedef struct GfxAppState {
50 IsoBackend* backend; 50 Gfx2dBackend* backend;
51 IsoGfx* iso; 51 Gfx2d* gfx;
52 Tile red; 52 Tile red;
53 int xpick; 53 int xpick;
54 int ypick; 54 int ypick;
55} GfxAppState; 55} GfxAppState;
56 56
57static void make_checkerboard(IsoGfx* iso, Tile black, Tile white) { 57static void make_checkerboard(Gfx2d* iso, Tile black, Tile white) {
58 assert(iso); 58 assert(iso);
59 for (int y = 0; y < isogfx_world_height(iso); ++y) { 59 for (int y = 0; y < gfx2d_world_height(iso); ++y) {
60 for (int x = 0; x < isogfx_world_width(iso); ++x) { 60 for (int x = 0; x < gfx2d_world_width(iso); ++x) {
61 const int odd_col = x & 1; 61 const int odd_col = x & 1;
62 const int odd_row = y & 1; 62 const int odd_row = y & 1;
63 const Tile value = (odd_row ^ odd_col) == 0 ? black : white; 63 const Tile value = (odd_row ^ odd_col) == 0 ? black : white;
64 isogfx_set_tile(iso, x, y, value); 64 gfx2d_set_tile(iso, x, y, value);
65 } 65 }
66 } 66 }
67} 67}
@@ -72,28 +72,29 @@ static bool init(GfxApp* app, GfxAppState* state, int argc, const char** argv) {
72 (void)argc; 72 (void)argc;
73 (void)argv; 73 (void)argv;
74 74
75 if (!((state->iso = 75 if (!((state->gfx =
76 isogfx_new(&(IsoGfxDesc){.memory = MEMORY, 76 gfx2d_new(&(Gfx2dDesc){.memory = MEMORY,
77 .memory_size = MEMORY_SIZE, 77 .memory_size = MEMORY_SIZE,
78 .screen_width = SCREEN_WIDTH, 78 .screen_width = SCREEN_WIDTH,
79 .screen_height = SCREEN_HEIGHT})))) { 79 .screen_height = SCREEN_HEIGHT})))) {
80 return false; 80 return false;
81 } 81 }
82 IsoGfx* iso = state->iso; 82 Gfx2d* iso = state->gfx;
83 83
84 isogfx_make_world( 84 gfx2d_make_map(
85 iso, &(WorldDesc){.tile_width = TILE_WIDTH, 85 iso, &(MapDesc){.tile_width = TILE_WIDTH,
86 .tile_height = TILE_HEIGHT, 86 .tile_height = TILE_HEIGHT,
87 .world_width = WORLD_WIDTH, 87 .world_width = WORLD_WIDTH,
88 .world_height = WORLD_HEIGHT, 88 .world_height = WORLD_HEIGHT,
89 .num_tiles = NUM_TILES}); 89 .num_tiles = NUM_TILES,
90 90 .orientation = MapIsometric});
91 const Tile black = isogfx_make_tile(iso, &tile_set[Black]); 91
92 const Tile white = isogfx_make_tile(iso, &tile_set[White]); 92 const Tile black = gfx2d_make_tile(iso, &tile_set[Black]);
93 state->red = isogfx_make_tile(iso, &tile_set[Red]); 93 const Tile white = gfx2d_make_tile(iso, &tile_set[White]);
94 state->red = gfx2d_make_tile(iso, &tile_set[Red]);
94 make_checkerboard(iso, black, white); 95 make_checkerboard(iso, black, white);
95 96
96 if (!((state->backend = iso_backend_init(iso)))) { 97 if (!((state->backend = gfx2d_backend_init(iso)))) {
97 return false; 98 return false;
98 } 99 }
99 100
@@ -104,8 +105,8 @@ static void shutdown(GfxApp* app, GfxAppState* state) {
104 assert(app); 105 assert(app);
105 assert(state); 106 assert(state);
106 107
107 iso_backend_shutdown(&state->backend); 108 gfx2d_backend_shutdown(&state->backend);
108 isogfx_del(&state->iso); 109 gfx2d_del(&state->gfx);
109} 110}
110 111
111static void update(GfxApp* app, GfxAppState* state, double t, double dt) { 112static void update(GfxApp* app, GfxAppState* state, double t, double dt) {
@@ -113,19 +114,19 @@ static void update(GfxApp* app, GfxAppState* state, double t, double dt) {
113 assert(state); 114 assert(state);
114 (void)dt; 115 (void)dt;
115 116
116 IsoGfx* iso = state->iso; 117 Gfx2d* iso = state->gfx;
117 118
118 isogfx_update(iso, t); 119 gfx2d_update(iso, t);
119 120
120 // Get mouse position in window coordinates. 121 // Get mouse position in window coordinates.
121 double mouse_x, mouse_y; 122 double mouse_x, mouse_y;
122 gfx_app_get_mouse_position(app, &mouse_x, &mouse_y); 123 gfx_app_get_mouse_position(app, &mouse_x, &mouse_y);
123 124
124 // Map from window coordinates to virtual screen coordinates. 125 // Map from window coordinates to virtual screen coordinates.
125 iso_backend_get_mouse_position( 126 gfx2d_backend_get_mouse_position(
126 state->backend, mouse_x, mouse_y, &mouse_x, &mouse_y); 127 state->backend, mouse_x, mouse_y, &mouse_x, &mouse_y);
127 128
128 isogfx_pick_tile(iso, mouse_x, mouse_y, &state->xpick, &state->ypick); 129 gfx2d_pick_tile(iso, mouse_x, mouse_y, &state->xpick, &state->ypick);
129 130
130 printf("Picked tile: (%d, %d)\n", state->xpick, state->ypick); 131 printf("Picked tile: (%d, %d)\n", state->xpick, state->ypick);
131} 132}
@@ -134,22 +135,22 @@ static void render(const GfxApp* app, GfxAppState* state) {
134 assert(app); 135 assert(app);
135 assert(state); 136 assert(state);
136 137
137 IsoGfx* iso = state->iso; 138 Gfx2d* iso = state->gfx;
138 139
139 isogfx_render(iso); 140 gfx2d_render(iso);
140 141
141 if ((state->xpick != -1) && (state->ypick != -1)) { 142 if ((state->xpick != -1) && (state->ypick != -1)) {
142 isogfx_draw_tile(iso, state->xpick, state->ypick, state->red); 143 gfx2d_draw_tile(iso, state->xpick, state->ypick, state->red);
143 } 144 }
144 145
145 iso_backend_render(state->backend, iso); 146 gfx2d_backend_render(state->backend, iso);
146} 147}
147 148
148static void resize(GfxApp* app, GfxAppState* state, int width, int height) { 149static void resize(GfxApp* app, GfxAppState* state, int width, int height) {
149 assert(app); 150 assert(app);
150 assert(state); 151 assert(state);
151 152
152 iso_backend_resize_window(state->backend, state->iso, width, height); 153 gfx2d_backend_resize_window(state->backend, state->gfx, width, height);
153} 154}
154 155
155int main(int argc, const char** argv) { 156int main(int argc, const char** argv) {