예제 #1
0
        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            Model asteroid = ((Game1)Game).Content.Load<Model>(@"Models/LargeAsteroid");
            //Example Asteroids.
            Asteroid asteroid1 = new Asteroid((Game1)Game, asteroid, new Vector3(0, 0, -1500));

            models.Add(asteroid1);

            base.Initialize();
        }
예제 #2
0
        public void GenerateAsteroids(int amountToGenerate)
        {
            List<Asteroid> createdAsteroids = new List<Asteroid>();
            Model asteroidModel = ((Game1)Game).Content.Load<Model>(@"Models/AsteroidModel");

            Random randomValue = new Random();

            for (int i = 0; i < amountToGenerate; i++)
            {
                //Creates an asteroid
                Asteroid temp = new Asteroid(game, asteroidModel, new Vector3((float)randomValue.Next((int)Misc.Settings.LEFT_REGION_SPAWN_BOUNDARY, (int)Misc.Settings.RIGHT_REGION_SPAWN_BOUNDARY), (float)randomValue.Next((int)Misc.Settings.BOTTOM_REGION_SPAWN_BOUNDARY, (int)Misc.Settings.TOP_REGION_SPAWN_BOUNDARY), (float)randomValue.Next(Misc.Settings.Z_REGION_SPAWN_BOUNDARY, (int)((Game1)Game).playerShip.position.Z) - 50), ref randomValue);

                //Checks to make sure this asteroid does not conflict with existing asteroids.
                for (int j = 0; j < models.Count; j++)
                {
                    //If it conflicts, generate a new one and rescan the list of models.
                    if (temp.CollidesWith(models[j].model, models[j].GetWorld()))
                    {
                        temp = new Asteroid(game, asteroidModel, new Vector3((float)randomValue.Next((int)Misc.Settings.LEFT_REGION_SPAWN_BOUNDARY, (int)Misc.Settings.RIGHT_REGION_SPAWN_BOUNDARY), (float)randomValue.Next((int)Misc.Settings.BOTTOM_REGION_SPAWN_BOUNDARY, (int)Misc.Settings.TOP_REGION_SPAWN_BOUNDARY), (float)randomValue.Next(Misc.Settings.Z_REGION_SPAWN_BOUNDARY, (int)((Game1)Game).playerShip.position.Z) - 50), ref randomValue);
                        j = 0;
                    }
                }

                //Success!  Add it to the list.
                models.Add(temp);
            }
        }