Esempio n. 1
0
        /*
         * Resests the game objects and some variables to the starting configurations.
         * Much of this is very similar to the LoadContent method.
         */
        private void ResetGame()
        {
            //Settings to reset to start a new game
            retrievedFuelCells = 0;
            menuScreenCounter = 0;
            stepCounter = 0;
            playerHealth = GameConstants.PlayerStartHealth;

            //Create new fuelcells, turrets and missiles
            fuelCells = new FuelCell[numFuelCells];
            turrets = new Turret[numTurrets];
            readyMissiles = new List<Missile>();
            firedMissiles = new List<Missile>();

            //Load the fuelcells, turrets and missiles in the same way they were loaded in LoadContent
            for (int i = 0; i < numFuelCells; i++)
            {
                Vector3 axis = new Vector3((float)(random.NextDouble() - 0.5), (float)(random.NextDouble() - 0.5), (float)(random.NextDouble() - 0.5));
                float angle = (float)random.NextDouble() * 6.242f;
                fuelCells[i] = new FuelCell();
                fuelCells[i].LoadContent(Content, "Models/fuelcell", axis, angle, planet.BoundingSphere);
            }

            for (int i = 0; i < numTurrets; i++)
            {
                Vector3 axis = new Vector3((float)(random.NextDouble() - 0.5), (float)(random.NextDouble() - 0.5), (float)(random.NextDouble() - 0.5));
                float angle = (float)random.NextDouble() * 6.242f;
                turrets[i] = new Turret();
                turrets[i].LoadContent(Content, "Models/turret", axis, angle, planet.BoundingSphere);
            }

            for (int i = 0; i < GameConstants.NumMissiles; i++)
            {
                readyMissiles.Add(new Missile());
                readyMissiles[i].LoadContent(Content, "Models/missile", spaceship);
            }

            explosions.Clear(); //Remove all occuring explosions

            //Initial spaceship starting location and rotation
            spaceship.Position = new Vector3(0, 300, 1000);
            spaceship.Rotation = Quaternion.Identity;
            exhaustParticleEmitter = new ParticleEmitter(fireParticles, 1000, spaceship.Position);
        }
Esempio n. 2
0
        /// <summary>
        /// Load all game objects with their models, as well ad initialising sounds and other 
        /// entities used in the game.  Sets up spaceship starting location.
        /// </summary>
        protected override void LoadContent()
        {
            //Create a new SpriteBatch, which can be used to draw 2D graphics.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            //Create a graphics device variable
            device = graphics.GraphicsDevice;

            //Load content of misc game entities
            statsFont = Content.Load<SpriteFont>("Fonts/stats_font");
            skyboxEffect = Content.Load<Effect>("Effects/skybox_effect");
            splashScreenTexture = Content.Load<Texture2D> ("Images/splash_screen");

            //Load object models
            spaceship.LoadContent(Content, "Models/spaceship");
            planet.LoadContent(Content, "Models/planet");
            boundingSphere.Model = Content.Load<Model>("Models/sphere");
            skyboxModel = LoadSkyboxModel("Models/skybox", out skyboxTextures);

            //Iteratively load content for fuelcells, also generate the random seeds which will be used in calculating positions and rotation
            for (int i = 0; i < numFuelCells; i++)
            {
                Vector3 axis = new Vector3((float)(random.NextDouble() - 0.5), (float)(random.NextDouble() - 0.5), (float)(random.NextDouble() - 0.5));
                float angle = (float)random.NextDouble() * 6.242f;
                fuelCells[i] = new FuelCell();
                fuelCells[i].LoadContent(Content, "Models/fuelcell", axis, angle, planet.BoundingSphere);
            }

            //turrets loaded in the same was as fuelcells
            for (int i = 0; i < numTurrets; i++)
            {
                Vector3 axis = new Vector3((float)(random.NextDouble() - 0.5), (float)(random.NextDouble() - 0.5), (float)(random.NextDouble() - 0.5));
                float angle = (float)random.NextDouble() * 6.242f;
                turrets[i] = new Turret();
                turrets[i].LoadContent(Content, "Models/turret", axis, angle, planet.BoundingSphere);
            }

            //Populate the ready missile array with all the missiles
            for (int i = 0; i < GameConstants.NumMissiles; i++)
            {
                readyMissiles.Add(new Missile());
                readyMissiles[i].LoadContent(Content, "Models/missile", spaceship);
            }

            //Load sounds, and start playing music
            explosionSound = Content.Load<SoundEffect>("Sound/explosion");
            fuelCellPickupSound = Content.Load<SoundEffect>("Sound/fuelcell_pickup");
            music = Content.Load<Song>("Sound/music");
            MediaPlayer.Play(music);

            //Initial spaceship starting location and rotation
            spaceship.Position = new Vector3(0, 300, 1000);
            spaceship.Rotation = Quaternion.Identity;
            exhaustParticleEmitter = new ParticleEmitter(fireParticles, 1000, spaceship.Position);
        }