示例#1
0
        // Spawn a new Superman enemy at a random location
        private void SpawnSuperman()
        {
            /*
             *  Renerate random Location
             */

            // for X location: Spawn in between 100 left to 100 right -> Domain is from 100 to 700 Horizontally
            int x = GetRandomLocation(GameVariables.SPAWN_LOCATION_MIN, graphics.PreferredBackBufferWidth - 2 * GameVariables.SPAWN_LOCATION_MIN);
            // for Y location: Spawn in between 100 top to 100 down -> Domain is from 100 to 500 Vertically
            int y = GetRandomLocation(GameVariables.SPAWN_LOCATION_MIN, graphics.PreferredBackBufferHeight - 2 * GameVariables.SPAWN_LOCATION_MIN);

            /*
             *  Renerate random Speed for Superman
             */
            float speed = GetRandomSpeed(GameVariables.SUPERMAN_MAX_SPEED);
            float angle = RandomGenerator.NextFloat((float)Math.PI * 2);

            Vector2 velocity = new Vector2((float)(speed * Math.Cos(angle)), (float)(speed * Math.Sin(angle)));

            /*
             *  Make a new Alive Man of Steel
             */
            Console.WriteLine(x + y);
            Superman newSuperMan = new Superman(Content, "superfat", x, y, velocity, SupermanShoot, SupermanGetHit);

            //make the superman does not spawn right at the collistion
            List <Rectangle> collideRectangles = getListCollideRectangles();

            while (!CollisionUtils.IsCollisionFree(newSuperMan.sRectangle, collideRectangles))
            {
                // for X location: Spawn in between 100 left to 100 right -> Domain is from 100 to 700 Horizontally
                newSuperMan.x = GetRandomLocation(GameVariables.SPAWN_LOCATION_MIN, graphics.PreferredBackBufferWidth - 2 * GameVariables.SPAWN_LOCATION_MIN);
                // for Y location: Spawn in between 100 top to 100 down -> Domain is from 100 to 500 Vertically
                newSuperMan.y = GetRandomLocation(GameVariables.SPAWN_LOCATION_MIN, graphics.PreferredBackBufferHeight - 2 * GameVariables.SPAWN_LOCATION_MIN);
            }

            /*
             *  Add New Enemies
             */
            supermen.Add(newSuperMan);
        }
示例#2
0
 // Random a velocity for Superman
 private float GetRandomSpeed(float maxSpeed)
 {
     return(GameVariables.SUPERMAN_MIN_SPEED + RandomGenerator.NextFloat(GameVariables.SUPERMAN_MAX_SPEED));
 }