Exemple #1
0
        public void Reset()
        {
            nextTetromino.Clear();
            currentTetromino = null;
            heldTetromino    = null;

            nextTetromino = BagRandomizer.GetNewBag();

            level          = MainPage.P1.GetStartingLevel();
            score          = 0;
            linesCleared   = 0;
            singleCleared  = 0;
            doublesCleared = 0;
            tripleCleared  = 0;
            tetrisCleared  = 0;

            Array.Clear(board, 0, 400);

            isBlockPlaced    = false;
            blockHeld        = false;
            blockCanMoveDown = true;

            currentTetromino = nextTetromino[0];
            nextTetromino.RemoveAt(0);
            CurrentBlockPositions = currentTetromino.StartingPosition();

            TempGameTotal = 0;
        }
Exemple #2
0
        private void GameUpdate(GameTime gameTime)
        {
            ///MISC
            //PAUSE
            if (currentGamepadState.IsButtonDown(Buttons.Start) && lastGamepadState.IsButtonUp(Buttons.Start) || currentKeyboardState.IsKeyDown(Keys.P) && lastKeyboardState.IsKeyUp(Keys.P))
            {
                currentGameState = GameStates.Pause;
            }

            //RESETING
            if (isBlockPlaced)
            {
                currentTetromino      = nextTetromino[0];
                CurrentBlockPositions = currentTetromino.StartingPosition();
                nextTetromino.RemoveAt(0);
                currentRotation  = Tetromino.rotations.rotation1;
                blockCanMoveDown = true;
                isBlockPlaced    = false;
                blockHeld        = false;
            }

            timer += timepassed;


            ///GENERATION PHASE
            //NEW BAG
            if (nextTetromino.Count < 7)
            {
                nextTetromino.AddRange(BagRandomizer.GetNewBag());
            }


            ///FALLING PHASE
            //AUTO MOVE DOWN
            if (timer >= Math.Pow((0.8 - ((level - 1) * 0.007)), (level - 1)))
            {
                Move(Directions.Down);
                timer = 0;
            }

            //HARD DROP?
            if (currentGamepadState.IsButtonDown(Buttons.DPadUp) && lastGamepadState.IsButtonUp(Buttons.DPadUp) || currentKeyboardState.IsKeyDown(Keys.Up) && lastKeyboardState.IsKeyUp(Keys.Up))
            {
                dropDistance          = (int)CurrentGhostPositions[1].Y - (int)CurrentBlockPositions[1].Y;
                CurrentBlockPositions = new List <Vector2>(CurrentGhostPositions);
                PlaceBlock();
                HarddropSFX.CreateInstance().Play();
                AddScore("hardDrop", dropDistance);
                isBlockPlaced = true;
            }


            ///LOCK PHASE
            //AUTO LOCK
            if (blockCanMoveDown == false)
            {
                lockTimer += timepassed;
                if (lockTimer >= 0.5)
                {
                    PlaceBlock();
                    isBlockPlaced = true;
                    lockTimer     = 0;
                }
            }

            //MOVING LEFT
            if (DASclickedLeft && !(currentGamepadState.IsButtonDown(Buttons.DPadLeft) || currentKeyboardState.IsKeyDown(Keys.Left)))
            {
                Debug.WriteLine("czyszczenie DASclickedLeft");
                DASclickedLeft = false;
            }

            if (currentGamepadState.IsButtonDown(Buttons.DPadLeft) || currentKeyboardState.IsKeyDown(Keys.Left))
            {
                if (DASclickedLeft == false)
                {
                    Debug.WriteLine("pierwszy klik");
                    DAStimerLeft = gameTime.TotalGameTime.TotalMilliseconds;

                    Move(Directions.Left);
                    DASclickedLeft = true;
                }
                if (gameTime.TotalGameTime.TotalMilliseconds > DAStimerLeft + DAS)
                {
                    if (gameTime.TotalGameTime.TotalMilliseconds - ARRtimer > ARR)
                    {
                        Debug.WriteLine("przesowanie ARR");
                        lockTimer = 0;
                        Move(Directions.Left);
                        ARRtimer = gameTime.TotalGameTime.TotalMilliseconds;
                    }
                }
            }

            //MOVING RIGHT
            if (DASclickedRight && !(currentGamepadState.IsButtonDown(Buttons.DPadRight) || currentKeyboardState.IsKeyDown(Keys.Right)))
            {
                Debug.WriteLine("czyszczenie DASclickedRight");
                DASclickedRight = false;
            }

            if (currentGamepadState.IsButtonDown(Buttons.DPadRight) || currentKeyboardState.IsKeyDown(Keys.Right))
            {
                if (DASclickedRight == false)
                {
                    Debug.WriteLine("pierwszy klik");
                    DAStimerRight = gameTime.TotalGameTime.TotalMilliseconds;

                    Move(Directions.Right);
                    DASclickedRight = true;
                }
                if (gameTime.TotalGameTime.TotalMilliseconds > DAStimerRight + DAS)
                {
                    if (gameTime.TotalGameTime.TotalMilliseconds - ARRtimer > ARR)
                    {
                        Debug.WriteLine("przesowanie ARR");
                        lockTimer = 0;
                        Move(Directions.Right);
                        ARRtimer = gameTime.TotalGameTime.TotalMilliseconds;
                    }
                }
            }

            //SOFT DROP
            if (currentGamepadState.IsButtonDown(Buttons.DPadDown) || currentKeyboardState.IsKeyDown(Keys.Down))
            {
                if (timer >= Math.Pow((0.8 - ((level - 1) * 0.007)), level - 1) / 20)
                {
                    lockTimer = 0;
                    timer     = 0;
                    Move(Directions.Down);
                }
            }


            //ROTATE
            if (currentGamepadState.IsButtonDown(Buttons.B) && lastGamepadState.IsButtonUp(Buttons.B) || currentKeyboardState.IsKeyDown(Keys.X) && lastKeyboardState.IsKeyUp(Keys.X))
            {
                lockTimer = 0;
                RotateSFX.CreateInstance().Play();
                CurrentBlockPositions = currentTetromino.Rotate(CurrentBlockPositions, currentRotation, Tetromino.rotationDirection.clockwise, ref board);
                if (currentRotation == Tetromino.rotations.rotation1)
                {
                    currentRotation = Tetromino.rotations.rotation2;
                }
                else if (currentRotation == Tetromino.rotations.rotation2)
                {
                    currentRotation = Tetromino.rotations.rotation3;
                }
                else if (currentRotation == Tetromino.rotations.rotation3)
                {
                    currentRotation = Tetromino.rotations.rotation4;
                }
                else if (currentRotation == Tetromino.rotations.rotation4)
                {
                    currentRotation = Tetromino.rotations.rotation1;
                }
            }


            if (currentGamepadState.IsButtonDown(Buttons.A) && lastGamepadState.IsButtonUp(Buttons.A) || currentKeyboardState.IsKeyDown(Keys.Z) && lastKeyboardState.IsKeyUp(Keys.Z))
            {
                lockTimer = 0;
                RotateSFX.CreateInstance().Play();
                CurrentBlockPositions = currentTetromino.Rotate(CurrentBlockPositions, currentRotation, Tetromino.rotationDirection.counterclockwise, ref board);
                if (currentRotation == Tetromino.rotations.rotation1)
                {
                    currentRotation = Tetromino.rotations.rotation4;
                }
                else if (currentRotation == Tetromino.rotations.rotation2)
                {
                    currentRotation = Tetromino.rotations.rotation1;
                }
                else if (currentRotation == Tetromino.rotations.rotation3)
                {
                    currentRotation = Tetromino.rotations.rotation2;
                }
                else if (currentRotation == Tetromino.rotations.rotation4)
                {
                    currentRotation = Tetromino.rotations.rotation3;
                }
            }

            //HOLD
            if ((currentGamepadState.IsButtonDown(Buttons.LeftShoulder) && lastGamepadState.IsButtonUp(Buttons.LeftShoulder) || currentKeyboardState.IsKeyDown(Keys.LeftShift) && lastKeyboardState.IsKeyUp(Keys.LeftShift)) && blockHeld == false)
            {
                if (heldTetromino == null)
                {
                    heldTetromino         = currentTetromino;
                    currentTetromino      = nextTetromino[0];
                    CurrentBlockPositions = currentTetromino.StartingPosition();
                    nextTetromino.RemoveAt(0);
                }
                else
                {
                    tempTetromino         = currentTetromino;
                    currentTetromino      = heldTetromino;
                    heldTetromino         = tempTetromino;
                    CurrentBlockPositions = currentTetromino.StartingPosition();
                }
                blockHeld = true;
            }

            ///ELIMINATE PHASE
            DeleteLines();

            //CHECK LEVEL UP
            if (linesCleared >= level * 10 + 10)
            {
                level++;
            }

            ///GHOST BLOCK
            ghostBlock();

            TempGameTotal += gameTime.ElapsedGameTime.TotalMilliseconds;

            if (currentGamemode.CheckWinCondition(linesCleared))
            {
                GameTotal        = TempGameTotal;
                currentGameState = GameStates.Win;

                SubmitStats(true);
            }
        }