/// <summary>
 /// The default constructor for a collision between a bullet and an asteroid.
 /// </summary>
 /// <param name="elasticity">The elasticity that will be used for the collision.</param>
 /// <param name="soundBank">A reference to the game's SoundBank.</param>
 /// <param name="bullets">A reference to the list of bullets.</param>
 /// <param name="asteroids">A reference to the list of asteroids.</param>
 /// <param name="explosions">A reference to the list of explosions.</param>
 public BulletAsteroidCollision(float elasticity, SoundBank soundBank, BulletList bullets, AsteroidList asteroids, ExplosionList explosions) : base(elasticity)
 {
     this.soundBank  = soundBank;
     this.bullets    = bullets;
     this.asteroids  = asteroids;
     this.explosions = explosions;
 }
Esempio n. 2
0
 /// <summary>
 /// Default constructor for a collision between the ship and an asteroid.
 /// </summary>
 /// <param name="soundBank">A reference to the game's SoundBank.</param>
 /// <param name="explosions">A reference to the list of explosions.</param>
 /// <param name="ship">A reference to the ship.</param>
 /// <param name="asteroids">A reference to the list of asteroids.</param>
 public ShipAsteroidCollision(SoundBank soundBank, ExplosionList explosions, Ship ship, AsteroidList asteroids)
     : base()
 {
     this.soundBank  = soundBank;
     this.explosions = explosions;
     this.ship       = ship;
     this.asteroids  = asteroids;
 }
Esempio n. 3
0
 /// <summary>
 /// The default constructor for a list of bullets.
 /// </summary>
 /// <param name="maxBullets">The maximum number of bullets that can be active at any time.</param>
 /// <param name="bulletSpeed">The speed that each bullet moves.</param>
 /// <param name="radius">A radius that encloses the entire bullet model, centred at (0,0,0) in object space.</param>
 /// <param name="hull">The convex hull segment that encloses the bullet.</param>
 /// <param name="environment">A reference to the physics engine.</param>
 /// <param name="model">The model used for the bullets.</param>
 /// <param name="transforms">The graphical transforms that are applied to the bullet.</param>
 /// <param name="soundBank">A reference to the SoundBank used for the game's sound effects.</param>
 /// <param name="asteroids">A reference to the list of asteroids.</param>
 /// <param name="explosions">A reference to the list of explosions.</param>
 public BulletList(int maxBullets, float bulletSpeed, float radius, ConvexSegment hull,
                   PhysicsEngine.Environment environment, Model model, Matrix[] transforms,
                   SoundBank soundBank, AsteroidList asteroids, ExplosionList explosions)
 {
     this.bullets          = new Bullet[maxBullets];
     this.bulletVelocity   = new Vector3(0, 0, (-1) * bulletSpeed);
     this.bulletRadius     = radius;
     this.hulls            = new ConvexHull[] { new ConvexHull(hull, Matrix.CreateScale(GameConstants.bulletScale)) };
     this.physics          = environment;
     this.bulletModel      = model;
     this.bulletTransforms = transforms;
     this.soundBank        = soundBank;
     this.asteroids        = asteroids;
     this.explosions       = explosions;
 }
Esempio n. 4
0
        /*************************************************************************************************************************/

        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // Load object models
            Model asteroidModel  = Content.Load <Model>(@"Models\asteroid1");
            Model shipModel      = Content.Load <Model>(@"Models\p1_wedge");
            Model bulletModel    = Content.Load <Model>(@"Models\pea_proj");
            Model boundaryModel  = Content.Load <Model>(@"Models\asteroid1");
            Model explosionModel = Content.Load <Model>(@"Models\Particle");

            // Set object graphical transforms
            Matrix[] asteroidTransforms  = CommonFunctions.SetupEffectDefaults(asteroidModel, camera);
            Matrix[] shipTransforms      = CommonFunctions.SetupEffectDefaults(shipModel, camera);
            Matrix[] bulletTransforms    = CommonFunctions.SetupEffectDefaults(bulletModel, camera);
            Matrix[] boundaryTransforms  = CommonFunctions.SetupEffectDefaults(boundaryModel, camera);
            Matrix[] explosionTransforms = CommonFunctions.SetupEffectDefaults(explosionModel, camera);

            // Load object hulls
            ConvexSegment asteroidHull = PhysicsEngine.CommonFunctions.LoadConvexHull(
                new System.IO.StreamReader(@"..\..\..\Content\Hulls\Asteroid1.hull"));
            ConvexSegment shipHull = PhysicsEngine.CommonFunctions.LoadConvexHull(
                new System.IO.StreamReader(@"..\..\..\Content\Hulls\Ship.hull"));
            ConvexSegment bulletHull = PhysicsEngine.CommonFunctions.LoadConvexHull(
                new System.IO.StreamReader(@"..\..\..\Content\Hulls\Projectile.hull"));

            // Create all game elements
            asteroids = new AsteroidList(GameConstants.numAsteroids, 70.0f, asteroidHull,
                                         physics, asteroidModel, asteroidTransforms);

            explosions = new ExplosionList(GameConstants.maxExplosions, physics, explosionModel, explosionTransforms);

            bullets = new BulletList(GameConstants.maxBullets, GameConstants.bulletSpeed, 25.0f, bulletHull, physics, bulletModel,
                                     bulletTransforms, soundBank, asteroids, explosions);

            ship = new Ship(70.0f, shipHull, physics, shipModel, shipTransforms,
                            new Vector3(GameConstants.playfieldSizeX / 2, GameConstants.playfieldSizeY / 2, 0), 0, soundBank, explosions, asteroids);

            // Prepare the perimeter
            perimeter = new AsteroidPerimeter(boundaryModel, boundaryTransforms);

            // Load the background texture
            stars = Content.Load <Texture2D>("Textures/B1_stars");

            // Load the font
            lucidaConsole = Content.Load <SpriteFont>("Fonts/Lucida Console");
        }
