public GameObject(float radius, ConvexSegment hull, PhysicsEngine.Environment environment, Model model, Matrix[] transforms) { ConvexHull[] hulls = new ConvexHull[] { new ConvexHull(hull, Matrix.Identity) }; physicsReference = new GameEntity(radius, new Hull(hulls), environment); environment.Add(physicsReference); this.objectModel = model; this.transforms = transforms; }
/// <summary> /// The default constructor for the list of asteroids. /// </summary> /// <param name="maxAsteroids">The maximum number of asteroids that can be active at any time.</param> /// <param name="radius">A radius that encloses the entire asteroid model, centred at (0,0,0) in object space.</param> /// <param name="hull">The convex hull segment that enclose the asteroid.</param> /// <param name="environment">A reference to the physics engine.</param> /// <param name="model">The model used for the asteroids.</param> /// <param name="transforms">The graphical transforms that are applied to the asteroid.</param> public AsteroidList(int maxAsteroids, float radius, ConvexSegment hull, PhysicsEngine.Environment environment, Model model, Matrix[] transforms) { this.asteroids = new Asteroid[maxAsteroids]; this.asteroidRadius = radius; this.hulls = new ConvexHull[] { new ConvexHull(hull, Matrix.CreateScale(GameConstants.asteroidScale)) }; this.physics = environment; this.asteroidModel = model; this.asteroidTransforms = transforms; }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // Set up camera GameVariables.screenWidth = graphics.GraphicsDevice.Viewport.Width; GameVariables.screenHeight = graphics.GraphicsDevice.Viewport.Height; camera = new Camera(); aspectRatio = (float)graphics.GraphicsDevice.Viewport.Width / (float)graphics.GraphicsDevice.Viewport.Height; camera.SetUpViewAndProjectionMatrices(aspectRatio); gameMode = GameVariables.initialGameMode; controls = new PlayerControls(); score = new Score(); // Set up physics engine physics = new PhysicsEngine.Environment(); PhysicsEngine.PhysicsParameters pp = new PhysicsEngine.PhysicsParameters(); pp.Gravity = GameVariables.gravity; pp.WindSpeed = GameVariables.windSpeed; physics.PhysicsParameters = pp; // Set up physical objects (walls and balls) room = new Room(camera, Content, physics); int numberOfBalls = GameVariables.ballLayers * (GameVariables.ballLayers + 1) * (GameVariables.ballLayers + 2) / 6; Model[] ballModels = new Model[numberOfBalls + 1]; // Add 1 for the cue ball ballModels[0] = Content.Load <Model>("Models\\ball_white"); for (int i = 1; i <= numberOfBalls; i++) { if (i < 10) { ballModels[i] = Content.Load <Model>("Models\\ball_0" + i.ToString()); } else if (i <= 20) { ballModels[i] = Content.Load <Model>("Models\\ball_" + i.ToString()); } else { ballModels[i] = Content.Load <Model>("Models\\ball_extra"); } } Matrix[] ballTransforms = CommonFunctions.SetupEffectDefaults(ballModels[0], camera); ConvexSegment ballSegment = PhysicsEngine.CommonFunctions.LoadConvexHull(new System.IO.StreamReader(@"..\..\..\Content/Hulls/Ball20.hull"));//@"..\..\..\Content/Hulls/UnitCube.hull")); Hull ballHull = new Hull(new ConvexHull[] { new ConvexHull(ballSegment, Matrix.CreateScale(GameVariables.ballScale)) }); balls = new Balls(GameVariables.ballLayers, ballModels, ballHull, ballTransforms, physics); camera.TargetBall = balls.CueBall; camera.SetUpViewAndProjectionMatrices(aspectRatio); base.Initialize(); }
/// <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; }
/// <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; }
/*************************************************************************************************************************/ 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"); }
/// <summary> /// Constructs a new room. /// </summary> /// <param name="camera">The camera to be used to draw the room.</param> /// <param name="Content">The content manager to load models from.</param> /// <param name="physics">The physics environment to which the room belogns.</param> public Room(Camera camera, ContentManager Content, PhysicsEngine.Environment physics) { wallModel = Content.Load <Model>("Models\\Wall"); wallGraphicsTransforms = CommonFunctions.SetupEffectDefaults(wallModel, camera); ConvexSegment wallSegment = PhysicsEngine.CommonFunctions.LoadConvexHull(new System.IO.StreamReader(@"..\..\..\Content/Hulls/Wall.hull")); wallHull = new ConvexHull[] { new ConvexHull(wallSegment, Matrix.Identity) }; // Create wall entities leftWall = CreateWallEntity(-Vector3.UnitX, -MathHelper.PiOver2 * Vector3.UnitZ); rightWall = CreateWallEntity(Vector3.UnitX, +MathHelper.PiOver2 * Vector3.UnitZ); bottomWall = CreateWallEntity(-Vector3.UnitY, 0.0f * Vector3.UnitX); topWall = CreateWallEntity(Vector3.UnitY, MathHelper.Pi * Vector3.UnitX); backWall = CreateWallEntity(-Vector3.UnitZ, +MathHelper.PiOver2 * Vector3.UnitX); frontWall = CreateWallEntity(Vector3.UnitZ, -MathHelper.PiOver2 * Vector3.UnitX); physics.Add(new Entity[] { leftWall, rightWall, bottomWall, topWall, backWall, frontWall }); }
/*************************************************************************************************************************/ protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); Model boxModel = Content.Load <Model>(@"Models\Colour_Cube"); Matrix[] boxTransforms = CommonFunctions.SetupEffectDefaults(boxModel, camera); ConvexSegment hull = PhysicsEngine.CommonFunctions.LoadConvexHull(new System.IO.StreamReader(@"..\..\..\Content\Hulls\QUTCube.hull")); box = new GameObject[GameConstants.numberOfObjects]; for (int i = 0; i < box.Length; ++i) { box[i] = new GameObject(70.0f, hull, physics, boxModel, boxTransforms); } aspectRatio = (float)graphics.GraphicsDevice.Viewport.Width / (float)graphics.GraphicsDevice.Viewport.Height; graphics.GraphicsDevice.RenderState.CullMode = CullMode.CullCounterClockwiseFace; }