private void InitializeTransform() { aspectRatio = graphics.GraphicsDevice.Viewport.AspectRatio; //Set up Third person camera m_ThirdPersonCamera = new Camera(new Vector3(0, 18.5f, 59.5f)); m_ThirdPersonCamera.camRotation = new Vector3(0, 0, -0.17f); m_ThirdPersonCamera.camProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45), aspectRatio, 0.1f, 500.0f); //Set up First person camera m_FirstPersonCamera = new Camera(new Vector3(-16, 30, 6)); m_FirstPersonCamera.camRotation = new Vector3(0, 0.3f, -1.5f); m_FirstPersonCamera.camProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45), aspectRatio, 0.1f, 500.0f); //Set main camera to the third person camera m_mainCamera = m_ThirdPersonCamera; }
protected void KeyboardInput() { // TODO: Add your update logic here KeyboardState keyboardState = Keyboard.GetState(); GamePadState gamePadState = GamePad.GetState(PlayerIndex.One); //Exit the game if (keyboardState.IsKeyDown(Keys.Escape)) { this.Exit(); } if (m_debugMode == true) { if (keyboardState.IsKeyDown(Keys.A)) { //Move camera left m_mainCamera.MoveCamera(new Vector3(-0.5f, 0, 0)); } if (keyboardState.IsKeyDown(Keys.D)) { //Move camera right m_mainCamera.MoveCamera(new Vector3(0.5f, 0, 0)); } if (keyboardState.IsKeyDown(Keys.W)) { //Move camera up m_mainCamera.MoveCamera(new Vector3(0, 0.5f, 0)); } if (keyboardState.IsKeyDown(Keys.S)) { //Move camera Down m_mainCamera.MoveCamera(new Vector3(0, -0.5f, 0)); } if (keyboardState.IsKeyDown(Keys.F)) { //Move camera Back m_mainCamera.MoveCamera(new Vector3(0, 0, 0.5f)); } if (keyboardState.IsKeyDown(Keys.R)) { ////Move camera forwards m_mainCamera.MoveCamera(new Vector3(0, 0, -0.5f)); } if (keyboardState.IsKeyDown(Keys.U)) { //Rotate camera left m_mainCamera.RotateCamera(new Vector3(GameVariables.camRotationSpeed, 0, 0)); } if (keyboardState.IsKeyDown(Keys.J)) { //Rotate camera right m_mainCamera.RotateCamera(new Vector3(-GameVariables.camRotationSpeed, 0, 0)); } if (keyboardState.IsKeyDown(Keys.O)) { //Pan camera up m_mainCamera.RotateCamera(new Vector3(0, 0, GameVariables.camRotationSpeed)); } if (keyboardState.IsKeyDown(Keys.L)) { //Pan camera down m_mainCamera.RotateCamera(new Vector3(0, 0, -GameVariables.camRotationSpeed)); } // Change camera type if (keyboardState.IsKeyDown(Keys.C)) { if (m_mainCamera == m_FirstPersonCamera) { m_mainCamera = m_ThirdPersonCamera; } else if (m_mainCamera == m_ThirdPersonCamera) { m_mainCamera = m_FirstPersonCamera; } } // Render collision skins (key 0) if (keyboardState.IsKeyDown(Keys.D0)) { m_PhysicsDebug = !m_PhysicsDebug; } // Toggle music (key 8) if (keyboardState.IsKeyDown(Keys.D8)) { m_playSounds = !m_playSounds; if (m_playSounds) { MediaPlayer.Play(m_mainTheme); } else if (!m_playSounds) { MediaPlayer.Stop(); } } } if (!gamePadState.IsConnected) { //Insert a coin/money once each time the key is pressed if (keyboardState.IsKeyDown(Keys.B) && m_coinInsertedOnceChecker == true) { //If the player has money if (m_Money > 0) { //Play sound effect and manage the money if (m_playSounds) m_insertCoinSE.Play(); m_coinsInserted++; m_Money--; m_coinInsertedOnceChecker = false; } } else if (keyboardState.IsKeyUp(Keys.B)) { //Allow money to be inserted if the key is released m_coinInsertedOnceChecker = true; } } if (keyboardState.IsKeyDown(Keys.D9)) { m_debugMode = !m_debugMode; } }
//This deviates from standard source(16Nov10). I added an argument for a Camera class object public DebugDrawer(Game game, Camera camera) : base(game) { this.vertexData = new List<VertexPositionColor>(); this.camera = camera; }
public void UFOLogic() { KeyboardState keyboardState = Keyboard.GetState(); GamePadState gamePadState = GamePad.GetState(PlayerIndex.One); //Grabbing dropping states for logic if (m_ufoState == e_UFOStates.e_freeRoam) { //If there is atleast 1 coin inserted allow the player to move the UFO if (m_coinsInserted > 0) { if (keyboardState.IsKeyDown(Keys.Left) || gamePadState.DPad.Left == ButtonState.Pressed) { m_UFOController.force0 = new Vector3(-GameVariables.ufoMoveSpeed, 0, 0); } else if (keyboardState.IsKeyDown(Keys.Right) || gamePadState.DPad.Right == ButtonState.Pressed) { m_UFOController.force0 = new Vector3(GameVariables.ufoMoveSpeed, 0, 0); } else if (keyboardState.IsKeyDown(Keys.Up) || gamePadState.DPad.Up == ButtonState.Pressed) { m_UFOController.force0 = new Vector3(0, 0, -GameVariables.ufoMoveSpeed); } else if (keyboardState.IsKeyDown(Keys.Down) || gamePadState.DPad.Down == ButtonState.Pressed) { m_UFOController.force0 = new Vector3(0, 0, GameVariables.ufoMoveSpeed); } //Set the UFO to grab if (keyboardState.IsKeyDown(Keys.Space) || gamePadState.Buttons.A == ButtonState.Pressed) { //Clear forces and set all forces to 0 so the UFO doesn't move based on previous moving forces. m_UFO.m_body.ClearForces(); m_UFO.m_body.Velocity = new Vector3(0, 0, 0); m_UFOController.force0 = Vector3.Zero; //Remove a try/coin m_coinsInserted--; //Play grabbing Sound effect if (m_playSounds) m_UFObeamingSE.Play(); //Change state to grabbing m_ufoState = e_UFOStates.e_grabbing; } } } else if (m_ufoState == e_UFOStates.e_grabbing) { m_mainCamera = m_FirstPersonCamera; //Move UFO down m_UFOController.force0 = new Vector3(0, -GameVariables.grabSpeed, 0); } else if (m_ufoState == e_UFOStates.e_moveBackUp) { //If the body of the UFO is not at/around the original position if (m_UFO.m_body.Position.Y < m_UFO.m_GOPos.Y) { //Move it back up m_UFOController.force0 = new Vector3(0, GameVariables.grabSpeed, 0); } //If it has else if (m_UFO.m_body.Position.Y >= m_UFO.m_GOPos.Y) { //Clear all forces again so it doesn't move higher m_UFO.m_body.ClearForces(); m_UFO.m_body.Velocity = new Vector3(0, 0, 0); m_UFOController.force0 = Vector3.Zero; //Change state to move across m_ufoState = e_UFOStates.e_moveBackAcross; } } else if (m_ufoState == e_UFOStates.e_moveBackAcross) { //Seek to the original position with slowing down algorithm based on the steering paper Vector3 targetOffset = m_UFO.m_GOPos - m_UFO.m_body.Position; float distance = targetOffset.Length(); float rampedSpeed = GameVariables.ufoMoveSpeed * (distance/50); float clippedSpeed = MathHelper.Min(rampedSpeed, GameVariables.ufoMoveSpeed); Vector3 desiredVelocity = (clippedSpeed/distance) * targetOffset; Vector3 steering = desiredVelocity - m_UFO.m_body.Velocity; m_UFOController.force0 = steering; //If the UFO is within the distance from the starting point if (distance <= 0.5f) { //Clear forces m_UFO.m_body.ClearForces(); m_UFO.m_body.Velocity = new Vector3(0, 0, 0); m_UFOController.force0 = Vector3.Zero; //Change state to drop the prizes m_ufoState = e_UFOStates.e_drop; } } else if (m_ufoState == e_UFOStates.e_drop) { //Drop all prizes. The ones grabbed will fall while the ones not grabbed will stay still foreach (Prize ob in m_prizesList) { ob.Drop(); } m_mainCamera = m_ThirdPersonCamera; //Allow the player to move again m_ufoState = e_UFOStates.e_freeRoam; } }
public virtual void Render(DebugDrawer debugDrawer, Camera cam) { foreach (ModelMesh mesh in m_GOModel.Meshes) { //This is where the mesh orientation is set foreach (BasicEffect effect in mesh.Effects) { effect.EnableDefaultLighting(); if (m_body.CollisionSkin != null) effect.World = m_GOModelTransforms[mesh.ParentBone.Index] * Matrix.CreateScale(m_GOScale) * m_body.CollisionSkin.GetPrimitiveLocal(0).Transform.Orientation * m_body.Orientation * Matrix.CreateFromYawPitchRoll(m_GORot.X, m_GORot.Y, m_GORot.Z) * Matrix.CreateTranslation(m_body.Position); else effect.World = m_GOModelTransforms[mesh.ParentBone.Index] * Matrix.CreateScale(m_GOScale) * m_body.Orientation * Matrix.CreateFromYawPitchRoll(m_GORot.X, m_GORot.Y, m_GORot.Z) * Matrix.CreateTranslation(m_body.Position); effect.Projection = cam.camProjectionMatrix; effect.View = cam.camViewMatrix; //render fog for all models. effect.SpecularPower = 2; effect.FogEnabled = true; effect.FogColor = Color.Black.ToVector3(); effect.FogStart = 70; effect.FogEnd = 80; if (m_textured) { effect.TextureEnabled = true; } else { effect.TextureEnabled = false; } } //Draw the mesh, will use the effects set above. mesh.Draw(); } }