Skip to content

Commit

Permalink
Fix potential bug when checking collisions
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewL246 authored Dec 4, 2023
1 parent 845f95e commit e3ef779
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions source/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ void CheckBulletEnemyCollisions(void)
{
currentBullet->health -= 1;
currentEnemy->health -= currentBullet->damage;
bool shouldReturn = false;

if (currentBullet->health <= 0)
{
Expand All @@ -37,7 +38,8 @@ void CheckBulletEnemyCollisions(void)

if (!currentBullet)
{
return;
// There are no more bullets to iterate
shouldReturn = true;
}
}
if (currentEnemy->health <= 0)
Expand All @@ -48,9 +50,15 @@ void CheckBulletEnemyCollisions(void)

if (!currentEnemy)
{
return;
// There are no more enemies to iterate
shouldReturn = true;
}
}

if (shouldReturn)
{
return;
}
}
}
}
Expand Down

0 comments on commit e3ef779

Please sign in to comment.