From 753cdae8c9656f2f5c8380868dca1c5e9be9b437 Mon Sep 17 00:00:00 2001 From: zlago Date: Wed, 9 Oct 2024 06:09:43 +0200 Subject: work on combat --- src/entity.h | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'src/entity.h') diff --git a/src/entity.h b/src/entity.h index 0166bdc..72fccb2 100644 --- a/src/entity.h +++ b/src/entity.h @@ -2,23 +2,32 @@ #include -#define from_fixed(a) (a / 16) -#define to_fixed(a) (a * 16) - -struct vec2 { - signed x, y; -}; +#define from_fixed(a) ((a) / 16) +#define to_fixed(a) ((a) * 16) struct hitbox { unsigned left, right, top, bottom; }; +static inline int hitbox_overlap(struct hitbox const a, struct hitbox const b) { + return a.left <= b.right && a.right >= b.left && a.top <= b.bottom && a.bottom >= b.top; +} + +struct vec2 { + signed x, y; +}; + struct anim { unsigned frame; SDL_Rect rect; unsigned length; }; +enum factions { + FACTION_PLAYER, + FACTION_ENEMY, +}; + struct entity { int (*update)(struct entity *self); int (*hurt)(struct entity *self, int damage); @@ -33,6 +42,7 @@ struct entity { int timer; int iframes; signed facing; + enum factions faction; void *texture; void *ext; }; @@ -60,6 +70,7 @@ struct projectile { int timer; int iframes; signed facing; + enum factions faction; void *texture; void *ext; }; -- cgit 1.4.1-2-gfad0