public void HandleInput(KeyboardState state) { if (!_keyLocker.KeyPressed && state.IsKeyDown(Keys.Space) && !oldState.IsKeyDown(Keys.Space)) { // Change to JumpAction _actionStateMachine.Change("jump"); _keyLocker.LockKey(Keys.Space); } else if (state.IsKeyDown(Keys.Left) || state.IsKeyDown(Keys.Right)) // If left or right key is pressed { _actionStateMachine.Change("move"); } else if (!_keyLocker.KeyPressed && state.IsKeyDown(Keys.Z) && !oldState.IsKeyDown(Keys.Z)) { _actionStateMachine.Change("attack"); _keyLocker.LockKey(Keys.Z); } else if (oldState.IsKeyUp(Keys.X) && state.IsKeyDown(Keys.X)) { // Change to ThrowAction if actor is currently not throwing if (!_actor.isThrowing) { _actionStateMachine.Change("throw", "stand"); } } else if (state.IsKeyDown(Keys.Down)) { _actionStateMachine.Change("crouch"); } _keyLocker.CheckInputLock(state, Keys.Space); _keyLocker.CheckInputLock(state, Keys.Z); oldState = state; }
public void HandleInput(KeyboardState state) { if (state.IsKeyDown(Keys.Left)) { moveLeft(); } else if (state.IsKeyDown(Keys.Right)) { _actionStateMachine.Change("moveRight"); } else { _actionStateMachine.Change("stand"); } }
public void HandleInput(KeyboardState state) { if (state.IsKeyDown(Keys.Right) && state.IsKeyDown(Keys.Space)) { velocity.X = 3f; // add velocity, go right } else if (state.IsKeyDown(Keys.Left) && state.IsKeyDown(Keys.Space)) { velocity.X = -3f; // substract velocity, lean left } else if (oldState.IsKeyUp(Keys.X) && state.IsKeyDown(Keys.X)) { // if actor currently is throwing, cannot switch to trowAction if (!_actor.isThrowing) { _actionStateMachine.Change("throw", "jump"); } } else // if no space key pressed { if (state.IsKeyDown(Keys.Left)) // continue going left if left key is pressed { velocity.X = -3f; _actor.direction = AActor.Direction.LEFT; // Set current facing direction } else if (state.IsKeyDown(Keys.Right)) // continue going to right if right key is pressed { velocity.X = 3f; _actor.direction = AActor.Direction.RIGHT; // Set current facing direction } else // if no space or left or right key is pressed, stay at same position { velocity.X = 0; } } if (state.IsKeyUp(Keys.Space) || hasJumped == true) { float i = 1; velocity.Y += 0.15f * i; } oldState = state; }
public void Update(GameTime gameTime) { _actor.Position = position; // Update position in actor timeSinceLastFrame += gameTime.ElapsedGameTime.Milliseconds; if (timeSinceLastFrame > 200) { timeSinceLastFrame -= 200; _actionStateMachine.Change("stand"); } }
public void HandleInput(KeyboardState state) { if (state.IsKeyDown(Keys.Space)) { // Switch to JumpAction _actionStateMachine.Change("jump"); } else if (state.IsKeyDown(Keys.Down)) { // Switch to CrouchAction _actionStateMachine.Change("crouch"); } else if (oldState.IsKeyUp(Keys.X) && state.IsKeyDown(Keys.X)) { // if actor currently is throwing, cannot switch to trowAction if (!_actor.isThrowing) { // Switch to ThrowAction _actionStateMachine.Change("throw", "move"); } } else if (state.IsKeyDown(Keys.Right)) { MoveRight(); } else if (state.IsKeyDown(Keys.Left)) { MoveLeft(); } else { // Switch to StandAction _actionStateMachine.Change("stand"); } oldState = state; }
public void HandleInput(KeyboardState state) { if (state.IsKeyDown(Keys.Down) && state.IsKeyDown(Keys.Right)) { MoveRight(); } if (state.IsKeyDown(Keys.Down) && state.IsKeyDown(Keys.Left)) { MoveLeft(); } if (!state.IsKeyDown(Keys.Down)) { _actionStateMachine.Change("stand"); } }
public void HandleInput(KeyboardState state) { _actionStateMachine.Change(prevAction); oldState = state; }