summaryrefslogtreecommitdiff
path: root/demos
diff options
context:
space:
mode:
Diffstat (limited to 'demos')
-rw-r--r--demos/checkerboard/checkerboard.c29
-rw-r--r--demos/isomap/isomap.c24
2 files changed, 31 insertions, 22 deletions
diff --git a/demos/checkerboard/checkerboard.c b/demos/checkerboard/checkerboard.c
index 9d1791e..b408fc2 100644
--- a/demos/checkerboard/checkerboard.c
+++ b/demos/checkerboard/checkerboard.c
@@ -20,6 +20,9 @@ static const int TILE_HEIGHT = TILE_WIDTH / 2;
20static const int WORLD_WIDTH = 20; 20static const int WORLD_WIDTH = 20;
21static const int WORLD_HEIGHT = 20; 21static const int WORLD_HEIGHT = 20;
22 22
23#define MEMORY_SIZE (2 * 1024 * 1024)
24uint8_t MEMORY[MEMORY_SIZE];
25
23static const TileDesc tile_set[] = { 26static const TileDesc tile_set[] = {
24 {.type = TileFromColour, 27 {.type = TileFromColour,
25 .width = TILE_WIDTH, 28 .width = TILE_WIDTH,
@@ -35,6 +38,8 @@ static const TileDesc tile_set[] = {
35 .colour = (Pixel){.r = 0xdc, .g = 0x76, .b = 0x84, .a = 0xff}}, 38 .colour = (Pixel){.r = 0xdc, .g = 0x76, .b = 0x84, .a = 0xff}},
36}; 39};
37 40
41#define NUM_TILES (sizeof(tile_set) / sizeof(tile_set[0]))
42
38typedef enum Colour { 43typedef enum Colour {
39 Black, 44 Black,
40 White, 45 White,
@@ -67,28 +72,28 @@ static bool init(GfxAppState* state, int argc, const char** argv) {
67 (void)argc; 72 (void)argc;
68 (void)argv; 73 (void)argv;
69 74
70 if (!(state->iso = isogfx_new(&(IsoGfxDesc){ 75 if (!((state->iso =
71 .screen_width = SCREEN_WIDTH, .screen_height = SCREEN_HEIGHT}))) { 76 isogfx_new(&(IsoGfxDesc){.memory = MEMORY,
77 .memory_size = MEMORY_SIZE,
78 .screen_width = SCREEN_WIDTH,
79 .screen_height = SCREEN_HEIGHT})))) {
72 return false; 80 return false;
73 } 81 }
74 IsoGfx* iso = state->iso; 82 IsoGfx* iso = state->iso;
75 83
76 isogfx_resize(iso, SCREEN_WIDTH, SCREEN_HEIGHT); 84 isogfx_make_world(
77 85 iso, &(WorldDesc){.tile_width = TILE_WIDTH,
78 if (!isogfx_make_world( 86 .tile_height = TILE_HEIGHT,
79 iso, &(WorldDesc){.tile_width = TILE_WIDTH, 87 .world_width = WORLD_WIDTH,
80 .tile_height = TILE_HEIGHT, 88 .world_height = WORLD_HEIGHT,
81 .world_width = WORLD_WIDTH, 89 .num_tiles = NUM_TILES});
82 .world_height = WORLD_HEIGHT})) {
83 return false;
84 }
85 90
86 const Tile black = isogfx_make_tile(iso, &tile_set[Black]); 91 const Tile black = isogfx_make_tile(iso, &tile_set[Black]);
87 const Tile white = isogfx_make_tile(iso, &tile_set[White]); 92 const Tile white = isogfx_make_tile(iso, &tile_set[White]);
88 state->red = isogfx_make_tile(iso, &tile_set[Red]); 93 state->red = isogfx_make_tile(iso, &tile_set[Red]);
89 make_checkerboard(iso, black, white); 94 make_checkerboard(iso, black, white);
90 95
91 if (!(state->backend = iso_backend_init(iso))) { 96 if (!((state->backend = iso_backend_init(iso)))) {
92 return false; 97 return false;
93 } 98 }
94 99
diff --git a/demos/isomap/isomap.c b/demos/isomap/isomap.c
index b328bfa..efae7fd 100644
--- a/demos/isomap/isomap.c
+++ b/demos/isomap/isomap.c
@@ -5,6 +5,7 @@
5 5
6#include <assert.h> 6#include <assert.h>
7#include <stdbool.h> 7#include <stdbool.h>
8#include <stdint.h>
8 9
9static const int WINDOW_WIDTH = 1408; 10static const int WINDOW_WIDTH = 1408;
10static const int WINDOW_HEIGHT = 960; 11static const int WINDOW_HEIGHT = 960;
@@ -14,6 +15,9 @@ static const int MAX_FPS = 60;
14static const int SCREEN_WIDTH = 704; 15static const int SCREEN_WIDTH = 704;
15static const int SCREEN_HEIGHT = 480; 16static const int SCREEN_HEIGHT = 480;
16 17
18#define MEMORY_SIZE (2 * 1024 * 1024)
19uint8_t MEMORY[MEMORY_SIZE];
20
17typedef struct GfxAppState { 21typedef struct GfxAppState {
18 IsoBackend* backend; 22 IsoBackend* backend;
19 IsoGfx* iso; 23 IsoGfx* iso;
@@ -28,30 +32,30 @@ static bool init(GfxAppState* state, int argc, const char** argv) {
28 (void)argc; 32 (void)argc;
29 (void)argv; 33 (void)argv;
30 34
31 if (!(state->iso = isogfx_new(&(IsoGfxDesc){ 35 if (!((state->iso =
32 .screen_width = SCREEN_WIDTH, .screen_height = SCREEN_HEIGHT}))) { 36 isogfx_new(&(IsoGfxDesc){.memory = MEMORY,
37 .memory_size = MEMORY_SIZE,
38 .screen_width = SCREEN_WIDTH,
39 .screen_height = SCREEN_HEIGHT})))) {
33 return false; 40 return false;
34 } 41 }
35 IsoGfx* iso = state->iso; 42 IsoGfx* iso = state->iso;
36 43
37 isogfx_resize(iso, SCREEN_WIDTH, SCREEN_HEIGHT);
38
39 if (!isogfx_load_world(iso, "/home/jeanne/Nextcloud/assets/maps/demo-1.tm")) { 44 if (!isogfx_load_world(iso, "/home/jeanne/Nextcloud/assets/maps/demo-1.tm")) {
40 return false; 45 return false;
41 } 46 }
42 47
43 if (!isogfx_load_sprite_sheet( 48 if (!((state->stag_sheet = isogfx_load_sprite_sheet(
44 iso, 49 iso,
45 "/home/jeanne/Nextcloud/assets/tilesets/scrabling/critters/stag/" 50 "/home/jeanne/Nextcloud/assets/tilesets/scrabling/critters/stag/"
46 "stag.ss", 51 "stag.ss")))) {
47 &state->stag_sheet)) {
48 return false; 52 return false;
49 } 53 }
50 54
51 state->stag = isogfx_make_sprite(iso, state->stag_sheet); 55 state->stag = isogfx_make_sprite(iso, state->stag_sheet);
52 isogfx_set_sprite_position(iso, state->stag, 5, 4); 56 isogfx_set_sprite_position(iso, state->stag, 5, 4);
53 57
54 if (!(state->backend = iso_backend_init(iso))) { 58 if (!((state->backend = iso_backend_init(iso)))) {
55 return false; 59 return false;
56 } 60 }
57 61