summary refs log tree commit diff
path: root/src/entity.h
diff options
context:
space:
mode:
authorzlago2024-10-09 06:09:43 +0200
committerzlago2024-10-09 06:09:43 +0200
commit753cdae8c9656f2f5c8380868dca1c5e9be9b437 (patch)
treefbf799f78e4c36ac2e3daad77e7a48087f1114d5 /src/entity.h
parentc851581465b9bae8ac679415368d792cefd76de2 (diff)
work on combat
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;
 };