MoveFigureRight() public method

public MoveFigureRight ( ) : void
return void
示例#1
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            KeyboardState keyboardState = Keyboard.GetState();

            if (keyboardState.IsKeyDown(Keys.Escape))
            {
                this.Exit();
            }

            // Check pause
            bool pauseKey = (oldKeyboardState.IsKeyDown(Keys.P) && (keyboardState.IsKeyUp(Keys.P)));

            oldKeyboardState = keyboardState;

            if (pauseKey)
            {
                pause = !pause;
            }

            if (!pause)
            {
                // Find dynamic figure position
                board.FindDynamicFigure();

                // Increase player score
                int lines = board.DestroyLines();
                if (lines > 0)
                {
                    score.Value += (int)((5.0f / 2.0f) * lines * (lines + 3));
                    board.Speed += 0.005f;
                }

                score.Level = (int)(10 * board.Speed);

                // Create new shape in game
                if (!board.CreateNewFigure())
                {
                    GameOver();
                }
                else
                {
                    // If left key is pressed
                    if (keyboardState.IsKeyDown(Keys.Left))
                    {
                        board.MoveFigureLeft();
                    }
                    // If right key is pressed
                    if (keyboardState.IsKeyDown(Keys.Right))
                    {
                        board.MoveFigureRight();
                    }
                    // If down key is pressed
                    if (keyboardState.IsKeyDown(Keys.Down))
                    {
                        board.MoveFigureDown();
                    }

                    // Rotate figure
                    if (keyboardState.IsKeyDown(Keys.Up) || keyboardState.IsKeyDown(Keys.Space))
                    {
                        board.RotateFigure();
                    }

                    // Moving figure
                    if (board.Movement >= 1)
                    {
                        board.Movement = 0;
                        board.MoveFigureDown();
                    }
                    else
                    {
                        board.Movement += board.Speed;
                    }
                }
            }

            base.Update(gameTime);
        }