diff options
| author | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2022-03-30 08:28:47 +0200 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2022-03-30 08:28:47 +0200 |
| commit | 1950fe7b0679c6b6486cc7b25bef813db2b1bb4e (patch) | |
| tree | c2098c9ec65f9a9e5fada68c0b51b0217f14b00c /src/building | |
| parent | 06056a9b5e900f67702c509ce1ba2e2351357fb7 (diff) | |
| download | jancity-1950fe7b0679c6b6486cc7b25bef813db2b1bb4e.tar.gz | |
Implement sub-tile collboxes
These will be later used by the pathfinding algorithm.
Diffstat (limited to 'src/building')
| -rw-r--r-- | src/building/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/building/inc/building.h | 2 | ||||
| -rw-r--r-- | src/building/src/building.c | 13 |
3 files changed, 16 insertions, 1 deletions
diff --git a/src/building/CMakeLists.txt b/src/building/CMakeLists.txt index 3eb352e..5bfa674 100644 --- a/src/building/CMakeLists.txt +++ b/src/building/CMakeLists.txt @@ -1,3 +1,3 @@ add_library(building "src/building.c") target_include_directories(building PUBLIC "inc") -target_link_libraries(building PUBLIC gfx instance camera) +target_link_libraries(building PUBLIC gfx instance camera util) diff --git a/src/building/inc/building.h b/src/building/inc/building.h index 7763b7d..a0ab539 100644 --- a/src/building/inc/building.h +++ b/src/building/inc/building.h @@ -5,6 +5,7 @@ #include <camera.h> #include <gfx.h> #include <instance.h> +#include <util.h> #include <stdbool.h> #include <stddef.h> @@ -28,6 +29,7 @@ struct building_cfg }; void building_create(const struct building_cfg *cfg, struct building *b); +void building_set_alive_cb(void (*f)(const struct util_rect *dim, bool alive, void *p), void *p); int building_render(const struct building *b, const struct camera *cam, bool sel); instance_hp building_maxhp(const struct building *b); const char *building_str(const struct building *b); diff --git a/src/building/src/building.c b/src/building/src/building.c index 5b94ee3..5ff9183 100644 --- a/src/building/src/building.c +++ b/src/building/src/building.c @@ -56,6 +56,9 @@ static void get_dimensions(const enum building_type type, short *const w, *h = d->h; } +static void *op; +static void (*cb)(const struct util_rect *, bool, void *); + void building_create(const struct building_cfg *const cfg, struct building *const b) { @@ -67,6 +70,16 @@ void building_create(const struct building_cfg *const cfg, i->r.y = cfg->y; i->alive = true; i->hp = building_maxhp(b); + + if (cb) + cb(&i->r, i->alive, op); +} + +void building_set_alive_cb(void (*const f)(const struct util_rect *, bool, void *), + void *const p) +{ + cb = f; + op = p; } const char *building_str(const struct building *const b) |
