diff options
Diffstat (limited to 'src/game.c')
-rw-r--r-- | src/game.c | 45 |
1 files changed, 43 insertions, 2 deletions
@@ -63,6 +63,46 @@ void UpdateEntity(Entity* e, float deltaTime) { } } +static bool IsHitting(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); + + if (CheckCollisionRecs(hitbox, hurtbox)) + return true; + } + } + + return false; +} + +void EntityHandleHit(Entity* a, Entity* b) { + switch(a->type) { + + default: + break; + } +} + +void HandleHitboxInteractions() { + for (int i = 0; i < MAX_ENTITY_COUNT; i++) { + for (int j = i + 1; j < MAX_ENTITY_COUNT; j++) { + Entity* a = &game.entities[i]; + Entity* b = &game.entities[j]; + + if (IsHitting(a, b)) + EntityHandleHit(a, b); + + if (IsHitting(b, a)) + EntityHandleHit(b, a); + } + } +} + void UpdateGame(float deltaTime) { #ifdef BEATEMUP_DEBUG if (IsKeyPressed(KEY_F3)) { @@ -75,6 +115,8 @@ void UpdateGame(float deltaTime) { if (EntityAllocated(e)) UpdateEntity(e, deltaTime); } + + HandleHitboxInteractions(); } void DrawEntitySprite(const Entity* e, int spriteIndex) { @@ -160,8 +202,7 @@ void DrawGame() { #ifdef BEATEMUP_DEBUG if (game.enableDebugOverlay) { - const int posX = 10, posY = 10; - DrawFPS(posX, posY); + DrawFPS(FPS_POS_X, FPS_POS_Y); } #endif |