summaryrefslogtreecommitdiff
path: root/src/game.c
diff options
context:
space:
mode:
authorBoredGuy <osome3717@gmail.com>2025-09-10 18:49:20 +0300
committerBoredGuy <osome3717@gmail.com>2025-09-10 18:49:20 +0300
commitc2add3e23ee1b69f059d5b78e33c0a922dc1a22d (patch)
tree3781913b577f6c94172fcd864c1873df8fc87324 /src/game.c
parent1418b5ade374a58bfdf2e3dfee8a4263d642442f (diff)
Hitbox-Hurtbox Collisions
Diffstat (limited to 'src/game.c')
-rw-r--r--src/game.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/game.c b/src/game.c
index 88f6405..6e72b97 100644
--- a/src/game.c
+++ b/src/game.c
@@ -11,6 +11,8 @@
#include <math.h>
#include "utils.h"
+#include "barrel.h"
+
Game game;
int compare(const void* a, const void* b) {
@@ -63,14 +65,14 @@ void UpdateEntity(Entity* e, float deltaTime) {
}
}
-static bool IsHitting(const Entity* a, const Entity* b) {
+static bool IsBeingHit(const Entity* a, const Entity* b) {
if (!PhysicsEnabled(a) || !PhysicsEnabled(b))
return false;
- for (int i = 0; i < a->numHitBoxes; i++) {
- for (int j = 0; j < b->numHurtBoxes; j++) {
- Rectangle hitbox = GetEntityHitboxGlobal(a, i);
- Rectangle hurtbox = GetEntityHurtboxGlobal(b, j);
+ for (int i = 0; i < a->numHurtBoxes; i++) {
+ for (int j = 0; j < b->numHitBoxes; j++) {
+ Rectangle hitbox = GetEntityHurtboxGlobal(a, i);
+ Rectangle hurtbox = GetEntityHitboxGlobal(b, j);
if (CheckCollisionRecs(hitbox, hurtbox))
return true;
@@ -82,6 +84,9 @@ static bool IsHitting(const Entity* a, const Entity* b) {
void EntityHandleHit(Entity* a, Entity* b) {
switch(a->type) {
+ case Barrel_Entity:
+ BarrelHandleCollision(a);
+ break;
default:
break;
@@ -94,10 +99,10 @@ void HandleHitboxInteractions() {
Entity* a = &game.entities[i];
Entity* b = &game.entities[j];
- if (IsHitting(a, b))
+ if (IsBeingHit(a, b))
EntityHandleHit(a, b);
- if (IsHitting(b, a))
+ if (IsBeingHit(b, a))
EntityHandleHit(b, a);
}
}