Game Development Reference
In-Depth Information
In a similar fashion to the enemy spawning system in Game, we use a variable
named _sinceLastShot to track the amount of time since the previous shot. This
we update in Player::Update using the delta time. If the player can fire, we as-
sume that the caller ( Game ) will fire, and reset the timer to zero, making it ready to
count towards the next shot. This would be the perfect location to add in another ac-
tion that allows the user to press a button to fire.
Now we need to make these bullets do something. Back in Game you will remember
we have a method for managing collisions named ProcessCollisions .
for (auto bullet : _bullets)
{
if (bullet->GetIsAlive())
{
if
(!bullet->GetCollider()->CollidesWith(_bounds))
{
bullet->Destroy();
}
else
{
for (auto enemy : _enemies)
{
if (enemy->GetIsAlive() &&
bullet->GetCollider()->CollidesWith(enemy->GetCollider()))
{
enemy->Damage(bullet->Damage);
bullet->Destroy();
if (!enemy->GetIsAlive())
_playerScore += 50;
}
}
}
}
}
We need to add a loop at the bottom of this to go through each bullet in existence
and check against all of the living enemies to see if there has been a collision, or
Search WWH ::




Custom Search