Exemplo n.º 1
0
        public void CurTetraminoMovLeft()
        {
            Point Position = curTetramino.GetPosition;

            Point[] Shape = curTetramino.GetShape;
            bool    move  = true;

            CurTetraminoErase();

            foreach (Point S in Shape)
            {
                if (((int)(S.X + Position.X) + ((cols / 2) - 1) - 1) < 0)
                {
                    move = false;
                }

                else if (BlockControls[((int)(S.X + Position.X) + ((cols / 2) - 1) - 1),
                                       (int)(S.Y + Position.Y) + 1].BackgroundImage != NoImage)
                {
                    move = false;
                }
            }

            if (move)
            {
                curTetramino.MoveLeft();
                CurTetraminoDraw();
            }

            else
            {
                CurTetraminoDraw();
            }
        }
Exemplo n.º 2
0
    private void GameUpdate()
    {
        Action    moveLeft      = delegate() { tetramino.MoveLeft(); };
        Action    moveRight     = delegate() { tetramino.MoveRight(); };
        Action    rotate90      = delegate() { tetramino.Rotate(); };
        Action    rotate270     = delegate() { tetramino.Rotate(); tetramino.Rotate(); tetramino.Rotate(); };
        const int ACTIONS_COUNT = 3;

        Action[]  actions     = { moveLeft, moveRight, rotate90 };
        Action[]  backActions = { moveRight, moveLeft, rotate270 };
        KeyCode[] keyCodes    = { KeyCode.A, KeyCode.D, KeyCode.W };
        tetramino.SetActive(field, false);
        for (int i = 0; i < ACTIONS_COUNT; i++)
        {
            if (Input.GetKeyDown(keyCodes[i]))
            {
                actions[i]();
                if (!tetramino.Check(field))
                {
                    backActions[i]();
                }
            }
        }
        if ((Input.GetKey(KeyCode.S) ? INCREASED_FALL_TIME : FALL_TIME) < Time.time - previousDownTime)
        {
            tetramino.MoveDown();
            if (!tetramino.Check(field))
            {
                tetramino.MoveUp();
                tetramino.SetActive(field, true);
                CheckLineToDelete();
                NewTetramino();
                if (!tetramino.Check(field))
                {
                    GameOver();
                    return;
                }
            }
            previousDownTime = Time.time;
        }
        tetramino.SetActive(field, true);
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            gameMode = GameMode.Pause;
            pauseScreen.SetActive(true);
        }
    }
Exemplo n.º 3
0
        private void CheckRotationWithWallKick()
        {
            var  coord             = actualTetramino.GetBlocksCoordinates();
            bool pieceCollision    = false;
            int  min               = Int32.MaxValue;
            int  max               = Int32.MinValue;
            int  minCollisionPoint = Int32.MaxValue;

            for (int c = 0; c < coord.Length; c += 2)
            {
                if (coord[c + 1] < min)
                {
                    min = coord[c + 1];
                }
                if (coord[c + 1] > max)
                {
                    max = coord[c + 1];
                }

                bool collision = landedBlocks[(coord[c] / Tetris.Resources.BlockHeight), (coord[c + 1] / Tetris.Resources.BlockWidth)] != null;
                pieceCollision |= collision;
                if (collision && coord[c + 1] < minCollisionPoint)
                {
                    minCollisionPoint = coord[c + 1];
                }
            }

            if (pieceCollision)
            {
                if (minCollisionPoint - min < max - minCollisionPoint)
                {
                    #region Check for left piece collision and eventually do a wall kick
                    actualTetramino.Rotate(false);
                    #endregion
                }

                else
                {
                    #region Check for right piece collision and eventually do a wall kick
                    actualTetramino.Rotate(false);
                    #endregion
                }
            }

            else
            {
                #region Check for left wall collision and eventually do a wall kick
                if (min < 0)
                {
                    int  moves   = -min / Tetris.Resources.BlockWidth;
                    bool canMove = true;

                    for (int i = 0; i < coord.Length; i += 2)
                    {
                        canMove &= landedBlocks[(coord[i] / Tetris.Resources.BlockHeight), (coord[i + 1] / Tetris.Resources.BlockWidth + moves)] == null;
                    }

                    if (canMove)
                    {
                        for (int m = 0; m < moves; m++)
                        {
                            actualTetramino.MoveRight();
                        }
                    }
                    else
                    {
                        actualTetramino.Rotate(false);
                    }
                }
                #endregion

                #region Check for right wall collision and eventually do a wall kick
                else if (max >= view.CanvasWidth)
                {
                    int  moves   = (max - (int)view.CanvasWidth) / Tetris.Resources.BlockWidth + 1;
                    bool canMove = true;

                    for (int i = 0; i < coord.Length; i += 2)
                    {
                        canMove &= landedBlocks[(coord[i] / Tetris.Resources.BlockHeight), (coord[i + 1] / Tetris.Resources.BlockWidth - moves)] == null;
                    }

                    if (canMove)
                    {
                        for (int m = 0; m < moves; m++)
                        {
                            actualTetramino.MoveLeft();
                        }
                    }
                    else
                    {
                        actualTetramino.Rotate(false);
                    }
                }
                #endregion
            }
        }