public void Update() { ChangeInvaderDirection(); UpdateInvaders(); // add bullet to allien AddAlienBullet(); //add the super UFO int timeControl = Convert.ToInt32(myTimer.Ticks / 40) % 100; if (!Quit && SuperUFOs.Count < 1 && timeControl == 0) { SuperUFOs.Add(new SuperUFO(50, 120)); UFOSound.Play(); } foreach (var item in SuperUFOs) { item.SuperUFOUpdate(); } foreach (Bullet item in Player.Bullets) { item.Update(); } foreach (var item in AlienBullets) { item.Update(); } CheckCollision(); // CheckIsPlayerWin(); }
public void CheckBulletCollisions() { List <Bullet> bulletsToRemove = new List <Bullet>(); List <Invader> invadersToRemove = new List <Invader>(); List <SuperUFO> UFOtoRemove = new List <SuperUFO>(); List <CaveBlock> CaveBlocksToRemove = new List <CaveBlock>(); foreach (var bullet in Player.Bullets) { if (bullet.IsOffScreen(GameWindow)) { bulletsToRemove.Add(bullet); } if (Invaders.Count != 0) { foreach (Invader invader in Invaders) { if (bullet.CollidedWith(invader)) { bulletsToRemove.Add(bullet); invadersToRemove.Add(invader); // invader.IsDead = true; int addScore = 100; Player.Score = Player.Score + addScore; bullet.CollisionSound.Play(); } } } foreach (var UFO in SuperUFOs) { if (UFO.IsOffScreenWidth(GameWindow)) { UFOtoRemove.Add(UFO); } if (bullet.CollidedWith(UFO)) { bulletsToRemove.Add(bullet); UFOtoRemove.Add(UFO); UFO.IsDead = true; Player.Score = Player.Score + 1000; bullet.CollisionSound.Play(); } } foreach (var cBlock in CaveBlocks) { if (cBlock.CollidedWith(bullet)) { bulletsToRemove.Add(bullet); CaveBlocksToRemove.Add(cBlock); Player.Score -= 500; cBlock.CaveCollide.Play(); } } } foreach (var bullet in bulletsToRemove) { Player.Bullets.Remove(bullet); } foreach (var invader in invadersToRemove) { Invaders.Remove(invader); } foreach (var UFO in UFOtoRemove) { SuperUFOs.Remove(UFO); } foreach (var cBlock in CaveBlocksToRemove) { CaveBlocks.Remove(cBlock); } CaveBlocksToRemove.Clear(); invadersToRemove.Clear(); UFOtoRemove.Clear(); CaveBlocksToRemove.Clear(); }