Пример #1
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);
            }
        }