summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/background.c12
-rw-r--r--src/game.c45
2 files changed, 44 insertions, 13 deletions
diff --git a/src/background.c b/src/background.c
index 7929fa1..a2b3334 100644
--- a/src/background.c
+++ b/src/background.c
@@ -14,17 +14,7 @@ void AddBackground(const char* backgroundTextureName) {
e.position = (Vector2) {0.0f, 0.0f};
Asset* backgroundTextureAsset =
- GetMatchingAssetWithType(backgroundTextureName, Texture_Asset);
-
- if (backgroundTextureAsset == NULL) {
-
- TraceLog(LOG_ERROR,
- "Failed to create background from texture asset: %s, asset not found",
- backgroundTextureName
- );
- exit(EXIT_FAILURE);
-
- }
+ GetMatchingAssetExitOnFail(backgroundTextureName, Texture_Asset);
Texture2D backgroundTexture = backgroundTextureAsset->texture;
const float backgroundSizeScale = (float)WINDOW_HEIGHT / backgroundTexture.height;
diff --git a/src/game.c b/src/game.c
index e4e2907..132eeab 100644
--- a/src/game.c
+++ b/src/game.c
@@ -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