diff --git a/code/core/types.h b/code/core/types.h index 08436db..a5bc66d 100644 --- a/code/core/types.h +++ b/code/core/types.h @@ -29,4 +29,16 @@ struct Str8 { U8 *data; }; +typedef struct V2f V2f; +struct V2f { + F32 x; + F32 y; +}; + +typedef struct V2i V2i; +struct V2i { + U32 x; + U32 y; +}; + #endif // LD_CORE_TYPES_H_ diff --git a/code/first.c b/code/first.c index 3202aea..6d714a8 100644 --- a/code/first.c +++ b/code/first.c @@ -3,6 +3,7 @@ #include #include "core/core.h" +#include "core/types.h" #include "os/core.h" #include "vulkan/core.h" diff --git a/code/game/aabb.h b/code/game/aabb.h new file mode 100644 index 0000000..060cb53 --- /dev/null +++ b/code/game/aabb.h @@ -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_ diff --git a/code/game/impl/aabb.c b/code/game/impl/aabb.c new file mode 100644 index 0000000..3637513 --- /dev/null +++ b/code/game/impl/aabb.c @@ -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; +} +