aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-03-31 07:29:16 +0200
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2022-03-31 07:29:16 +0200
commitb8c30e83e3a59681882d574a1fff8150700bf265 (patch)
tree5e521b9f69c03a9e7e871e21d31f2e64612eb74c /src
parent405819eef95bb89c13ba6a02286a5fd48c6bd872 (diff)
downloadrts-b8c30e83e3a59681882d574a1fff8150700bf265.tar.gz
resource.c: decouple collbox from sprite dimensions
Diffstat (limited to 'src')
-rw-r--r--src/resource/src/resource.c32
1 files changed, 26 insertions, 6 deletions
diff --git a/src/resource/src/resource.c b/src/resource/src/resource.c
index 40f2301..2a11c92 100644
--- a/src/resource/src/resource.c
+++ b/src/resource/src/resource.c
@@ -73,12 +73,31 @@ int resource_render(const struct resource *const res,
if (sprite_clone(&resource_sprites[res->type], s))
return -1;
- if (res->type == RESOURCE_TYPE_GOLD)
+ const struct instance_render_off *off = NULL;
+
+ switch (res->type)
{
- s->h = in->r.h;
+ case RESOURCE_TYPE_GOLD:
+ s->h = in->r.h;
+
+ if (res->res.gold.n_miners)
+ s->v += s->h;
+
+ break;
+
+ case RESOURCE_TYPE_WOOD:
+ {
+ static const struct instance_render_off w_off =
+ {
+ .y = -30
+ };
+
+ off = &w_off;
+ }
+ break;
- if (res->res.gold.n_miners)
- s->v += s->h;
+ default:
+ break;
}
const struct instance_render_cfg cfg =
@@ -88,7 +107,8 @@ int resource_render(const struct resource *const res,
.prim = {.s = s},
.cam = cam,
.sel = sel,
- .max_hp = resource_maxhp(res)
+ .max_hp = resource_maxhp(res),
+ .off = off
};
return instance_render(&cfg);
@@ -103,7 +123,7 @@ static void get_dimensions(const enum resource_type type, short *const w,
} dim[] =
{
[RESOURCE_TYPE_GOLD] = {.w = 96, .h = 96},
- [RESOURCE_TYPE_WOOD] = {.w = 32, .h = 46}
+ [RESOURCE_TYPE_WOOD] = {.w = 32, .h = 16}
};
const struct dim *const d = &dim[type];