Beispiel #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;
        }
Beispiel #2
0
        private void GameDraw()
        {
            GraphicsDevice.SetRenderTarget(nextRenderer);
            GraphicsDevice.Clear(Color.Transparent);
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied);
            int starting = 1;

            for (int i = 0; i < 5; i++)
            {
                foreach (Vector2 v in nextTetromino[i].StartingPosition())
                {
                    Rectangle kloc = new Rectangle(((int)v.X - 3) * 44, ((int)v.Y + 2) * 44 + (44 * starting), 44, 44);

                    if (nextTetromino[i].PieceSymbol() == 'i')
                    {
                        spriteBatch.Draw(IBlockTex, kloc, Color.White);
                    }
                    if (nextTetromino[i].PieceSymbol() == 'o')
                    {
                        spriteBatch.Draw(OBlockTex, kloc, Color.White);
                    }
                    if (nextTetromino[i].PieceSymbol() == 't')
                    {
                        spriteBatch.Draw(TBlockTex, kloc, Color.White);
                    }
                    if (nextTetromino[i].PieceSymbol() == 's')
                    {
                        spriteBatch.Draw(SBlockTex, kloc, Color.White);
                    }
                    if (nextTetromino[i].PieceSymbol() == 'z')
                    {
                        spriteBatch.Draw(ZBlockTex, kloc, Color.White);
                    }
                    if (nextTetromino[i].PieceSymbol() == 'j')
                    {
                        spriteBatch.Draw(JBlockTex, kloc, Color.White);
                    }
                    if (nextTetromino[i].PieceSymbol() == 'l')
                    {
                        spriteBatch.Draw(LBlockTex, kloc, Color.White);
                    }
                }
                starting += 4;
            }
            spriteBatch.End();

            GraphicsDevice.SetRenderTarget(null);

            GraphicsDevice.SetRenderTarget(holdRenderer);
            GraphicsDevice.Clear(Color.Transparent);
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied);


            if (heldTetromino != null)
            {
                foreach (Vector2 v in heldTetromino.StartingPosition())
                {
                    Rectangle kloc = new Rectangle(((int)v.X - 3) * 44, ((int)v.Y + 2) * 44, 44, 44);

                    if (heldTetromino.PieceSymbol() == 'i')
                    {
                        spriteBatch.Draw(IBlockTex, kloc, Color.White);
                    }
                    if (heldTetromino.PieceSymbol() == 'o')
                    {
                        spriteBatch.Draw(OBlockTex, kloc, Color.White);
                    }
                    if (heldTetromino.PieceSymbol() == 't')
                    {
                        spriteBatch.Draw(TBlockTex, kloc, Color.White);
                    }
                    if (heldTetromino.PieceSymbol() == 's')
                    {
                        spriteBatch.Draw(SBlockTex, kloc, Color.White);
                    }
                    if (heldTetromino.PieceSymbol() == 'z')
                    {
                        spriteBatch.Draw(ZBlockTex, kloc, Color.White);
                    }
                    if (heldTetromino.PieceSymbol() == 'j')
                    {
                        spriteBatch.Draw(JBlockTex, kloc, Color.White);
                    }
                    if (heldTetromino.PieceSymbol() == 'l')
                    {
                        spriteBatch.Draw(LBlockTex, kloc, Color.White);
                    }
                }
            }


            spriteBatch.End();

            GraphicsDevice.SetRenderTarget(null);



            GraphicsDevice.SetRenderTarget(boardRenderer);
            GraphicsDevice.Clear(Color.Transparent);
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied);
            for (int i = 0; i < 20; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    Rectangle kloc = new Rectangle(j * 44, i * 44, 44, 44);


                    if (board[j, i + 20] == 'i')
                    {
                        spriteBatch.Draw(IBlockTex, kloc, Color.White);
                    }
                    if (board[j, i + 20] == 'o')
                    {
                        spriteBatch.Draw(OBlockTex, kloc, Color.White);
                    }
                    if (board[j, i + 20] == 't')
                    {
                        spriteBatch.Draw(TBlockTex, kloc, Color.White);
                    }
                    if (board[j, i + 20] == 's')
                    {
                        spriteBatch.Draw(SBlockTex, kloc, Color.White);
                    }
                    if (board[j, i + 20] == 'z')
                    {
                        spriteBatch.Draw(ZBlockTex, kloc, Color.White);
                    }
                    if (board[j, i + 20] == 'j')
                    {
                        spriteBatch.Draw(JBlockTex, kloc, Color.White);
                    }
                    if (board[j, i + 20] == 'l')
                    {
                        spriteBatch.Draw(LBlockTex, kloc, Color.White);
                    }
                }
            }
            foreach (Vector2 v in CurrentGhostPositions)
            {
                if (currentTetromino.PieceSymbol() != null)
                {
                    spriteBatch.Draw(GhostTex, new Rectangle((int)v.X * 44, (int)v.Y * 44, 44, 44), Color.White);
                }
            }
            foreach (Vector2 v in CurrentBlockPositions)
            {
                if (currentTetromino.PieceSymbol() == 'i')
                {
                    spriteBatch.Draw(IBlockTex, new Rectangle((int)v.X * 44, (int)v.Y * 44, 44, 44), Color.White);
                }
                if (currentTetromino.PieceSymbol() == 'o')
                {
                    spriteBatch.Draw(OBlockTex, new Rectangle((int)v.X * 44, (int)v.Y * 44, 44, 44), Color.White);
                }
                if (currentTetromino.PieceSymbol() == 't')
                {
                    spriteBatch.Draw(TBlockTex, new Rectangle((int)v.X * 44, (int)v.Y * 44, 44, 44), Color.White);
                }
                if (currentTetromino.PieceSymbol() == 's')
                {
                    spriteBatch.Draw(SBlockTex, new Rectangle((int)v.X * 44, (int)v.Y * 44, 44, 44), Color.White);
                }
                if (currentTetromino.PieceSymbol() == 'z')
                {
                    spriteBatch.Draw(ZBlockTex, new Rectangle((int)v.X * 44, (int)v.Y * 44, 44, 44), Color.White);
                }
                if (currentTetromino.PieceSymbol() == 'j')
                {
                    spriteBatch.Draw(JBlockTex, new Rectangle((int)v.X * 44, (int)v.Y * 44, 44, 44), Color.White);
                }
                if (currentTetromino.PieceSymbol() == 'l')
                {
                    spriteBatch.Draw(LBlockTex, new Rectangle((int)v.X * 44, (int)v.Y * 44, 44, 44), Color.White);
                }
            }

            spriteBatch.End();

            GraphicsDevice.SetRenderTarget(null);

            GraphicsDevice.SetRenderTarget(themeRenderer);
            GraphicsDevice.Clear(Color.Transparent);

            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied);

            spriteBatch.Draw(BackgroundTex, new Rectangle(0, 0, 1920, 1080), Color.White);
            spriteBatch.Draw(GridTex, new Rectangle(480, 0, 960, 1080), Color.White);
            spriteBatch.Draw(boardRenderer, new Rectangle(740, 100, 440, 880), Color.White);
            spriteBatch.Draw(nextRenderer, new Rectangle(1220, 119, 140, 462), Color.White);
            spriteBatch.Draw(holdRenderer, new Rectangle(600, 124, 140, 140), Color.White);
            spriteBatch.Draw(OverlayTex, new Rectangle(480, 0, 960, 1080), Color.White);

            spriteBatch.DrawString(neuro, $"SCORE:", new Vector2(1220, 650), Color.White);
            spriteBatch.DrawString(neuro, $"{score}", new Vector2(1220, 700), Color.White);
            spriteBatch.DrawString(neuro, $"CLEARED LINES:", new Vector2(1220, 775), Color.White);
            spriteBatch.DrawString(neuro, $"{linesCleared}", new Vector2(1220, 825), Color.White);
            spriteBatch.DrawString(neuro, $"LEVEL:", new Vector2(1220, 900), Color.White);
            spriteBatch.DrawString(neuro, $"{level}", new Vector2(1220, 950), Color.White);



            spriteBatch.End();

            GraphicsDevice.SetRenderTarget(null);



            spriteBatch.Begin();

            spriteBatch.Draw(themeRenderer, GraphicsDevice.Viewport.Bounds, Color.White);

            spriteBatch.End();
        }
Beispiel #3
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);
            }
        }