Esempio n. 5
0
 /// <summary>
 /// The default constructor for a bullet.
 /// </summary>
 /// <param name="radius">A radius that encloses the entire bullet model, centred at (0,0,0) in object space.</param>
 /// <param name="hulls">The convex hull segments that enclose the bullet.</param>
 /// <param name="environment">A reference to the physics engine.</param>
 /// <param name="model">The model used for the bullets.</param>
 /// <param name="transforms">The graphical transforms that are applied to the bullet.</param>
 /// <param name="initialPosition">The initial position of the bullet.</param>
 /// <param name="initialVelocity">The initial velocity of the bullet.</param>
 /// <param name="soundBank">A reference to the SoundBank used for the game's sound effects.</param>
 /// <param name="bullets">A reference to the list of bullets.</param>
 /// <param name="asteroids">A reference to the list of asteroids.</param>
 /// <param name="explosions">A reference to the list of explosions.</param>
 public Bullet(float radius, ConvexHull[] hulls, PhysicsEngine.Environment environment, Model model, Matrix[] transforms,
               Vector3 initialPosition, Vector3 initialVelocity, SoundBank soundBank, BulletList bullets, AsteroidList asteroids, ExplosionList explosions)
 {
     physicsReference = new NonForceEntity(initialPosition, Vector3.Up, 25, radius, new Hull(hulls), new BulletAsteroidCollision(1.0f, soundBank, bullets, asteroids, explosions));
     environment.Add(physicsReference);
     this.bulletModel          = model;
     this.transforms           = transforms;
     physicsReference.Velocity = initialVelocity;
 }
Esempio n. 6
0
        /// <summary>
        /// The default constructor for the ship class.
        /// </summary>
        /// <param name="radius">An estimate to the radius that encloses the ship, measured from (0,0,0) in object space.</param>
        /// <param name="hull">The convex hull for the ship model.</param>
        /// <param name="environment">A reference to the physics engine.</param>
        /// <param name="model">The model used to draw the ship.</param>
        /// <param name="transforms">The graphics transforms to be applied to the model.</param>
        /// <param name="initialPosition">The initial position of the ship.</param>
        /// <param name="initialSpeed">The initial speed of the ship.</param>
        /// <param name="soundBank">A reference to the game's SoundBank.</param>
        /// <param name="explosions">A reference to the list of explosions.</param>
        /// <param name="asteroids">A reference to the list of asteroids.</param>
        public Ship(float radius, ConvexSegment hull, PhysicsEngine.Environment environment, Model model, Matrix[] transforms,
                    Vector3 initialPosition, float initialSpeed, SoundBank soundBank, ExplosionList explosions, AsteroidList asteroids)
        {
            ConvexHull[] hulls = new ConvexHull[] { new ConvexHull(hull, Matrix.CreateScale(GameConstants.shipScale)) };
            physicsReference = new NonForceEntity(initialPosition, Vector3.Up, 25.0f, radius, new Hull(hulls),
                                                  new ShipAsteroidCollision(soundBank, explosions, this, asteroids));
            environment.Add(physicsReference);
            this.objectModel = model;
            this.transforms  = transforms;

            // Set the initial speed of the object
            physicsReference.Velocity = Vector3.UnitZ * initialSpeed;
            this.soundBank            = soundBank;
        }