/// <summary> /// Constructs a new projectile. /// </summary> public Projectile(ParticleSystem explosionParticles, ParticleSystem explosionSmokeParticles, ParticleSystem projectileTrailParticles) { this.explosionParticles = explosionParticles; this.explosionSmokeParticles = explosionSmokeParticles; // Start at the origin, firing in a random (but roughly upward) direction. position = Vector3.Zero; velocity.X = (float)(random.NextDouble() - 0.5) * sidewaysVelocityRange; velocity.Y = (float)(random.NextDouble() + 0.5) * verticalVelocityRange; velocity.Z = (float)(random.NextDouble() - 0.5) * sidewaysVelocityRange; // Use the particle emitter helper to output our trail particles. trailEmitter = new ParticleEmitter(projectileTrailParticles, trailParticlesPerSecond, position); }
/* * 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); }
Vector3 position; //The explosions position in space #endregion Fields #region Constructors /// <summary> /// Creates a new game explosion. /// </summary> /// <param name="particleSystem">The particle system to emit particles with</param> /// <param name="position">The position to place the particle emitter</param> public Explosion(ParticleSystem particleSystem, Vector3 position) { Age = 0; this.position = position; explosionParticleEmitter = new ParticleEmitter(particleSystem, 1000, position); }
/// <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); }