summaryrefslogtreecommitdiff
path: root/src/entity.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/entity.h')
-rw-r--r--src/entity.h23
1 files changed, 17 insertions, 6 deletions
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 <SDL2/SDL.h>
-#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;
};