Exemple #1
0
    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);
    }
Exemple #2
0
    //HandleInput methode voor de TetrisGrid.
    /// <summary>
    /// Handles the player input.
    /// </summary>
    /// <param name="gameTime">An object with information about the time that has passed in the game.</param>
    /// <param name="spriteBatch">The SpriteBatch used for drawing sprites and text.</param>
    /// <param name="LeftMove">When this key is pressed the currently active block is (if possable) moved 1 block to the left in the grid.</param>
    /// <param name="RightMove">When this key is pressed the currently active block is (if possable) moved 1 block to the right in the grid.</param>
    /// <param name="RotateCW">When this key is pressed the currently active block is (if possable) rotated 90 degrees Clockwise.</param>
    /// <param name="RotateCCW">When this key is pressed the currently active block is (if possable) rotated 90 degrees CounterClockwise.</param>
    /// <param name="GoDown">While this key is pressed the currently active block will move down through the grid at an accelerated speed.</param>
    public void HandleInput(GameTime gameTime, InputHelper inputHelper, Keys LeftMove, Keys RightMove, Keys RotateCW, Keys RotateCCW, Keys SlamDown, Keys GoDown)
    {
        //This part makes sure that the player can move the block to the left and right.
        if (inputHelper.KeyDown(RightMove) && gameTime.TotalGameTime.Ticks % 6 == 0) //Makes sure the movement is not to fast
        {
            Block.MoveRight();
        }
        else if (inputHelper.KeyDown(LeftMove) && gameTime.TotalGameTime.Ticks % 6 == 0)
        {
            Block.MoveLeft();
        }

        //The next part is about rotating the blocks.
        if (inputHelper.KeyPressed(RotateCCW))
        {
            TetrisBlock.RotateCounterClockwiseLegit(Block);
        }
        else if (inputHelper.KeyPressed(RotateCW))
        {
            TetrisBlock.RotateClockwiseLegit(Block);
        }

        //The following part allows the player to move the block down faster.
        if (inputHelper.KeyDown(GoDown) && gameTime.TotalGameTime.Ticks % 6 == 0)
        {
            Block.MoveDown();
            ForceBlockDownwards = true;
        }
        else
        {
            ForceBlockDownwards = false;
        }

        if (inputHelper.KeyPressed(SlamDown))
        {
            Block.SlamDown();
        }
    }
Exemple #3
0
    /// <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;
        }
    }
Exemple #4
0
 public void MoveLeft()
 {
     currentBlock.MoveLeft();
 }