void PerformPlayerControlledMovement() { if (currentBlock == null) { return; } if (Input.GetButtonDown("rotateclockwise")) { currentBlock.RotateClockwise(tetrisBoard); soundEngine.PlaySoundWithName("BlockRotate"); } if (Input.GetButtonDown("rotatecounterclockwise")) { currentBlock.RotateCounterClockwise(tetrisBoard); soundEngine.PlaySoundWithName("BlockRotate"); } if (Input.GetButtonDown("left")) { currentBlock.MoveLeft(tetrisBoard); soundEngine.PlaySoundWithName("BlockMove"); } if (Input.GetButtonDown("right")) { currentBlock.MoveRight(tetrisBoard); soundEngine.PlaySoundWithName("BlockMove"); } if (Input.GetButtonDown("up")) { currentBlock.MoveDownMax(tetrisBoard); } else if (Input.GetButtonDown("down")) { PerformNextDownwardMove(); soundEngine.PlaySoundWithName("BlockMove"); } if (Input.GetButtonDown("stash")) { StashCurrentBlock(); } display.UpdateBoard(tetrisBoard, currentBlock); }
/// <summary> /// Handles all the player input. /// <param name="gameTime"></param> /// <param name="inputHelper"></param> public void HandleInput(GameTime gameTime, InputHelper inputHelper) { switch (gameState) { case GameState.Start: if (inputHelper.KeyPressed(Microsoft.Xna.Framework.Input.Keys.Space)) { GameStart(); } break; case GameState.Playing: if (inputHelper.KeyPressed(Microsoft.Xna.Framework.Input.Keys.Escape)) { OpenGameMenu(); } if (inputHelper.KeyPressed(Microsoft.Xna.Framework.Input.Keys.Left)) { activeBlock.MoveLeft(); } if (inputHelper.KeyPressed(Microsoft.Xna.Framework.Input.Keys.Right)) { activeBlock.MoveRight(); } if (inputHelper.KeyPressed(Microsoft.Xna.Framework.Input.Keys.Down)) { activeBlock.MoveDown(); } if (inputHelper.KeyPressed(Microsoft.Xna.Framework.Input.Keys.Up)) { while (activeBlock != null) { activeBlock.MoveDown(); } } if (inputHelper.KeyPressed(Microsoft.Xna.Framework.Input.Keys.A)) { activeBlock.RotateCounterclockwise(); } if (inputHelper.KeyPressed(Microsoft.Xna.Framework.Input.Keys.D)) { activeBlock.RotateClockwise(); } // Quick GameOver debug cheat if (inputHelper.KeyDown(Microsoft.Xna.Framework.Input.Keys.NumPad0)) { GameOver(); } break; case GameState.GameMenu: if (inputHelper.KeyPressed(Microsoft.Xna.Framework.Input.Keys.Escape)) { CloseGameMenu(); } if (inputHelper.KeyPressed(Microsoft.Xna.Framework.Input.Keys.Space)) { GameOver(); GameHomescreen(); } break; case GameState.GameOver: if (inputHelper.KeyPressed(Microsoft.Xna.Framework.Input.Keys.Space)) { GameStart(); } if (inputHelper.KeyPressed(Microsoft.Xna.Framework.Input.Keys.Escape)) { GameHomescreen(); } break; } }