1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
#include <isogfx/app.h>
#include <isogfx/isogfx.h>
#include <assert.h>
#include <stdbool.h>
typedef struct IsoGfxAppState {
int xpick;
int ypick;
SpriteSheet stag_sheet;
Sprite stag;
} IsoGfxAppState;
static bool init(
IsoGfxAppState* state, IsoGfx* iso, int argc, const char** argv) {
assert(state);
assert(iso);
(void)argc;
(void)argv;
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);
return true;
}
static void shutdown(IsoGfxAppState* state, IsoGfx* iso) {
assert(state);
assert(iso);
}
static void update(IsoGfxAppState* state, IsoGfx* iso, double t, double dt) {
assert(state);
assert(iso);
(void)t;
(void)dt;
double mouse_x, mouse_y;
gfx_app_get_mouse_position(&mouse_x, &mouse_y);
isogfx_pick_tile(iso, mouse_x, mouse_y, &state->xpick, &state->ypick);
// printf("Picked tile: (%d, %d)\n", state->xpick, state->ypick);
}
static void render(IsoGfxAppState* state, IsoGfx* iso) {
assert(state);
assert(iso);
isogfx_render(iso);
}
int main(int argc, const char** argv) {
IsoGfxAppState state = {0};
iso_run(
argc, argv,
&(IsoGfxApp){
.pixel_scale = 2,
.state = &state,
.init = init,
.shutdown = shutdown,
.update = update,
.render = render,
});
return 0;
}
|