Hi all,
I’m new to programming and new to game development, any help would be greatly appreciated. I did the shooter game tutorial and I learned a lot. I’m trying to add functionality so when the player’s health goes to 0 then the game kind of restarts. The player class has an active variable and it gets set to false when player’s health is 0 but the game continues on. Any ideas? this is the code where the isActive gets set to 0.
for (int i = 0; i < enemies.Count; i++)
{
enemyRectangle = new Rectangle((int)enemies[i].Position.X, (int)enemies[i].Position.Y, enemies[i].Width, enemies[i].Health);
if (playerRectangle.Intersects(enemyRectangle))
{
//since the enemy collided with the player destroy it
enemies[i].Health = 0;
//show the explosion where the enemy was...
AddExplosion(enemies[i].Position);
//subtract the health from the player based on the enemy damage
player.Health = player.Health - enemies[i].Damage;
//if the player health is less than zero we died
if (player.Health <= 0)
{
player.Active = false;
AddExplosion(player.Position);
}
}
for (var l = 0; l < LaserBeams.Count; l++)
{
//create a rectangle for this laserbeam
laserRectangle = new Rectangle((int)LaserBeams[l].Position.X, (int)LaserBeams[l].Position.Y, LaserBeams[l].Width, LaserBeams[l].Height);
//test the bounds of the laser and enemy
if (laserRectangle.Intersects(enemyRectangle))
{
//show the explosion where the enemy was...
AddExplosion(enemies[i].Position);
//kill of the enemy
enemies[i].Health = 0;
//kill of the laserbeam
LaserBeams[l].Active = false;
}
}