private void CheckEnemyProjectileCollision()//discovers collisions between enemy projectiles and other gameobjects { foreach (EnemyProjectile EnemyProjectile in EnemyProjectiles) { foreach (Wall wall in Walls) { if (wall.IsHit(EnemyProjectile.X, EnemyProjectile.Y + 10)) { TemporaryEnemyProjectiles.Add(EnemyProjectile); //removes enemy projectile TemporaryWalls.Add(wall); //removes wall } } if (Player.IsHit(EnemyProjectile.X, EnemyProjectile.Y)) { Player.HealthPoints--; //removes one player life TemporaryEnemyProjectiles.Add(EnemyProjectile); //removes enemy projectile } if (EnemyProjectile.Y > GameDisplay.ActualHeight) { TemporaryEnemyProjectiles.Add(EnemyProjectile);//removes enemy projectile } } }
private void CheckplayerProjectileCollisions()//discovers collisions between player projectiles and other gameobjects { foreach (PlayerProjectile PlayerProjectile in PlayerProjectiles) { foreach (Wall wall in Walls) { if (wall.IsHit(PlayerProjectile.X, PlayerProjectile.Y)) { TemporaryWalls.Add(wall); //removes wall TemporaryPlayerProjectiles.Add(PlayerProjectile); //removes player projectile } } foreach (Invader invader in Invaders) { if (invader.IsHit(PlayerProjectile.X, PlayerProjectile.Y)) { TemporaryInvaders.Add(invader); //removes invader TemporaryPlayerProjectiles.Add(PlayerProjectile); //removes player projectile score = score + 5 + 15 * difficultyIndex; //score for a destroyed invader } } foreach (Ufo ufo in Ufos) { if (ufo.IsHit(PlayerProjectile.X, PlayerProjectile.Y)) { score += 50; TemporaryUfos.Add(ufo); //removes UFO TemporaryPlayerProjectiles.Add(PlayerProjectile); //removes player projectile } } if (PlayerProjectile.Y < 0) { TemporaryPlayerProjectiles.Add(PlayerProjectile);//removes player projectile } } }