Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

why does my program update more than once?

$
0
0
hi all , so im making a small 2d game , i have a spaceship than shoots once at a enemy and it dies,score goes up etc , but i trying to make it so the enemies have there own health , my problem is the game is updating it so many times within one "turn" than it is just acting like it hit it enough to die. i have it so a bullet damage would be 20 and the enemy health is 100 so technically i should need to shoot it 5 times but i hit it once and it dies, i tried debugging and i watch it go round the foreach loop once fine then it goes back into update and somehow acts as if the bullet is still intersecting even though when it did hit the bullet's visible changed to false and its enabled also become false? here is the code just for the collision loop


// player1 bullet > enemy collision
                foreach (Bullets newbullet1 in bulletList)
                {
                    foreach (Enemy newenemy in enemiesList)
                    {
                        if (newbullet1.GetBounds().Intersects(newenemy.GetBounds()))
                        {
                            newbullet1.isVisible = false;
                            newbullet1.Enabled = false;
                            newenemy.enemyHit = true;
                            newenemy.enemyHealth -= 20;
                            player1.score += 2;
                            audio.Explosion.Play();

                            if (newenemy.enemyHit == true)
                            {
                                newenemy.enemyHit = false;
                                if (newenemy.enemyHealth <= 0)
                                {
                                    newenemy.isVisible = false;
                                    newenemy.Enabled = false;
                                }

                            }
                    }
              }
          }


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>