Beispiel #1
0
        /// <summary>
        /// Checks for collisions.
        /// </summary>
        private static void CollisionChecks()
        {
            // Only check alive ships
            foreach (Ship ship in world.GetShips())
            {
                if (IsConnected(ship.id))
                {
                    if (ship.HP > 0)
                    {
                        // Check for Collisions of Stars and ships
                        foreach (Star star in world.GetStars())
                        {
                            if ((star.Loc - ship.Loc).Length() < starSize)
                            {
                                ship.HP = 0;
                                new Thread(() => Respawn(ship)).Start();
                            }
                        }

                        // Check for Collisions of projectiles and ships
                        foreach (Projectile projectile in world.GetProjectiles())
                        {
                            if (projectile.Owner != ship.id)
                            {
                                if ((ship.Loc - projectile.Loc).Length() < shipSize)
                                {
                                    ship.HP--;
                                    projectile.Alive = false;
                                    //DB - increment Hits
                                    Ship shooter = world.GetShip(projectile.Owner);
                                    shooter.Hits++;

                                    if (ship.HP == 0)
                                    {
                                        world.AddPoint(projectile.Owner);
                                        new Thread(() => Respawn(ship)).Start();
                                    }
                                }
                            }
                        }
                    }
                }
            }

            // Check for Collisions of projectiles and stars
            foreach (Star star in world.GetStars())
            {
                foreach (Projectile projectile in world.GetProjectiles())
                {
                    if ((star.Loc - projectile.Loc).Length() < starSize)
                    {
                        projectile.Alive = false;
                    }
                }
            }
        }