feat: collision functions added

This commit is contained in:
2025-10-04 14:57:09 +01:00
parent 14321c71b8
commit a9f12532b4
4 changed files with 45 additions and 0 deletions

17
code/game/aabb.h Normal file
View File

@@ -0,0 +1,17 @@
#if !defined(LD_CORE_AABB_H_)
#define LD_CORE_AABB_H_
#include "types.h"
#include "../core/macros.h"
typedef struct AABB AABB;
struct AABB {
V2f pos;
V2f size;
};
function bool AABB_Collide(AABB a, AABB b);
function bool AABB_Point(AABB a, V2f v);
#endif // LD_CORE_AABB_H_

15
code/game/impl/aabb.c Normal file
View File

@@ -0,0 +1,15 @@
#include "../aabb.h"
#include "../types.h"
bool AABB_Collide(AABB a, AABB b) {
bool collision_x = a.pos.x + a.size.x >= b.pos.x && b.pos.x + b.size.x >= a.pos.x;
bool collision_y = a.pos.y + a.size.x >= b.pos.y && b.pos.y + b.size.y >= a.pos.y;
return collision_x && collision_y;
}
bool AABB_Point(AABB a, V2f v) {
bool collision_x = a.pos.x + a.size.x >= v.x && a.pos.x <= v.x;
bool collision_y = a.pos.x + a.size.y >= v.y && a.pos.y <= v.y;
return collision_x && collision_y;
}