/// <summary> /// Does all the keyboard checking /// </summary> /// <param name="time">Ellapsed time for last step</param> public void keyBoardChecks(float time) { KeyboardState state = Keyboard.GetState(); #region "Player 1" if (index == PlayerIndex.One) { #region "Extra Controls (Camera)" if (state.IsKeyDown(Keys.F1) && oldState.IsKeyUp(Keys.F1)) cameraType = cameraType.Equals(CurrentCam.Chase) ? CurrentCam.FirstPerson : CurrentCam.Chase; if (state.IsKeyDown(Keys.R) && oldState.IsKeyUp(Keys.R)) Controller.GridDataCollection.tryCaptureTower(this); if (state.IsKeyDown(Keys.V) && oldState.IsKeyUp(Keys.V)) getNewTarget(); if (state.IsKeyDown(Keys.B) && oldState.IsKeyUp(Keys.B)) drawMapBool = !drawMapBool; #endregion #region "Accel Deccel checks" if (state.IsKeyDown(Keys.W)) { if (shipData.speed < maxSpeed) { shipData.speed += acceleration * time; } } else if (state.IsKeyDown(Keys.S)) { if (shipData.speed > minSpeed) { shipData.speed -= deceleration * time; } } else { if (shipData.speed > 0) { shipData.speed -= deceleration * time * 2; if (shipData.speed < 0) shipData.speed = 0; } else if (shipData.speed < 0) { shipData.speed += acceleration * time; if (shipData.speed > 0) shipData.speed = 0; } } #endregion #region "Rotations" #region "Yaw" if (state.IsKeyDown(Keys.A)) { shipData.yaw += yawSpeed * time; } if (state.IsKeyDown(Keys.D)) { shipData.yaw -= yawSpeed * time; } #endregion #region "pitch & roll" float pitch = 0; float roll = 0; if (state.IsKeyDown(Keys.I)) pitch = pitchSpeed * time; else if (state.IsKeyDown(Keys.K)) pitch = -pitchSpeed * time; if (state.IsKeyDown(Keys.J)) roll = (rollSpeed) * time; else if (state.IsKeyDown(Keys.L)) roll = -(rollSpeed) * time; shipData.roll -= roll; shipData.pitch = mouseInverted ? shipData.pitch + pitch : shipData.pitch - pitch; #endregion // Debug if (state.IsKeyDown(Keys.Space) && oldState.IsKeyUp(Keys.Space)) mouseInverted = mouseInverted ? false : true; #endregion #region "Guns" if (state.IsKeyDown(Keys.F)) { if (target != null) if (reloadTimer[1] <= 0 && numMissiles > 0) { Controller.GameController.addObject(new Objects.Missile(Game, this.target, this)); reloadTimer[1] = MissileReload; numMissiles--; } } if (state.IsKeyDown(Keys.E)) { if (reloadTimer[0] <= 0) { Controller.GameController.addObject(new Objects.Bullet(Game, this.target, this)); reloadTimer[0] = MechinegunReload; } } #endregion } #endregion #region "Player 2" if (twoPlayer) if (index == PlayerIndex.Two) { #region "Extra Controls (Camera)" if (state.IsKeyDown(Keys.F2) && oldState.IsKeyUp(Keys.F2)) cameraType = cameraType.Equals(CurrentCam.Chase) ? CurrentCam.FirstPerson : CurrentCam.Chase; if (state.IsKeyDown(Keys.PageUp) && oldState.IsKeyUp(Keys.PageUp)) Controller.GridDataCollection.tryCaptureTower(this); if (state.IsKeyDown(Keys.PageDown) && oldState.IsKeyUp(Keys.PageDown)) getNewTarget(); if (state.IsKeyDown(Keys.NumPad9) && oldState.IsKeyUp(Keys.NumPad9)) drawMapBool = !drawMapBool; #endregion #region "Accel Deccel checks" if (state.IsKeyDown(Keys.Up)) { if (shipData.speed < maxSpeed) { shipData.speed += acceleration * time; } } else if (state.IsKeyDown(Keys.Down)) { if (shipData.speed > minSpeed) { shipData.speed -= deceleration * time; } } else { if (shipData.speed > 0) { shipData.speed -= deceleration * time * 2; if (shipData.speed < 0) shipData.speed = 0; } else if (shipData.speed < 0) { shipData.speed += acceleration * time; if (shipData.speed > 0) shipData.speed = 0; } } #endregion #region "Rotations" #region "Yaw" if (state.IsKeyDown(Keys.Left)) { shipData.yaw += yawSpeed * time; } if (state.IsKeyDown(Keys.Right)) { shipData.yaw -= yawSpeed * time; } #endregion #region "pitch & roll" float pitch = 0; float roll = 0; if (state.IsKeyDown(Keys.NumPad8)) pitch = pitchSpeed * time; else if (state.IsKeyDown(Keys.NumPad5)) pitch = -pitchSpeed * time; if (state.IsKeyDown(Keys.NumPad4)) roll = (rollSpeed) * time; else if (state.IsKeyDown(Keys.NumPad6)) roll = -(rollSpeed) * time; shipData.roll -= roll; shipData.pitch = mouseInverted ? shipData.pitch + pitch : shipData.pitch - pitch; #endregion // Debug if (state.IsKeyDown(Keys.NumPad0)) mouseInverted = mouseInverted ? false : true; #endregion #region "Guns" if (state.IsKeyDown(Keys.NumPad1)) { if (reloadTimer[1] <= 0 && numMissiles > 0) { Controller.GameController.addObject(new Objects.Missile(Game, this.target, this)); reloadTimer[1] = MissileReload; numMissiles--; } } if (state.IsKeyDown(Keys.NumPad7)) { if (reloadTimer[0] <= 0) { Controller.GameController.addObject(new Objects.Bullet(Game, this.target, this)); reloadTimer[0] = MechinegunReload; } } } #endregion // reset loader for (int i = 0; i < 3; ++i) reloadTimer[i] = reloadTimer[i] > 0 ? reloadTimer[i] - (1 * time) : 0; #endregion oldState = state; }
public void xboxControls(float time) { GamePadState pad1State = GamePad.GetState(PlayerIndex.One); GamePadState pad2State = GamePad.GetState(PlayerIndex.Two); #region Player 1 if (index == PlayerIndex.One) { #region Extra Controls: Turret Capture & Camera if (pad1State.Buttons.LeftShoulder == ButtonState.Pressed && prevPadState1.Buttons.LeftShoulder == ButtonState.Released) cameraType = cameraType.Equals(CurrentCam.Chase) ? CurrentCam.FirstPerson : CurrentCam.Chase; if (pad1State.Buttons.A == ButtonState.Pressed && prevPadState1.Buttons.A == ButtonState.Released) Controller.GridDataCollection.tryCaptureTower(this); if (pad1State.Buttons.Y == ButtonState.Pressed && prevPadState1.Buttons.Y == ButtonState.Released) drawMapBool = !drawMapBool; //select new target if (pad1State.Triggers.Left >= 0.6 && prevPadState1.Triggers.Left < 0.6) getNewTarget(); #endregion #region Rotations #region yaw if (pad1State.ThumbSticks.Left.X <= -0.5) { shipData.yaw += yawSpeed * time; } if (pad1State.ThumbSticks.Left.X >= 0.5) { shipData.yaw -= yawSpeed * time; } #endregion #region Pitch & Roll float pitch = 0; float roll = 0; if (pad1State.ThumbSticks.Right.Y >= 0.5) pitch = pitchSpeed * time; else if (pad1State.ThumbSticks.Right.Y <= -0.5) pitch = -pitchSpeed * time; if (pad1State.ThumbSticks.Right.X <= -0.5) roll = (rollSpeed) * time; else if (pad1State.ThumbSticks.Right.X >= 0.5) roll = -(rollSpeed) * time; shipData.roll -= roll; shipData.pitch = mouseInverted ? shipData.pitch + pitch : shipData.pitch - pitch; #endregion #endregion #region Accel Deccel checks if (pad1State.ThumbSticks.Left.Y >= 0.6) { if (shipData.speed < maxSpeed) { shipData.speed += acceleration * time; } } else if (pad1State.ThumbSticks.Left.Y <= -0.6) { if (shipData.speed > minSpeed) { shipData.speed -= deceleration * time; } } else { if (shipData.speed > 0) { shipData.speed -= deceleration * time * 2; if (shipData.speed < 0) shipData.speed = 0; } else if (shipData.speed < 0) { shipData.speed += acceleration * time; if (shipData.speed > 0) shipData.speed = 0; } } #endregion #region Guns //fire missile if (pad1State.Buttons.B == ButtonState.Pressed) { if (reloadTimer[1] <= 0 && numMissiles > 0) { Controller.GameController.addObject(new Objects.Missile(Game, this.target, this)); reloadTimer[1] = MissileReload; numMissiles--; } } //fire cannon if (pad1State.Triggers.Right >= 0.6) { if (reloadTimer[0] <= 0) { Controller.GameController.addObject(new Objects.Bullet(Game, this.target, this)); reloadTimer[0] = MechinegunReload; } } #endregion } #endregion #region Player 2 if (twoPlayer) if (index == PlayerIndex.Two) { // Allows the game to exit using XBox if (pad2State.Buttons.Start == ButtonState.Pressed) this.Game.Exit(); #region Extra Controls: Turret Capture & Camera if (pad2State.Buttons.LeftShoulder == ButtonState.Pressed && prevPadState2.Buttons.LeftShoulder == ButtonState.Released) cameraType = cameraType.Equals(CurrentCam.Chase) ? CurrentCam.FirstPerson : CurrentCam.Chase; if (pad2State.Buttons.A == ButtonState.Pressed && prevPadState2.Buttons.A == ButtonState.Released) Controller.GridDataCollection.tryCaptureTower(this); if (pad2State.Buttons.Y == ButtonState.Pressed && prevPadState2.Buttons.Y == ButtonState.Released) drawMapBool = !drawMapBool; //select new target if (pad2State.Triggers.Left >= 0.6 && prevPadState2.Triggers.Left < 0.6) getNewTarget(); #endregion #region Rotations #region yaw if (pad2State.ThumbSticks.Left.X <= -0.5) { shipData.yaw += yawSpeed * time; } if (pad2State.ThumbSticks.Left.X >= 0.5) { shipData.yaw -= yawSpeed * time; } #endregion #region Pitch & Roll float pitch = 0; float roll = 0; if (pad2State.ThumbSticks.Right.Y >= 0.5) pitch = pitchSpeed * time; else if (pad2State.ThumbSticks.Right.Y <= -0.5) pitch = -pitchSpeed * time; if (pad2State.ThumbSticks.Right.X <= -0.5) roll = (rollSpeed) * time; else if (pad2State.ThumbSticks.Right.X >= 0.5) roll = -(rollSpeed) * time; shipData.roll -= roll; shipData.pitch = mouseInverted ? shipData.pitch + pitch : shipData.pitch - pitch; #endregion #endregion #region Accel Deccel checks if (pad2State.ThumbSticks.Left.Y >= 0.6) { if (shipData.speed < maxSpeed) { shipData.speed += acceleration * time; } } else if (pad2State.ThumbSticks.Left.Y <= -0.6) { if (shipData.speed > minSpeed) { shipData.speed -= deceleration * time; } } else { if (shipData.speed > 0) { shipData.speed -= deceleration * time * 2; if (shipData.speed < 0) shipData.speed = 0; } else if (shipData.speed < 0) { shipData.speed += acceleration * time; if (shipData.speed > 0) shipData.speed = 0; } } #endregion #region Guns //fire missile if (pad2State.Buttons.B == ButtonState.Pressed) { if (reloadTimer[1] <= 0 && numMissiles > 0) { Controller.GameController.addObject(new Objects.Missile(Game, this.target, this)); reloadTimer[1] = MissileReload; numMissiles--; } } //fire cannon if (pad2State.Triggers.Right >= 0.6) { if (reloadTimer[0] <= 0) { Controller.GameController.addObject(new Objects.Bullet(Game, this.target, this)); reloadTimer[0] = MechinegunReload; } } #endregion } // reset loader for (int i = 0; i < 3; ++i) reloadTimer[i] = reloadTimer[i] > 0 ? reloadTimer[i] - (1 * time) : 0; #endregion prevPadState1 = pad1State; prevPadState2 = pad2State; }
/// <summary> /// Initialises the variables /// And for computer gets the mouse ready to control the ship /// </summary> public override void Initialize() { #region "Viewport initialization" playerViewport = Game.GraphicsDevice.Viewport; playerViewport.Width = twoPlayer ? Game.GraphicsDevice.Viewport.Width / 2 - 1 : Game.GraphicsDevice.Viewport.Width; // if player 2 it must start in a differant place if (index == PlayerIndex.Two) { playerViewport.X = Game.GraphicsDevice.Viewport.Width / 2 + 1; } #endregion #region "Camera initialization" this.cameraType = CurrentCam.Chase; chaseCamera = new BBN_Game.Camera.ChaseCamera(playerViewport.Width, playerViewport.Height); fpCamera = new BBN_Game.Camera.FirstPersonCam(playerViewport.Width, playerViewport.Height); #endregion oldState = Keyboard.GetState(); base.Initialize(); }