예제 #1
0
        /// <summary>
        /// Creates a ship at a random location in the world in a random direction
        /// </summary>
        public void Respawn(Ship ship)
        {
            // find random empty location in the world
            FindRandomLocation(ship);

            // make a new normalized direction vector pointing up
            Vector2D dir = new Vector2D(0, -1);

            dir.Normalize();

            // make a randomizing object
            Random r         = new Random();
            int    randAngle = r.Next(0, 360);

            //rotate by random angle
            dir.Rotate(randAngle);

            // sets a random direction for the ship
            ship.SetDirection(dir);

            // reset ship's velocity
            ship.SetVelocity(new Vector2D(0, 0));

            // if dead ship is king
            if (ship.IsKing())
            {
                // hit points go up beacuse ship is now king
                ship.SetHP(startingHitPoints + 3);
            }
            else
            {
                // reset the ship's health to original health
                ship.SetHP(startingHitPoints);
            }

            // reset ships death timer
            ship.ResetRespawnTimer();
        }