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/resource | |
| 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/resource')
| -rw-r--r-- | src/resource/inc/resource.h | 1 | ||||
| -rw-r--r-- | src/resource/src/resource.c | 20 |
2 files changed, 20 insertions, 1 deletions
diff --git a/src/resource/inc/resource.h b/src/resource/inc/resource.h index 56da45e..aa7f1bd 100644 --- a/src/resource/inc/resource.h +++ b/src/resource/inc/resource.h @@ -41,6 +41,7 @@ struct resource_cfg }; const struct container_list *resource_res(void); +void resource_set_alive_cb(void (*f)(const struct util_rect *dim, bool alive, void *p), void *p); int resource_create(const struct resource_cfg *cfg, struct resource *list, size_t n); int resource_render(const struct resource *res, const struct camera *cam, bool sel); instance_sheltered_cb resource_shelter(const struct resource *res); diff --git a/src/resource/src/resource.c b/src/resource/src/resource.c index ae0b528..40f2301 100644 --- a/src/resource/src/resource.c +++ b/src/resource/src/resource.c @@ -5,6 +5,8 @@ #include <stddef.h> struct sprite resource_sprites[MAX_RESOURCE_TYPES]; +static void (*cb)(const struct util_rect *, bool, void *); +static void *op; static bool gold_shelter(struct instance *const self, struct instance *const other) @@ -39,7 +41,12 @@ instance_sheltered_cb resource_shelter(const struct resource *res) bool resource_harvested(struct instance *const self, const instance_hp ap) { - return instance_attacked(self, ap); + const bool ret = instance_attacked(self, ap); + + if (ret && cb) + cb(&self->r, self->alive, op); + + return ret; } instance_hp resource_maxhp(const struct resource *const res) @@ -120,6 +127,10 @@ int resource_create(const struct resource_cfg *const cfg, struct resource *const in->r.y = cfg->y; in->alive = true; in->hp = resource_maxhp(r); + + if (cb) + cb(&in->r, in->alive, op); + return 0; } } @@ -127,6 +138,13 @@ int resource_create(const struct resource_cfg *const cfg, struct resource *const return -1; } +void resource_set_alive_cb(void (*const f)(const struct util_rect *, bool, void *), + void *const p) +{ + cb = f; + op = p; +} + const char *resource_str(const struct resource *const res) { static const char *const str[] = |
