Game Development Reference
In-Depth Information
_enemyBullets.Add(bullet);
}
public void UpdatePlayerCollision(PlayerCharacter playerCharacter)
{
foreach (Bullet bullet in _enemyBullets)
{
if(bullet.GetBoundingBox().IntersectsWith(playerCharacter.
GetBoundingBox()))
{
bullet.Dead ¼ true;
playerCharacter.OnCollision(bullet);
}
}
}
The UpdatePlayerCollision is quite similar to the existing UpdateEne-
myCollision method and eventually they should be combined, but for
this iteration of the game development, it's easier if they stay separate. The
PlayerCharacter class needs a new OnCollision method that takes in a
bullet object.
internal void OnCollision(Bullet bullet)
{
_dead ¼ true;
}
The PlayerCharacter now has two collision methods: one for bullets and
one for enemies. The PlayerCharacter dies if he touches an enemy or a
bullet so these methods are redundant. The reason they have been written this
way is to make extending the game easier. It's important to know what the player
is colliding with. If the player is given a health value, then colliding with an
enemy may cause more damage than a bullet. If missiles, mines, or various types
of power-up are added, they too can have an extra collision method to deal with
that case.
Shooter is a very strict game. If the player hits an enemy, he immediately loses.
The same is true if he hits a bullet. The BulletManager now needs an extra call
in the Update loop of the Level class to test if an enemy bullet has hit the
player.
 
Search WWH ::




Custom Search