Exemple #1
0
        /// <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>
 /// Construct a DefaultEntity.
 /// </summary>
 /// <param name="position">The initial position of the entity.</param>
 /// <param name="orientation">The initial orientation of the entity.</param>
 /// <param name="mass">The mass of the entity.</param>
 /// <param name="boundingRadius">The minimal radius of the sphere which entirly encloses the entity.</param>
 /// <param name="hull">The collision detection hull of the entity.</param>
 /// <param name="collisionHandler">The entity collision handler.</param>
 /// <param name="environment">The enviroment in which the entity resides, used to calculate gravity strength, etc.
 /// </param>
 /// <param name="coefficientOfAirResistance">The strength of air resistance, high values mean increased air resistance.
 /// </param>
 public DefaultEntity
 (
     Vector3 position,
     Vector3 orientation,
     float mass,
     float boundingRadius,
     Hull hull,
     CollisionHandler collisionHandler,
     PhysicsParameters physicsParameters,
     float coefficientOfAirResistance
 )
     : base(position, orientation, mass, boundingRadius, hull, collisionHandler)
 {
     this._parameters = physicsParameters;
     this._coefficientOfAirResistance = coefficientOfAirResistance;
 }