public override void Move(KeyboardState keys, GamePadState gpState) { //create a new temp rectangle to modify the position of the player Rectangle temp = hitBox; keys = Keyboard.GetState(); //check if a controller is connected if ((GamePad.GetState(PlayerIndex.One).IsConnected || GamePad.GetState(PlayerIndex.Two).IsConnected)) { //check which player has a controller connected if (GamePad.GetState(PlayerIndex.One).IsConnected&& player == 1) { gpState = GamePad.GetState(PlayerIndex.One); } if (GamePad.GetState(PlayerIndex.Two).IsConnected&& player == 2) { gpState = GamePad.GetState(PlayerIndex.Two); } } if (gpState.IsButtonDown(right)) { temp.X += moveSpeed; } if (gpState.IsButtonDown(left)) { temp.X -= moveSpeed; } if (gpState.IsButtonDown(up)) { temp.Y -= moveSpeed; } if (gpState.IsButtonDown(down)) { temp.Y += moveSpeed; } if (keys.IsKeyDown(keyRight)) { temp.X += moveSpeed; } if (keys.IsKeyDown(keyLeft)) { temp.X -= moveSpeed; } if (keys.IsKeyDown(keyUp)) { temp.Y -= moveSpeed; } if (keys.IsKeyDown(keyDown)) { temp.Y += moveSpeed; } hitBox = temp; }
public bool padJustReleased(GamePadState oldState, GamePadState newState, Buttons thisKey) { return(newState.IsButtonUp(thisKey) && oldState.IsButtonDown(thisKey)); }
public override void Update(GameTime gameTime) { if (!this.isRunning) { return; } // Console.WriteLine("InputController : Update"); var dt = (float)gameTime.ElapsedGameTime.TotalSeconds; // Console.WriteLine("dt " + dt); //KeyboardState keyboard = Keyboard.GetState(); //if (keyboard.IsKeyDown(Keys.Space) && // prev_kb.IsKeyUp(Keys.Space)) // if (Shoot != null) // Shoot(); //prev_kb = keyboard; // Camera camera; var state = Keyboard.GetState(); if (this.gamePaused != null) { if (state.IsKeyUp(Keys.P) && prev_kb.IsKeyDown(Keys.P)) { this.gamePaused(); } else if (KinectManager.getInstance().isPaused()) { this.gamePaused(); } } //exist at least one handler listening for camera events.. if (changedCamera != null) { if (state.IsKeyDown(Keys.I)) { changedCamera(Camera.CameraTransformations.MoveForward, dt); } if (state.IsKeyDown(Keys.K)) { changedCamera(Camera.CameraTransformations.MoveBackward, dt); } if (state.IsKeyDown(Keys.J)) { changedCamera(Camera.CameraTransformations.MoveLeft, dt); } if (state.IsKeyDown(Keys.L)) { changedCamera(Camera.CameraTransformations.MoveRight, dt); } if (state.IsKeyDown(Keys.Q)) { changedCamera(Camera.CameraTransformations.MoveUp, dt); } if (state.IsKeyDown(Keys.A)) { changedCamera(Camera.CameraTransformations.MoveDown, dt); } if (state.IsKeyDown(Keys.W)) { changedCamera(Camera.CameraTransformations.PitchUp, dt); } if (state.IsKeyDown(Keys.S)) { changedCamera(Camera.CameraTransformations.PitchDown, dt); } if (state.IsKeyDown(Keys.E)) { changedCamera(Camera.CameraTransformations.RollAnticlockwise, dt); } if (state.IsKeyDown(Keys.D)) { changedCamera(Camera.CameraTransformations.RollClockwise, dt); } if (state.IsKeyDown(Keys.R)) { changedCamera(Camera.CameraTransformations.YawLeft, dt); } if (state.IsKeyDown(Keys.F)) { changedCamera(Camera.CameraTransformations.YawRight, dt); } } var gamePadState = GamePad.GetState(PlayerIndex.One); if (gamePadState != null) { if (gamePadState.IsButtonDown(Buttons.Start) && prev_game_pad_state.IsButtonDown(Buttons.Start)) { this.gamePaused(); } if ((gamePadState.IsButtonDown(Buttons.LeftThumbstickUp))) { changedCamera(Camera.CameraTransformations.MoveForward, dt); } if ((gamePadState.IsButtonDown(Buttons.LeftThumbstickDown))) { changedCamera(Camera.CameraTransformations.MoveBackward, dt); } if ((gamePadState.IsButtonDown(Buttons.LeftThumbstickLeft))) { changedCamera(Camera.CameraTransformations.MoveLeft, dt); } if ((gamePadState.IsButtonDown(Buttons.LeftThumbstickRight))) { changedCamera(Camera.CameraTransformations.MoveRight, dt); } if ((gamePadState.IsButtonDown(Buttons.RightShoulder))) { changedCamera(Camera.CameraTransformations.RollAnticlockwise, dt); } if ((gamePadState.IsButtonDown(Buttons.LeftShoulder))) { changedCamera(Camera.CameraTransformations.RollClockwise, dt); } if ((gamePadState.IsButtonDown(Buttons.RightTrigger))) { changedCamera(Camera.CameraTransformations.YawRight, dt); } if ((gamePadState.IsButtonDown(Buttons.LeftTrigger))) { changedCamera(Camera.CameraTransformations.YawLeft, dt); } if ((gamePadState.IsButtonDown(Buttons.RightThumbstickUp))) { changedCamera(Camera.CameraTransformations.PitchUp, dt); } if ((gamePadState.IsButtonDown(Buttons.RightThumbstickDown))) { changedCamera(Camera.CameraTransformations.PitchDown, dt); } prev_game_pad_state = gamePadState; } prev_kb = state; base.Update(gameTime); }
/// <summary> /// Gets the latest input and uses it to update the input history buffer. /// </summary> public void Update(GameTime gameTime) { // Get latest input state. GamePadState lastGamePadState = GamePadState; GamePadState = GamePad.GetState(PlayerIndex); KeyboardState lastKeyboardState = EmptyKeyboardState; #if !XBOX // keyboard only happens from one player if (this.IsActiveController) //PlayerIndex == PlayerIndex.One) { lastKeyboardState = currentKeyboardState; currentKeyboardState = Keyboard.GetState(PlayerIndex); } else { lastKeyboardState = EmptyKeyboardState; currentKeyboardState = EmptyKeyboardState; } #endif // Expire old input. TimeSpan time = gameTime.TotalGameTime; TimeSpan timeSinceLast = time - LastInputTime; if (timeSinceLast > BufferTimeOut) { Buffer.Clear(); } // Get all of the non-direction buttons pressed. Buttons buttons = 0; Releases = 0; foreach (var buttonAndKey in NonDirectionButtons) { Buttons button = buttonAndKey.Key; Keys key = buttonAndKey.Value; // Check the game pad and keyboard for presses. if (lastGamePadState.IsButtonUp(button) && GamePadState.IsButtonDown(button)) { buttons |= button; } #if !XBOX else if (IsActiveController && (lastKeyboardState.IsKeyUp(key) && currentKeyboardState.IsKeyDown(key))) { buttons |= button; } #endif if (lastGamePadState.IsButtonDown(button) && GamePadState.IsButtonUp(button)) { Releases |= button; } #if !XBOX else if (IsActiveController && (lastKeyboardState.IsKeyDown(key) && currentKeyboardState.IsKeyUp(key))) { Releases |= button; } #endif } // It is very hard to press two buttons on exactly the same frame. // If they are close enough, consider them pressed at the same time. bool mergeInput = (Buffer.Count > 0 && timeSinceLast < MergeInputTime); // If there is a new direction, var direction = Direction.FromInput(GamePadState, currentKeyboardState); if (Direction.FromInput(lastGamePadState, lastKeyboardState) != direction) { // combine the direction with the buttons. buttons |= direction; // Don't merge two different directions. This avoids having impossible // directions such as Left+Up+Right. This also has the side effect that // the direction needs to be pressed at the same time or slightly before // the buttons for merging to work. mergeInput = false; } // If there was any new input on this update, add it to the buffer. if (buttons != 0) { if (mergeInput) { // Use a bitwise-or to merge with the previous input. // LastInputTime isn't updated to prevent extending the merge window. Buffer[Buffer.Count - 1] = Buffer[Buffer.Count - 1] | buttons; } else { // Append this input to the buffer, expiring old input if necessary. if (Buffer.Count == Buffer.Capacity) { Buffer.RemoveAt(0); } Buffer.Add(buttons); // Record this the time of this input to begin the merge window. LastInputTime = time; } } }
public void Update(GameTime gameTime) { timeSinceLastBShot += (float)gameTime.ElapsedGameTime.TotalSeconds; timeSinceLastSShot += (float)gameTime.ElapsedGameTime.TotalSeconds; timeSinceLastMShot += (float)gameTime.ElapsedGameTime.TotalSeconds; timeSinceLastRShot += (float)gameTime.ElapsedGameTime.TotalSeconds; KeyboardState keyboard = Keyboard.GetState(); GamePadState controller = GamePad.GetState(PlayerIndex.One); if (keyboard.IsKeyDown(Keys.Left) || controller.IsButtonDown(Buttons.DPadLeft)) { playerObject.Position += new Vector2(-5, 0); } if (keyboard.IsKeyDown(Keys.Right) || controller.IsButtonDown(Buttons.DPadRight)) { playerObject.Position += new Vector2(5, 0); } if (keyboard.IsKeyDown(Keys.Up) || controller.IsButtonDown(Buttons.DPadUp)) { playerObject.Position += new Vector2(0, -5); } if (keyboard.IsKeyDown(Keys.Down) || controller.IsButtonDown(Buttons.DPadDown)) { playerObject.Position += new Vector2(0, 5); } if (keyboard.IsKeyDown(Keys.D1)) { g = gunType.D1; } if (keyboard.IsKeyDown(Keys.D2)) { g = gunType.D2; } if (keyboard.IsKeyDown(Keys.D3)) { g = gunType.D3; } if (keyboard.IsKeyDown(Keys.D4)) { g = gunType.D4; } if (timeSinceLastBShot > shotCooldownB) { if ((keyboard.IsKeyDown(Keys.Space) && g == gunType.D1) || controller.IsButtonDown(Buttons.A)) { shotCooldownB = PlayerProjectiles.pBulletData.shotCooldown; PlayerProjectiles.fireBullet(playerObject.Position + new Vector2(30, 15), rotate(mShipdata.facing, playerObject.Rotation) * PlayerProjectiles.pBulletData.bulletSpeed); timeSinceLastBShot = 0.0f; } } if (timeSinceLastSShot > shotCooldownS) { if ((keyboard.IsKeyDown(Keys.Space) && g == gunType.D2) || controller.IsButtonDown(Buttons.B)) { shotCooldownS = PlayerProjectiles.pSonarData.shotCooldown; PlayerProjectiles.fireSonar(playerObject.Position + new Vector2(30, 15), rotate(mShipdata.facing, playerObject.Rotation) * PlayerProjectiles.pSonarData.bulletSpeed); timeSinceLastSShot = 0.0f; } } if (timeSinceLastMShot > shotCooldownM) { if ((keyboard.IsKeyDown(Keys.Space) && g == gunType.D3) || controller.IsButtonDown(Buttons.X)) { shotCooldownM = PlayerProjectiles.pMissileData.shotCooldown; PlayerProjectiles.fireMissile(playerObject.Position + new Vector2(30, 15), rotate(mShipdata.facing, playerObject.Rotation) * PlayerProjectiles.pMissileData.bulletSpeed); timeSinceLastMShot = 0.0f; } } if (timeSinceLastRShot > shotCooldownR) { if ((keyboard.IsKeyDown(Keys.Space) && g == gunType.D4) || controller.IsButtonDown(Buttons.Y)) { shotCooldownR = PlayerProjectiles.pRocketData.shotCooldown; PlayerProjectiles.fireRocket(playerObject.Position + new Vector2(30, 15), rotate(mShipdata.facing, playerObject.Rotation) * PlayerProjectiles.pRocketData.bulletSpeed); timeSinceLastRShot = 0.0f; } } PlayerProjectiles.Update(gameTime); }
override public void Update(GameTime time) { oldState = currentState; XboxoldState = XboxcurrentState; XboxcurrentState = GamePad.GetState(PlayerIndex.One); currentState = Keyboard.GetState(); if ((currentState.IsKeyDown(Keys.Space) && !oldState.IsKeyDown(Keys.Space)) || (currentState.IsKeyDown(Keys.Enter) && !oldState.IsKeyDown(Keys.Enter)) || (currentState.IsKeyDown(Keys.Left) && !oldState.IsKeyDown(Keys.Left)) || (XboxcurrentState.IsButtonDown(Buttons.Back) && !XboxoldState.IsButtonDown(Buttons.Back))) { ScreenManager.AddScreen(new MainMenu()); } }
private bool GetReleased(Buttons button) { return(gamePadState.IsButtonUp(button) && oldGPState.IsButtonDown(button)); }
public void Update(GameTime gameTime) { KeyboardState newKeyboardState = Keyboard.GetState(); GamePadState newGamepadState = GamePad.GetState(PlayerIndex.One); if (Mario.StarStatus) { nextFlashTime += gameTime.ElapsedGameTime.Milliseconds; if (nextFlashTime > Game1Utility.MillisecondsPerFlash) { nextFlashTime -= Game1Utility.MillisecondsPerFlash; if (flashStatus == 0) { flashStatus = 1; } else if (flashStatus == 1) { flashStatus = 0; } } } else { flashStatus = 0; } if (newKeyboardState.IsKeyDown(Keys.Left) || newGamepadState.IsButtonDown(Buttons.LeftThumbstickLeft) || newKeyboardState.IsKeyDown(Keys.A) || ((Game1.GetInstance.MouseState.X < (Mario.LocationX - Camera.CameraPositionX)) && Game1.GetInstance.MouseControl)) { if (Mario.JumpStatus && Mario.RunStatus) { if (Mario.LocationX >= Game1Utility.MovingLeftOffset) { Mario.LocationX -= 7 * Mario.EnergyStatus; } currentFrame = 1; resetFrames = true; } else if (Mario.JumpStatus) { if (Mario.LocationX >= Game1Utility.MovingLeftOffset) { Mario.LocationX -= 3 * Mario.EnergyStatus; } currentFrame = 1; resetFrames = true; } else { if (resetFrames) { currentFrame = 4; resetFrames = false; } timeSinceLastFrame += gameTime.ElapsedGameTime.Milliseconds; if (timeSinceLastFrame > millisecondsPerFrame) { timeSinceLastFrame -= millisecondsPerFrame; currentFrame--; } if (currentFrame == startFrame - totalFrames) { currentFrame = startFrame; } if (Mario.LocationX >= Game1Utility.MovingLeftOffset) { if (Mario.RunStatus == true) { Mario.LocationX -= 4 * Mario.EnergyStatus; } else { Mario.LocationX -= 2 * Mario.EnergyStatus; } } } } else if (Mario.JumpStatus) { currentFrame = 1; } else { currentFrame = 4; mario.StateMachine.MarioMode = (int)MarioStateMachine.MarioModes.Small; mario.StateMachine.Orientation = (int)MarioStateMachine.Orientations.StandingLeft; } }
public bool RequestSingleKeypress() { var keys = _keyboardState.GetPressedKeys(); if (keys.Length != 0) { return(true); } if (_padState.IsButtonDown(Buttons.A) || _padState.IsButtonDown(Buttons.B) || _padState.IsButtonDown(Buttons.X) || _padState.IsButtonDown(Buttons.Y) || _padState.IsButtonDown(Buttons.Back) || _padState.IsButtonDown(Buttons.Start) || _padState.IsButtonDown(Buttons.LeftShoulder) || _padState.IsButtonDown(Buttons.RightShoulder) || _padState.IsButtonDown(Buttons.LeftTrigger) || _padState.IsButtonDown(Buttons.RightThumbstickDown)) { return(true); } return(false); }
/// <summary> /// Helper for checking if a button was newly pressed during this update. /// </summary> public bool IsNewButtonPress(Buttons button) { return(GamePadState.IsButtonDown(button) && PreviousGamePadState.IsButtonUp(button)); }
public static bool getA() { return(keyboardState.IsKeyDown(Keys.J) || keyboardState.IsKeyDown(Keys.Z) || gamepadState.IsButtonDown(Buttons.A)); }
/// <summary> /// Handles the input and movement of the character. /// </summary> /// <param name="dt">Time since last frame in simulation seconds.</param> /// <param name="keyboardInput">Keyboard state.</param> /// <param name="gamePadInput">Gamepad state.</param> public void Update(float dt, KeyboardState keyboardInput, GamePadState gamePadInput) { //Update the wheel's graphics. for (int k = 0; k < 4; k++) { WheelModels[k].WorldTransform = Vehicle.Wheels[k].Shape.WorldTransform; } if (IsActive) { #if XBOX360 float speed = gamePadInput.Triggers.Right * ForwardSpeed + gamePadInput.Triggers.Left * BackwardSpeed; Vehicle.Wheels[1].DrivingMotor.TargetSpeed = speed; Vehicle.Wheels[3].DrivingMotor.TargetSpeed = speed; if (gamePadInput.IsButtonDown(Buttons.LeftStick)) { foreach (Wheel wheel in Vehicle.Wheels) { wheel.Brake.IsBraking = true; } } else { foreach (Wheel wheel in Vehicle.Wheels) { wheel.Brake.IsBraking = false; } } Vehicle.Wheels[1].Shape.SteeringAngle = (gamePadInput.ThumbSticks.Left.X * MaximumTurnAngle); Vehicle.Wheels[3].Shape.SteeringAngle = (gamePadInput.ThumbSticks.Left.X * MaximumTurnAngle); #else if (keyboardInput.IsKeyDown(Keys.W)) { //Drive Vehicle.Wheels[1].DrivingMotor.TargetSpeed = ForwardSpeed; Vehicle.Wheels[3].DrivingMotor.TargetSpeed = ForwardSpeed; } else if (keyboardInput.IsKeyDown(Keys.S)) { //Reverse Vehicle.Wheels[1].DrivingMotor.TargetSpeed = BackwardSpeed; Vehicle.Wheels[3].DrivingMotor.TargetSpeed = BackwardSpeed; } else { //Idle Vehicle.Wheels[1].DrivingMotor.TargetSpeed = 0; Vehicle.Wheels[3].DrivingMotor.TargetSpeed = 0; } if (keyboardInput.IsKeyDown(Keys.Space)) { //Brake foreach (Wheel wheel in Vehicle.Wheels) { wheel.Brake.IsBraking = true; } } else { //Release brake foreach (Wheel wheel in Vehicle.Wheels) { wheel.Brake.IsBraking = false; } } //Use smooth steering; while held down, move towards maximum. //When not pressing any buttons, smoothly return to facing forward. float angle; bool steered = false; if (keyboardInput.IsKeyDown(Keys.A)) { steered = true; angle = Math.Max(Vehicle.Wheels[1].Shape.SteeringAngle - TurnSpeed * dt, -MaximumTurnAngle); Vehicle.Wheels[1].Shape.SteeringAngle = angle; Vehicle.Wheels[3].Shape.SteeringAngle = angle; } if (keyboardInput.IsKeyDown(Keys.D)) { steered = true; angle = Math.Min(Vehicle.Wheels[1].Shape.SteeringAngle + TurnSpeed * dt, MaximumTurnAngle); Vehicle.Wheels[1].Shape.SteeringAngle = angle; Vehicle.Wheels[3].Shape.SteeringAngle = angle; } if (!steered) { //Neither key was pressed, so de-steer. if (Vehicle.Wheels[1].Shape.SteeringAngle > 0) { angle = Math.Max(Vehicle.Wheels[1].Shape.SteeringAngle - TurnSpeed * dt, 0); Vehicle.Wheels[1].Shape.SteeringAngle = angle; Vehicle.Wheels[3].Shape.SteeringAngle = angle; } else { angle = Math.Min(Vehicle.Wheels[1].Shape.SteeringAngle + TurnSpeed * dt, 0); Vehicle.Wheels[1].Shape.SteeringAngle = angle; Vehicle.Wheels[3].Shape.SteeringAngle = angle; } } #endif } else { //Parking brake foreach (Wheel wheel in Vehicle.Wheels) { wheel.Brake.IsBraking = true; } //Don't want the car to keep trying to drive. Vehicle.Wheels[1].DrivingMotor.TargetSpeed = 0; Vehicle.Wheels[3].DrivingMotor.TargetSpeed = 0; } }
/// <summary> /// only true if down this frame /// </summary> /// <returns><c>true</c>, if button pressed was ised, <c>false</c> otherwise.</returns> /// <param name="button">Button.</param> public bool isButtonPressed(Buttons button) { return(_currentState.IsButtonDown(button) && !_previousState.IsButtonDown(button)); }
public override void Attack(Player player1, Player player2, KeyboardState kbState, GamePadState gpState, int playerNum, double currentTime) { //proj1.HitBox.X = player1.HitBox.X + player1.HitBox.Width / 2; Diamond player = (Diamond)player1; //attack method if (kbState.IsKeyDown(player.keyAttack1) && !(prevKbState.IsKeyDown(player.keyAttack1))) { //shoot a projectile in the direction the player is moving if stationary just send it in a random direction //conditional to limit the amount of projectiles to four //if(projList.Count >= 8) //{ // projList.Clear(); // for(int i = 0; i < 8; i++) // { // projList.Add(new Projectile(7, 5, 3, i)); // projList[i].HitBox = new Rectangle(player1.HitBox.X - player1.HitBox.Width/4 - 4, player1.HitBox.Y - player1.HitBox.Height / 2, // player1.HitBox.Width/2, player1.HitBox.Height/2); // } //} //else //{ // for (int i = 0; i < 8; i++) // { // projList.Add(new Projectile(7, 5, 3, i)); // projList[i].HitBox = new Rectangle(player1.HitBox.X - player1.HitBox.Width / 4 - 4, player1.HitBox.Y - player1.HitBox.Height / 2, // player1.HitBox.Width/2, player1.HitBox.Height/2); // } //} if (count > 1) { Projectile proj; if (kbState.IsKeyDown(keyRight)) { proj = (new Projectile(7, 0)); count = 0; } else if (kbState.IsKeyDown(keyDown)) { proj = (new Projectile(7, 1)); count = 0; } else if (kbState.IsKeyDown(keyLeft)) { proj = (new Projectile(7, 2)); count = 0; } else if (kbState.IsKeyDown(keyUp)) { proj = (new Projectile(7, 3)); count = 0; } else { proj = (new Projectile(7, rng.Next(0, 4))); count = 0; } //if(projList.Count >= 2) //{ // projList.RemoveAt(0); //} proj.HitBox = new Rectangle(player1.HitBox.X + player1.HitBox.Width / 4, player1.HitBox.Y + player1.HitBox.Height / 4, player1.HitBox.Width / 2, player1.HitBox.Height / 2); projList.Add(proj); } count++; } //controller //shoot a projectile in the direction the player is moving if stationary just send it in a random direction //conditional to limit the amount of projectiles to four //if(projList.Count >= 8) //{ // projList.Clear(); // for(int i = 0; i < 8; i++) // { // projList.Add(new Projectile(7, 5, 3, i)); // projList[i].HitBox = new Rectangle(player1.HitBox.X - player1.HitBox.Width/4 - 4, player1.HitBox.Y - player1.HitBox.Height / 2, // player1.HitBox.Width/2, player1.HitBox.Height/2); // } //} //else //{ // for (int i = 0; i < 8; i++) // { // projList.Add(new Projectile(7, 5, 3, i)); // projList[i].HitBox = new Rectangle(player1.HitBox.X - player1.HitBox.Width / 4 - 4, player1.HitBox.Y - player1.HitBox.Height / 2, // player1.HitBox.Width/2, player1.HitBox.Height/2); // } //} //check if a controller is connected if ((GamePad.GetState(PlayerIndex.One).IsConnected || GamePad.GetState(PlayerIndex.Two).IsConnected)) { //check which player has a controller connected if (GamePad.GetState(PlayerIndex.One).IsConnected&& playerNum == 1) { gpState = GamePad.GetState(PlayerIndex.One); } if (GamePad.GetState(PlayerIndex.Two).IsConnected&& playerNum == 2) { gpState = GamePad.GetState(PlayerIndex.Two); } if (gpState.IsButtonDown(attack) && !(prevGpState.IsButtonDown(attack))) { if (count > 1) { Projectile proj; if (gpState.IsButtonDown(right)) { proj = (new Projectile(7, 0)); count = 0; } else if (gpState.IsButtonDown(down)) { proj = (new Projectile(7, 1)); count = 0; } else if (gpState.IsButtonDown(left)) { proj = (new Projectile(7, 2)); count = 0; } else if (gpState.IsButtonDown(up)) { proj = (new Projectile(7, 3)); count = 0; } else { proj = (new Projectile(7, rng.Next(0, 4))); count = 0; } //if(projList.Count >= 2) //{ // projList.RemoveAt(0); //} proj.HitBox = new Rectangle(player1.HitBox.X + player1.HitBox.Width / 4, player1.HitBox.Y + player1.HitBox.Height / 4, player1.HitBox.Width / 2, player1.HitBox.Height / 2); projList.Add(proj); } count++; } } for (int i = 0; i < projList.Count(); i++) { Projectile temp = projList[i]; if (temp.Active && temp.HitBox.Intersects(player2.HitBox)) { projList[i].Active = false; player2.Health -= damage; projList.RemoveAt(i); } } prevGpState = gpState; prevKbState = kbState; }
/// <summary> /// ボタンが押された瞬間か? /// (新しく用意しました。) /// </summary> /// <param name="button">チェックしたいボタン</param> /// <returns>現在フレームは押していて、1フレーム前は押されていないか</returns> public static bool IsButtonDown(Buttons button) { return(currentButton.IsButtonDown(button) && !previousButton.IsButtonDown(button)); }
private void updateSelection(GamePadState pad, KeyboardState keys, int player) { if (currentPlayer != player) { keys = new KeyboardState(); } //Start button functions if ((pad.IsButtonDown(Buttons.Start) || keys.IsKeyDown(Keys.Enter)) && !startButtons[player]) { if (showLoadScreen) { startMatch(); } //Player X has entered the game! else if (!this.connected[player]) { this.connected[player] = true; charThumbs[0].hover(player); selected[player] = 0; } else { //Is everybody readied up? Then we can gooooo! bool readyToGo = true; int connectedPlayers = 0; for (int i = 0; i < 4; i++) { if (connected[i]) { connectedPlayers++; } if ((!locked[i] && connected[i])) { readyToGo = false; } } if (readyToGo && connectedPlayers > 0) { showLoadScreen = true; } //Character X selected if (!charThumbs[selected[player]].isSelected()) { locked[player] = true; charThumbs[selected[player]].select(player); } } startButtons[player] = true; } else if (pad.IsButtonUp(Buttons.Start) && keys.IsKeyUp(Keys.Enter)) { startButtons[player] = false; } if (!connected[player]) { return; } //B button functions if ((pad.IsButtonDown(Buttons.B) || keys.IsKeyDown(Keys.Back)) && !back[player]) { //Unlock character selection if (locked[player]) { locked[player] = false; charThumbs[selected[player]].unselect(player); } //Disconnect player else if (connected[player]) { connected[player] = false; charThumbs[selected[player]].unhover(player); } back[player] = true; } else if (pad.IsButtonUp(Buttons.B) && keys.IsKeyUp(Keys.Back)) { back[player] = false; } if (locked[player]) { //control player } else { //Right button functions if ((pad.IsButtonDown(Buttons.LeftThumbstickRight) || pad.IsButtonDown(Buttons.DPadRight) || keys.IsKeyDown(Keys.Right)) && !right[player]) { charThumbs[selected[player]].unhover(player); selected[player]++; if (selected[player] % THUMBROWSIZE == 0) { selected[player] -= THUMBROWSIZE; } charThumbs[selected[player]].hover(player); right[player] = true; } else if (pad.IsButtonUp(Buttons.LeftThumbstickRight) && pad.IsButtonUp(Buttons.DPadRight) && keys.IsKeyUp(Keys.Right)) { right[player] = false; } //Left button functions if ((pad.IsButtonDown(Buttons.LeftThumbstickLeft) || pad.IsButtonDown(Buttons.DPadLeft) || keys.IsKeyDown(Keys.Left)) && !left[player]) { charThumbs[selected[player]].unhover(player); selected[player]--; if (selected[player] % THUMBROWSIZE == 1 || selected[player] < 0) { selected[player] += THUMBROWSIZE; } charThumbs[selected[player]].hover(player); left[player] = true; } else if (pad.IsButtonUp(Buttons.LeftThumbstickLeft) && pad.IsButtonUp(Buttons.DPadLeft) && keys.IsKeyUp(Keys.Left)) { left[player] = false; } //Up button functions if ((pad.IsButtonDown(Buttons.LeftThumbstickUp) || pad.IsButtonDown(Buttons.DPadUp) || keys.IsKeyDown(Keys.Up)) && !up[player]) { charThumbs[selected[player]].unhover(player); selected[player] -= THUMBROWSIZE; if (selected[player] < 0) { selected[player] += charNames.Count;//(int)Math.Ceiling((double)(charNames.Count/THUMBROWSIZE)); if (selected[player] > charNames.Count) { selected[player] = charNames.Count - 1; } } charThumbs[selected[player]].hover(player); up[player] = true; } else if (pad.IsButtonUp(Buttons.LeftThumbstickUp) && pad.IsButtonUp(Buttons.DPadUp) && keys.IsKeyUp(Keys.Up)) { up[player] = false; } //Down button functions if ((pad.IsButtonDown(Buttons.LeftThumbstickDown) || pad.IsButtonDown(Buttons.DPadDown) || keys.IsKeyDown(Keys.Down)) && !down[player]) { charThumbs[selected[player]].unhover(player); selected[player] += THUMBROWSIZE; if (selected[player] >= charNames.Count) { selected[player] %= charNames.Count; } charThumbs[selected[player]].hover(player); down[player] = true; } else if (pad.IsButtonUp(Buttons.LeftThumbstickDown) && pad.IsButtonUp(Buttons.DPadDown) && keys.IsKeyUp(Keys.Down)) { down[player] = false; } } /*else * { * //INSERT PLAY GAME CONTROLS HERE * }*/ }
protected void GamepadInput() { for (PlayerIndex index = PlayerIndex.One; index <= PlayerIndex.Four; index++) { if (GamePad.GetCapabilities(index).IsConnected) { GamePadState state = GamePad.GetState(index); if (((state.ThumbSticks.Left.Y < 0f && previousState[(int)index].ThumbSticks.Left.Y == 0) || (state.IsButtonDown(Buttons.DPadDown) && previousState[(int)index].IsButtonUp(Buttons.DPadDown))) && stage < numButtons - 1) { Input(InputType.Down, (InputController)index); } if (((state.ThumbSticks.Left.Y > 0f && previousState[(int)index].ThumbSticks.Left.Y == 0) || (state.IsButtonDown(Buttons.DPadUp) && previousState[(int)index].IsButtonUp(Buttons.DPadUp))) && stage > 0) { Input(InputType.Up, (InputController)index); } if (state.IsButtonUp(Buttons.A) && previousState[(int)index].IsButtonDown(Buttons.A)) { Input(InputType.Confirm, (InputController)index); } if (state.IsButtonUp(Buttons.B) && previousState[(int)index].IsButtonDown(Buttons.B)) { Input(InputType.Back, (InputController)index); } if ((state.ThumbSticks.Left.X > 0.2f && previousState[(int)index].ThumbSticks.Left.X < 0.2f) || (state.IsButtonDown(Buttons.DPadRight) && previousState[(int)index].IsButtonUp(Buttons.DPadRight))) { Input(InputType.Left, (InputController)index); } if ((state.ThumbSticks.Left.X < -0.2f && previousState[(int)index].ThumbSticks.Left.X > -0.2f) || (state.IsButtonDown(Buttons.DPadLeft) && previousState[(int)index].IsButtonUp(Buttons.DPadLeft))) { Input(InputType.Right, (InputController)index); } previousState[(int)index] = state; } } }
//* -----------------------------------------------------------------------* /// <summary>入力状態を更新します。</summary> private void stateReflesh() { if (bState.Length < BUTTON_STATE.Length) { Array.Resize <bool>(ref bState, BUTTON_STATE.Length); } #if WINDOWS KeyboardState stateKey = Keyboard.GetState(); for (int i = 0; i < bState.Length; i++) { bState[i] = stateKey.IsKeyDown(assignKeyboard[i]); } if (legacy != null) { Microsoft.DirectX.DirectInput.JoystickState legacystate = legacy.state; byte[] buttons = legacystate.GetButtons(); bState[(int)EDirection.up] = bState[(int)EDirection.up] || (legacystate.Y < -600); bState[(int)EDirection.down] = bState[(int)EDirection.down] || (legacystate.Y > 600); bState[(int)EDirection.left] = bState[(int)EDirection.left] || (legacystate.X < -600); bState[(int)EDirection.right] = bState[(int)EDirection.right] || (legacystate.X > 600); for (int i = (int)EDirection.__reserved; i < bState.Length; i++) { int nButtonID = assignLegacy[i - (int)EDirection.__reserved]; bState[i] = bState[i] || (buttons.Length > nButtonID && buttons[nButtonID] != 0); } } #else for (int i = 0; i < bState.Length; bState[i++] = false) { ; } #endif if (isUseXBOX360GamePad) { GamePadState stateButton = GamePad.GetState(PlayerIndex.One); Vector2 leftStick = stateButton.ThumbSticks.Left; if (leftStick.Length() > 0.7f) { double dAngle = Math.Atan2(leftStick.Y, leftStick.X); bState[(int)EDirection.up] = bState[(int)EDirection.up] || (dAngle <= MathHelper.PiOver4 * 3.5 && dAngle >= MathHelper.PiOver4 * 0.5); bState[(int)EDirection.down] = bState[(int)EDirection.down] || (dAngle >= MathHelper.PiOver4 * -3.5 && dAngle <= MathHelper.PiOver4 * -0.5); bState[(int)EDirection.left] = bState[(int)EDirection.left] || Math.Abs(dAngle) >= MathHelper.PiOver4 * 2.5; bState[(int)EDirection.right] = bState[(int)EDirection.right] || Math.Abs(dAngle) <= MathHelper.PiOver4 * 1.5; } else { bState[(int)EDirection.up] = bState[(int)EDirection.up] || stateButton.IsButtonDown(Buttons.DPadUp); bState[(int)EDirection.down] = bState[(int)EDirection.down] || stateButton.IsButtonDown(Buttons.DPadDown); bState[(int)EDirection.left] = bState[(int)EDirection.left] || stateButton.IsButtonDown(Buttons.DPadLeft); bState[(int)EDirection.right] = bState[(int)EDirection.right] || stateButton.IsButtonDown(Buttons.DPadRight); } for (int i = (int)EDirection.__reserved; i < bState.Length; i++) { bState[i] = bState[i] || stateButton.IsButtonDown(assignXBOX360[i - (int)EDirection.__reserved]); } } for (int i = 0; i < bState.Length; i++) { BUTTON_STATE[i].refresh(bState[i]); } }
public void UpdatePlayer(GameTime theTime, List <SoundEffect> sounds) { Timer = theTime; GetStates(); if (Position.X < (0 - Image.Width)) { SetPositionX(Graphics.PreferredBackBufferWidth + Image.Width); // thePosition.X = Graphics.PreferredBackBufferWidth + image.Width; //thePosition = new Vector2(X,Y); } if (Position.X > (Graphics.PreferredBackBufferWidth + Image.Width)) { SetPositionX(0 - Image.Width); } if (Position.Y < (0 - Image.Height)) { SetPositionY(Graphics.PreferredBackBufferHeight + Image.Height); } if (Position.Y > Graphics.PreferredBackBufferHeight + Image.Height) { SetPositionY(0 - Image.Height); } spriteRec = new Rectangle((int)Position.X, (int)Position.Y, Image.Width, Image.Height); SetPosition(Velocity + Position); imageCenter = new Vector2(spriteRec.Width / 2, spriteRec.Height / 2); // TODO: Add your update logic here if (keyState.IsKeyDown(Keys.Right) || player1State.ThumbSticks.Left.X > 0) { // X += 2; Angle += AngleIncrement; AngularVelocity += AngularVelocityIncrement; } if (keyState.IsKeyDown(Keys.Left) || player1State.ThumbSticks.Left.X < 0) { //X -= 2; Angle -= AngleIncrement; AngularVelocity -= AngularVelocityIncrement; } if (keyState.IsKeyDown(Keys.Up) || player1State.Triggers.Left > 0) { Speed += SpeedIncrement; // if(Degree >= 255 && Degree <=285) fire.CreateFire(Position.X, Position.Y + 40, INTENSITY, keyState, player1State); fireTime -= Timer.ElapsedGameTime.Milliseconds; if (fireTime < 0) { sounds[(int)Game1.Sounds.Thrust].Play(); fireTime = FIREINTERVAL; } oldx = Position.X; oldy = Position.Y; } if (keyState.IsKeyDown(Keys.T) && oldState.IsKeyUp(Keys.T) || player1State.Buttons.X > 0 ) { SetPosition(new Vector2(Graphics.PreferredBackBufferWidth / 2, graphics.PreferredBackBufferHeight / 2)); Velocity = new Vector2(0f, 0f); } else if (float.IsNaN(Position.X) || float.IsNaN(Position.Y) || float.IsNaN(Velocity.X) || float.IsNaN(Velocity.Y)) { SetPosition(new Vector2(Graphics.PreferredBackBufferWidth / 2, graphics.PreferredBackBufferHeight / 2)); Velocity = new Vector2(0f, 0f); } if (keyState.IsKeyDown(Keys.Down) || player1State.IsButtonDown(Buttons.DPadDown) && oldPadStatePlayer.IsButtonUp(Buttons.DPadDown)) { Speed -= SpeedIncrement; //if (!(Position.X == oldx && Position.Y == oldy)) //{ fire.CreateFire(Position.X, Position.Y, INTENSITY, keyState, player1State); //} //oldx = Position.X; //oldy = Position.Y; } if (keyState.IsKeyDown(Keys.Space) || player1State.Triggers.Right > 0) { time -= Timer.ElapsedGameTime.Milliseconds; if (time < 0) { weapon.FireWeapon(); time = FIREWEAPONINTERVAL; sounds[(int)Game1.Sounds.Weapon].Play(); } } oldState = keyState; Angle += AngularVelocity; AngularVelocity *= AngularVelocityDecrement; if (Angle > fullRotation) { angle -= fullRotation; } if (Angle < 0) { Angle += fullRotation; } SetVelocityX(Velocity.X + (float)Math.Cos(Angle) * Speed); SetVelocityY(Velocity.Y + (float)Math.Sin(Angle) * Speed); SetVelocityX(Velocity.X * VelocityDecrement); SetVelocityY(Velocity.Y * VelocityDecrement); SetPositionX(Position.X + Velocity.X); SetPositionY(Position.Y + Velocity.Y); Speed *= SpeedDecrement; //player vs asteroid collision foreach (Asteroid i in AccessAsteroids) { timeSinceLastCollision2 -= Timer.ElapsedGameTime.Milliseconds; if (Collided(Position.X, Position.Y, i, i.Image)) { ChosenColor = Color.Red; timeSinceLastCollision -= Timer.ElapsedGameTime.Milliseconds; if (timeSinceLastCollision < 0) { sounds[(int)Game1.Sounds.AsteroidHit].Play(); SetVelocityX((i.Velocity.X / i.Velocity.X) * (i.Velocity.X - Velocity.X) / 2); SetVelocityY((i.Velocity.Y / i.Velocity.Y) * (i.Velocity.Y - Velocity.X) / 2); float currentAngularVelocity = AngularVelocity; AngularVelocity += ((i.AngularVelocity / 3.5f) - currentAngularVelocity); HealthPoints -= HEALTHPOINTDEDUCTION; timeSinceLastCollision = MAXCOLLISIONINTERVAL; } Hit = true; timeSinceLastCollision2 = MAXCOLLISIONINTERVAL; } if (timeSinceLastCollision2 < 0) { Hit = false; } if (Hit) { timeSinceLastFlash -= Timer.ElapsedGameTime.Milliseconds; if (timeSinceLastFlash < 0 && TheColor != ChosenColor) { TheColor = ChosenColor; timeSinceLastFlash = FLASH; } else if (timeSinceLastFlash < 0 && TheColor != Color.White) { TheColor = Color.White; timeSinceLastFlash = FLASH; } } else { TheColor = Color.White; } } //Enemy Weapon vs player foreach (EnemyWeapon e in AccesEnemyWeapon.AccessWeapons) { timeSinceLastCollision2 -= Timer.ElapsedGameTime.Milliseconds; if (Collided(Position.X, Position.Y, e, Image)) { ChosenColor = Color.Blue; timeSinceLastCollision -= Timer.ElapsedGameTime.Milliseconds; if (timeSinceLastCollision < 0) { sounds[(int)Game1.Sounds.EnemyWeaponHit].Play(); SetVelocityX((e.Velocity.X / e.Velocity.X) * (e.Velocity.X - Velocity.X) / 2); SetVelocityY((e.Velocity.Y / e.Velocity.Y) * (e.Velocity.Y - Velocity.X) / 2); float currentAngularVelocity = AngularVelocity; AngularVelocity += ((e.AngularVelocity / 3.5f) - currentAngularVelocity); HealthPoints -= HEALTHPOINTDEDUCTION; timeSinceLastCollision = MAXCOLLISIONINTERVAL; } Hit = true; timeSinceLastCollision2 = MAXCOLLISIONINTERVAL; } if (timeSinceLastCollision2 < 0) { Hit = false; } if (Hit) { timeSinceLastFlash -= Timer.ElapsedGameTime.Milliseconds; if (timeSinceLastFlash < 0 && TheColor != ChosenColor) { TheColor = ChosenColor; timeSinceLastFlash = FLASH; } else if (timeSinceLastFlash < 0 && TheColor != Color.White) { TheColor = Color.White; timeSinceLastFlash = FLASH; } } else { TheColor = Color.White; } } // Enemy Vs Player Collision foreach (Enemy e in AccessEnemy.AccessEnemyList) { timeSinceLastCollision2 -= Timer.ElapsedGameTime.Milliseconds; if (Collided(Position.X, Position.Y, e, Image)) { ChosenColor = Color.Purple; timeSinceLastCollision -= Timer.ElapsedGameTime.Milliseconds; if (timeSinceLastCollision < 0) { sounds[(int)Game1.Sounds.EnemyHit].Play(); SetVelocityX((e.Velocity.X / e.Velocity.X) * (e.Velocity.X - Velocity.X) / 2); SetVelocityY((e.Velocity.Y / e.Velocity.Y) * (e.Velocity.Y - Velocity.X) / 2); CurrentAngularVelocity = AngularVelocity; AngularVelocity += ((e.AngularVelocity / 2f) - currentAngularVelocity); HealthPoints -= HEALTHPOINTDEDUCTION; timeSinceLastCollision = MAXCOLLISIONINTERVAL; } Hit = true; timeSinceLastCollision2 = MAXCOLLISIONINTERVAL; } if (timeSinceLastCollision2 < 0) { Hit = false; } if (Hit) { timeSinceLastFlash -= Timer.ElapsedGameTime.Milliseconds; if (timeSinceLastFlash < 0 && TheColor != ChosenColor) { TheColor = ChosenColor; timeSinceLastFlash = FLASH; } else if (timeSinceLastFlash < 0 && TheColor != Color.White) { TheColor = Color.White; timeSinceLastFlash = FLASH; } } else { TheColor = Color.White; } } }
//Updates all powerups. public void Update(double elapsedTime) { KeyboardState input = Keyboard.GetState(); if (player1.XBox) { GamePadState gamePad1 = GamePad.GetState(player1.PlayerNumber); if (gamePad1.IsButtonDown(Buttons.X)) { powerP1.Activate(); } } if (player2.XBox) { GamePadState gamePad2 = GamePad.GetState(player2.PlayerNumber); if (gamePad2.IsButtonDown(Buttons.X)) { powerP2.Activate(); } } if (!player1.XBox) { if (input.IsKeyDown((Keys)player1.use)) { powerP1.Activate(); } } if (!player2.XBox) { if (input.IsKeyDown((Keys)player2.use)) { powerP2.Activate(); } } if (player3 != null && player3.XBox) { GamePadState gamePad3 = GamePad.GetState(player3.PlayerNumber); if (gamePad3.IsButtonDown(Buttons.X)) { powerP3.Activate(); } } if (player4 != null && player4.XBox) { GamePadState gamePad4 = GamePad.GetState(player4.PlayerNumber); if (gamePad4.IsButtonDown(Buttons.X)) { powerP4.Activate(); } } if (player3 != null && !player3.XBox) { if (input.IsKeyDown((Keys)player3.use)) { powerP3.Activate(); } } if (player4 != null && !player4.XBox) { if (input.IsKeyDown((Keys)player4.use)) { powerP4.Activate(); } } powerP1.Update(elapsedTime); powerP2.Update(elapsedTime); if (player3 != null) { powerP3.Update(elapsedTime); } if (player4 != null) { powerP4.Update(elapsedTime); } }
public override bool block() { return(c.HasRightShoulderButton && s.IsButtonDown(Buttons.LeftShoulder)); }
protected override void Update(GameTime gameTime) { padState = GamePad.GetState(PlayerIndex.One); keyState = Keyboard.GetState(); mouseState = Mouse.GetState(); // let the user escape the demo if (PressedOnce(Keys.Escape, Buttons.Back)) { this.Exit(); } // change threading mode if (PressedOnce(Keys.M, Buttons.A)) { multithread = !multithread; } if (PressedOnce(Keys.P, Buttons.A)) { var e = World.RigidBodies.GetEnumerator(); e.MoveNext(); e.MoveNext(); World.RemoveBody(e.Current as RigidBody); } #region drag and drop physical objects with the mouse if (mouseState.LeftButton == ButtonState.Pressed && mousePreviousState.LeftButton == ButtonState.Released || padState.IsButtonDown(Buttons.RightThumbstickDown) && gamePadPreviousState.IsButtonUp(Buttons.RightThumbstickUp)) { JVector ray = Conversion.ToJitterVector(RayTo(mouseState.X, mouseState.Y)); JVector camp = Conversion.ToJitterVector(Camera.Position); ray = JVector.Normalize(ray) * 100; float fraction; bool result = World.CollisionSystem.Raycast(camp, ray, RaycastCallback, out grabBody, out hitNormal, out fraction); if (result) { hitPoint = camp + fraction * ray; if (grabConstraint != null) { World.RemoveConstraint(grabConstraint); } JVector lanchor = hitPoint - grabBody.Position; lanchor = JVector.Transform(lanchor, JMatrix.Transpose(grabBody.Orientation)); grabConstraint = new SingleBodyConstraints.PointOnPoint(grabBody, lanchor); grabConstraint.Softness = 0.01f; grabConstraint.BiasFactor = 0.1f; World.AddConstraint(grabConstraint); hitDistance = (Conversion.ToXNAVector(hitPoint) - Camera.Position).Length(); scrollWheel = mouseState.ScrollWheelValue; grabConstraint.Anchor = hitPoint; } } if (mouseState.LeftButton == ButtonState.Pressed || padState.IsButtonDown(Buttons.RightThumbstickDown)) { hitDistance += (mouseState.ScrollWheelValue - scrollWheel) * 0.01f; scrollWheel = mouseState.ScrollWheelValue; if (grabBody != null) { Vector3 ray = RayTo(mouseState.X, mouseState.Y); ray.Normalize(); grabConstraint.Anchor = Conversion.ToJitterVector(Camera.Position + ray * hitDistance); grabBody.IsActive = true; if (!grabBody.IsStatic) { grabBody.LinearVelocity *= 0.98f; grabBody.AngularVelocity *= 0.98f; } } } else { if (grabConstraint != null) { World.RemoveConstraint(grabConstraint); } grabBody = null; grabConstraint = null; } #endregion #region create random primitives if (PressedOnce(Keys.Space, Buttons.B)) { SpawnRandomPrimitive(Conversion.ToJitterVector(Camera.Position), Conversion.ToJitterVector((Camera.Target - Camera.Position) * 40.0f)); } #endregion #region switch through physic scenes if (PressedOnce(Keys.Add, Buttons.X)) { DestroyCurrentScene(); currentScene++; currentScene = currentScene % PhysicScenes.Count; PhysicScenes[currentScene].Build(); } if (PressedOnce(Keys.Subtract, Buttons.Y)) { DestroyCurrentScene(); currentScene += PhysicScenes.Count - 1; currentScene = currentScene % PhysicScenes.Count; PhysicScenes[currentScene].Build(); } #endregion UpdateDisplayText(gameTime); float step = (float)gameTime.ElapsedGameTime.TotalSeconds; if (step > 1.0f / 100.0f) { step = 1.0f / 100.0f; } World.Step(step, multithread); gamePadPreviousState = padState; keyboardPreviousState = keyState; mousePreviousState = mouseState; base.Update(gameTime); }
public void StaticStateChange(String collisionDirection, IStaticObject staticObject) { if (staticObject.ToString() == "SuperMario.Flagpole" && !finishedCollidingWithFlagPole) { if (playableObject.PlayableObjectState.ToString() != "SuperMario.MarioStates.SmallMarioFlagSlide" && playableObject.PlayableObjectState.ToString() != "SuperMario.MarioStates.BigMarioFlagSlide" && playableObject.PlayableObjectState.ToString() != "SuperMario.MarioStates.FireMarioFlagSlide") { playableObject.Velocity = Vector2.Zero; playableObject.Acceleration = Vector2.Zero; playableObject.MaxVelocity = new Vector2(playableObject.MaxVelocity.X, GameValues.MarioStateMachineFlagpoleMarioYVelocity); SoundManager.Instance.OverWorldInstance.Stop(); SoundManager.Instance.PlayFlagSlideSound(); } if (playableObject.Acceleration.Y < Vector2.Zero.Y) { playableObject.Acceleration = Vector2.Zero; } new MarioCollidesWithFlagPoleCommand(playableObject).Execute(); Level.Instance.Flagpoles[0].SetScoreValue(playableObject.Position.Y); playableObject.Position = new Vector2(staticObject.CollisionRectangle.Left - playableObject.CollisionRectangle.Width + GameValues.MarioStateMachineFlagPoleCollisionRectangleWidthOffset, playableObject.Position.Y); staticObject.CollisionRectangle = GameValues.EmptyCollisionRectangle; playableObject.CollisionRectangle = new Rectangle((int)playableObject.Position.X, (int)playableObject.Position.Y, playableObject.CollisionRectangle.Width, playableObject.CollisionRectangle.Height); } else { if (collisionDirection == GameValues.CollisionDirectionTop) { } else if (collisionDirection == GameValues.CollisionDirectionBottom) { new MarioCollidesWithGroundCommand(playableObject).Execute(); if (!playableObject.IsEnteringPipe && !playableObject.IsExitingPipe) { playableObject.Position = new Vector2(playableObject.Position.X, staticObject.CollisionRectangle.Top - playableObject.CollisionRectangle.Height); playableObject.CollisionRectangle = new Rectangle((int)playableObject.Position.X, (int)playableObject.Position.Y, playableObject.CollisionRectangle.Width, playableObject.CollisionRectangle.Height); } KeyboardState keyboardState = Keyboard.GetState(); GamePadState gamePadState = GamePad.GetState(PlayerIndex.One); if ((keyboardState.IsKeyDown(Keys.Down) || gamePadState.IsButtonDown(Buttons.LeftThumbstickDown) || gamePadState.IsButtonDown(Buttons.DPadDown)) && staticObject.ToString() == "SuperMario.Pipe" && playableObject.CollisionRectangle.Left > staticObject.CollisionRectangle.Left && playableObject.CollisionRectangle.Right < staticObject.CollisionRectangle.Right) { Pipe pipe = staticObject as Pipe; if (pipe.IsWarpPipe && !playableObject.IsEnteringPipe) { playableObject.IsEnteringPipe = true; SoundManager.Instance.PlayPowerDownSound(); } } } else if (collisionDirection == GameValues.CollisionDirectionRight) { Vector2 pipeExitPosition = Vector2.Zero; if (staticObject.ToString() == "SuperMario.Pipe") { Pipe pipe = staticObject as Pipe; if (pipe.IsHorizontalPipe) { playableObject.IsEnteringPipe = true; //command for pipe animation SoundManager.Instance.PlayPowerDownSound(); playableObject.InCoinRoom = false; foreach (Pipe pipeTemp in Level.Instance.Pipes) { if (pipeTemp.Position.X > pipeExitPosition.X && pipeTemp.Position.X != pipe.Position.X && pipeTemp.Position.X < pipe.Position.X) { pipeExitPosition = new Vector2(pipeTemp.Position.X, pipeTemp.Position.Y); } } } } if (pipeExitPosition.X != Vector2.Zero.X && pipeExitPosition.Y != Vector2.Zero.Y) { playableObject.IsExitingPipe = true; playableObject.Position = new Vector2(pipeExitPosition.X, pipeExitPosition.Y); } else { playableObject.Position = new Vector2(staticObject.CollisionRectangle.Left - playableObject.CollisionRectangle.Width + GameValues.MarioStateMachineCollisionRectangleWidthOffset, playableObject.Position.Y); } playableObject.CollisionRectangle = new Rectangle((int)playableObject.Position.X, (int)playableObject.Position.Y, playableObject.CollisionRectangle.Width, playableObject.CollisionRectangle.Height); if (playableObject.Velocity.X > Vector2.Zero.X) { playableObject.Velocity = new Vector2(GameValues.MarioStateMachineCollisionNewXVelocity, playableObject.Velocity.Y); } } else if (collisionDirection == GameValues.CollisionDirectionLeft) { playableObject.Position = new Vector2(staticObject.CollisionRectangle.Right, playableObject.Position.Y); playableObject.CollisionRectangle = new Rectangle((int)playableObject.Position.X, (int)playableObject.Position.Y, playableObject.CollisionRectangle.Width, playableObject.CollisionRectangle.Height); if (playableObject.Velocity.X < Vector2.Zero.X) { playableObject.Velocity = new Vector2(-GameValues.MarioStateMachineCollisionNewXVelocity, playableObject.Velocity.Y); } } if (playableObject.IsEnteringPipe && !playableObject.IsExitingPipe) { if (PipeBuffer >= GameValues.MarioStateMachinePipeBufferMin) { PipeBuffer = GameValues.MarioStateMachinePipeBuffer; playableObject.IsEnteringPipe = false; playableObject.MaxVelocity = new Vector2(playableObject.MaxVelocity.X, GameValues.PhysicsMaxYVelocity); playableObject.Position = new Vector2(Level.Instance.CoinRoomPosition.X + GameValues.LevelCellSize, (Level.Instance.CoinRoomPosition.Y / GameValues.LevelCellSize) + GameValues.MarioStateMachineEnteringPipeYPositionOffset); playableObject.InCoinRoom = true; } else { PipeBuffer++; //playableObject.Position = new Vector2(playableObject.Position.X, playableObject.Position.Y + 0.1f); playableObject.MaxVelocity = new Vector2(playableObject.MaxVelocity.X, GameValues.MarioStateMachineCollisionNewXVelocity); playableObject.Acceleration = Vector2.Zero; } } else if (playableObject.IsExitingPipe) { if (staticObject.ToString() == "SuperMario.Pipe") { if (playableObject.Position.Y <= staticObject.Position.Y - playableObject.CollisionRectangle.Height + GameValues.MarioStateMachineExitingPipeCollisionRectangleHeightOffset) { playableObject.IsEnteringPipe = false; playableObject.IsExitingPipe = false; playableObject.Position = new Vector2(playableObject.Position.X, staticObject.Position.Y - playableObject.CollisionRectangle.Height); } else { playableObject.Velocity = new Vector2(playableObject.Velocity.X, GameValues.MarioStateMachineExitingPipeNewYVelocity); } } } } }
public Buttons?Update(GamePadState gamepadstate, int playerNum) //returns button if button that was just pressed { Buttons?returnVal = null; setKeys(playerNum); KeyboardState kbstate = Keyboard.GetState(); newStart = gamepadstate.IsButtonDown(Buttons.Start) || kbstate.IsKeyDown(start); newA = gamepadstate.IsButtonDown(Buttons.A) || kbstate.IsKeyDown(a); newB = gamepadstate.IsButtonDown(Buttons.B) || kbstate.IsKeyDown(b); newX = gamepadstate.IsButtonDown(Buttons.X) || kbstate.IsKeyDown(x); newY = gamepadstate.IsButtonDown(Buttons.Y) || kbstate.IsKeyDown(y); newLeft = gamepadstate.IsButtonDown(Buttons.DPadLeft) || kbstate.IsKeyDown(left); newRight = gamepadstate.IsButtonDown(Buttons.DPadRight) || kbstate.IsKeyDown(right); newDown = gamepadstate.IsButtonDown(Buttons.DPadDown) || kbstate.IsKeyDown(down); newUp = gamepadstate.IsButtonDown(Buttons.DPadUp) || kbstate.IsKeyDown(Up); //return buttons so combos can equal true if (newA == true && oldA == false) { returnVal = Buttons.A; } else if (newStart == true && oldStart == false) { returnVal = Buttons.Start; } else if (newB == true && oldB == false) { returnVal = Buttons.B; } else if (newX == true && oldX == false) { returnVal = Buttons.X; } else if (newY == true && oldY == false) { returnVal = Buttons.Y; } else if (newLeft == true && oldLeft == false) { returnVal = Buttons.DPadLeft; } else if (newRight == true && oldRight == false) { returnVal = Buttons.DPadRight; } else if (newDown == true && oldDown == false) { returnVal = Buttons.DPadDown; } else if (newUp == true && oldUp == false) { returnVal = Buttons.DPadUp; } oldA = newA; oldB = newB; oldX = newX; oldRight = newRight; oldLeft = newLeft; oldY = newY; oldDown = newDown; oldUp = newUp; oldStart = newStart; return(returnVal); }
//* -----------------------------------------------------------------------* /// <summary>入力状態更新のスレッドです。</summary> /// /// <returns>スレッドが実行される間、<c>true</c></returns> private IEnumerator <object> threadStateReflesh() { while (true) { yield return(null); bool[] bState = new bool[BUTTON_STATE.Length]; #if WINDOWS Microsoft.Xna.Framework.Input.KeyboardState stateKey = Microsoft.Xna.Framework.Input.Keyboard.GetState(); for (int i = 0; i < bState.Length; i++) { bState[i] = stateKey.IsKeyDown(assignKeyboard[i]); } if (legacy != null) { Microsoft.DirectX.DirectInput.JoystickState legacystate = legacy.state; byte[] buttons = legacystate.GetButtons(); bState[( int )EDirType.Up] = bState[( int )EDirType.Up] || (legacystate.Y < -600); bState[( int )EDirType.Down] = bState[( int )EDirType.Down] || (legacystate.Y > 600); bState[( int )EDirType.Left] = bState[( int )EDirType.Left] || (legacystate.X < -600); bState[( int )EDirType.Right] = bState[( int )EDirType.Right] || (legacystate.X > 600); for (int i = ( int )EDirType.__reserved; i < bState.Length; i++) { int nButtonID = assignLegacy[i - ( int )EDirType.__reserved]; bState[i] = bState[i] || (buttons.Length > nButtonID && buttons[nButtonID] != 0); } } #else for (int i = 0; i < bState.Length; bState[i++] = false) { ; } #endif if (isUseXBOX360GamePad) { GamePadState stateButton = GamePad.GetState(PlayerIndex.One); Vector2 leftStick = stateButton.ThumbSticks.Left; if (leftStick.Length() > 0.7f) { double dAngle = Math.Atan2(leftStick.Y, leftStick.X); bState[( int )EDirType.Up] = bState[( int )EDirType.Up] || (dAngle <= MathHelper.PiOver4 * 3.5 && dAngle >= MathHelper.PiOver4 * 0.5); bState[( int )EDirType.Down] = bState[( int )EDirType.Down] || (dAngle >= MathHelper.PiOver4 * -3.5 && dAngle <= MathHelper.PiOver4 * -0.5); bState[( int )EDirType.Left] = bState[( int )EDirType.Left] || Math.Abs(dAngle) >= MathHelper.PiOver4 * 2.5; bState[( int )EDirType.Right] = bState[( int )EDirType.Right] || Math.Abs(dAngle) <= MathHelper.PiOver4 * 1.5; } else { bState[( int )EDirType.Up] = bState[( int )EDirType.Up] || stateButton.IsButtonDown(Buttons.DPadUp); bState[( int )EDirType.Down] = bState[( int )EDirType.Down] || stateButton.IsButtonDown(Buttons.DPadDown); bState[( int )EDirType.Left] = bState[( int )EDirType.Left] || stateButton.IsButtonDown(Buttons.DPadLeft); bState[( int )EDirType.Right] = bState[( int )EDirType.Right] || stateButton.IsButtonDown(Buttons.DPadRight); } for (int i = ( int )EDirType.__reserved; i < bState.Length; i++) { bState[i] = bState[i] || stateButton.IsButtonDown(assignXBOX360[i - ( int )EDirType.__reserved]); } } for (int i = 0; i < bState.Length; i++) { BUTTON_STATE[i].refresh(bState[i]); } } }
public Boolean JoyHold(Buttons button) { return(currGamePadState.IsButtonDown(button) && prevGamePadState.IsButtonUp(button)); }
public static bool WasButtonPressed(Buttons button) { return(lastGamepadState.IsButtonUp(button) && gamepadState.IsButtonDown(button)); }
public bool IsButtonDown(Buttons button) { return(state.IsButtonDown(button)); }
public bool WasPressed(Buttons button) { return(_gamePadState.IsButtonDown(button) && !_lastGamePadState.IsButtonDown(button)); }
/// <summary> /// Check if Controller Button is being pressed right now /// </summary> /// <param name="b"></param> /// <returns>Pressed button</returns> public bool IsControlerButtonDown(Buttons b) { return(currentControlerState.IsButtonDown(b)); }