コード例 #1
0
 public void CheckCollision(Player player, World currentLevel)
 {
     CheckPickablesCollision(player, currentLevel);
     CheckDoorCollision(player, currentLevel);
     CheckPlatformCollision(player, currentLevel);
     CheckMapRange(player, currentLevel);
     if (currentLevel is SpecialWorld)
     {
         SpecialWorld specialWorld = currentLevel as SpecialWorld;
         CheckEnemiesBulletsCollision(player, specialWorld);
         CheckPlayerBulletsCollison(player, specialWorld);
     }
 }
コード例 #2
0
 private void CheckEnemiesBulletsCollision(Player player, SpecialWorld specialWorld)
 {
     foreach (Tank tank in specialWorld.AllTanks)
     {
         for (int i = 0; i < tank.ShootedBullets.Count; i++)
         {
             if (tank.ShootedBullets[i].CollisionRectangle.Intersects(player.CollisionRectangle))
             {
                 player.UpdateHealth(tank.ShootedBullets[i]);
                 tank.ShootedBullets.RemoveAt(i);
             }
         }
     }
 }
コード例 #3
0
        private void CheckPlayerBulletsCollison(Player player, SpecialWorld specialWorld)
        {
            for (int i = 0; i < player.ShootedBullets.Count; i++)
            {
                Bullet bullet = player.ShootedBullets[i];

                for (int j = 0; j < specialWorld.AllTanks.Count; j++)
                {
                    Tank tank = specialWorld.AllTanks[j];

                    if (bullet.CollisionRectangle.Intersects(tank.CollisionRectangle))
                    {
                        tank.UpdateHealth(bullet);
                        player.ShootedBullets.RemoveAt(i);

                        if (tank.IsDestroyed)
                        {
                            GameSounds.PlayExplosionSound();
                            specialWorld.AllTanks.RemoveAt(j);
                        }
                    }
                }
            }
        }