Draw() public method

public Draw ( GameTime gameTime ) : void
gameTime GameTime
return void
Ejemplo n.º 1
0
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);
            spriteBatch.Begin();
            // Draw the background
            spriteBatch.Draw(background, new Rectangle(250, 200, 320, 768), Color.White);
            // Draw the ghost piece
            // currentTetromino?.DrawGhost(spriteBatch, BoardLocation);
            // Draw the board
            gameBoard.Draw(spriteBatch, BoardLocation, texture1px);
            nextBlockBoards.Draw(spriteBatch, nextBlockBoardsLocation, texture1px);
            // Draw Game Info

            // Score
            spriteBatch.DrawString(GameFont, String.Format("Score: {0}", Score), new Vector2(50, 60), Color.White);
            // Level
            spriteBatch.DrawString(GameFont, String.Format("Level: {0}", Level), new Vector2(50, 110), Color.White);
            // Lines
            spriteBatch.DrawString(GameFont, String.Format("Lines: {0}", Lines), new Vector2(50, 160), Color.White);

            player.Draw(spriteBatch, position1);


            if (GameOver)
            {
                // Draw game over screen
                spriteBatch.DrawString(GameFont, "Game Over!\nPress Enter to restart.", new Vector2(50, 210), Color.Red);
            }

            // Display the debug Window
            //DrawDebugWindow(spriteBatch);

            spriteBatch.End();
            base.Draw(gameTime);
        }
Ejemplo n.º 2
0
        private void spawnBlock()
        {
            if (_nextBlock == null)
            {
                _nextBlock             = new Block(_rand);
                _nextBlock.Coordinates = new Point(2, 2);
                Debug.WriteLine("Next block spawned: " + _nextBlock.Type);
            }

            _block             = _nextBlock;
            _block.Coordinates = new Point(_rand.Next(3, _width - 3), 0);
            Debug.WriteLine("_block becomes: " + _block.Type);
            _nextBlock             = new Block(_rand);
            _nextBlock.Coordinates = new Point(2, 2);
            Debug.WriteLine("Next block spawned: " + _nextBlock.Type);

            if (_board.canSpawn(_block))
            {
                Debug.WriteLine("_block spawned, drawing...");
                _predict.Reset();
                _predict.Draw(_nextBlock);
                _board.Draw(_block);
            }
            else
            {
                _block = null;
                Debug.WriteLine("_block cannot spawn...\n GAME OVER");
                _blockMoveTimer.Stop();
                _board.gameOver();
                _predict.gameOver();
                _soundLib.gameOver();

                if (_score > _database.getHighScore())
                {
                    System.Windows.Forms.MessageBox.Show(
                        "Congrats " + _playerName + "! You got a new highscore!", "New Highscore", MessageBoxButtons.OK);
                }

                if (_score > 0)
                {
                    _database.saveNewScore(_score, _playerName);
                }

                _highScore = _database.getHighScore();
                updateScoreBoard(0);

                DialogResult dialogResult = System.Windows.Forms.MessageBox.Show(
                    "Game Over!\nWould you like to play again?", "Game Over", MessageBoxButtons.YesNo);
                if (dialogResult == System.Windows.Forms.DialogResult.Yes)
                {
                    _board.Reset();
                    Reset();
                    _blockMoveTimer.Start();
                }
                else if (dialogResult == System.Windows.Forms.DialogResult.No)
                {
                    this.Close();
                }
            }
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            Shape shape = new Shape(9, 5);

            Console.CursorVisible = false;

            for (int t = 0; true; t++)
            {
                t = t % 12000000;
                if (t == 0)
                {
                    Console.Clear();
                    for (int i = 0; i < Board.Width; i++)
                    {
                        Console.SetCursorPosition(i, Board.Height);
                        Console.Write("═");
                    }
                    for (int i = 0; i < Board.Height; i++)
                    {
                        Console.SetCursorPosition(Board.Width, i);
                        Console.Write("║");
                    }

                    shape.Update();
                    Board1.Draw();
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.White);

            Matrix ScaleMatrix = Matrix.CreateScale(new Vector3((float)graphics.GraphicsDevice.PresentationParameters.BackBufferWidth / 320f, (float)graphics.GraphicsDevice.PresentationParameters.BackBufferHeight / 288f, 1));

            spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, ScaleMatrix);

            //Draw the game board
            GameBoard.Draw(spriteBatch);

            spriteBatch.End();

            base.Draw(gameTime);
        }
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);
            spriteBatch.Begin();
            // Draw the background
            spriteBatch.Draw(background, new Rectangle(250, 200, 320, 768), Color.White);
            spriteBatch.Draw(winGame, new Vector2(570, 712), Color.White);
            spriteBatch.Draw(ground, new Vector2(250, 940), Color.White);
            spriteBatch.Draw(ground, new Vector2(0, 940), Color.White);
            spriteBatch.Draw(ground1, new Vector2(570, 808), Color.White);
            spriteBatch.Draw(startPlace, new Vector2(154, 872), Color.White);
            spriteBatch.Draw(logo, new Vector2(0, 0), Color.White);
            spriteBatch.Draw(nextPiece, new Vector2(571, 120), Color.White);

            // Draw the board
            gameBoard.Draw(spriteBatch, BoardLocation, texture1px);
            nextBlockBoards.Draw(spriteBatch, nextBlockBoardsLocation, texture1px);

            // Draw Game Info
            // Lines Cleared
            spriteBatch.DrawString(GameFont, String.Format("Cleared: {0}", Lines), new Vector2(50, 160), Color.White);

            // Draw the player
            if (playerShouldRemove == false)
            {
                player.Draw(spriteBatch, position1);
            }

            if (GameOver)
            {
                // Draw game over screen
                spriteBatch.DrawString(GameFont, "Game Over!\nPress Enter to restart.", new Vector2(50, 210), Color.Red);
            }

            // Display the debug Window
            DrawDebugWindow(spriteBatch);

            if (GameWon)
            {
                // Draw game over screen
                spriteBatch.DrawString(GameFont, "Game Won!\nPress Enter to restart.", new Vector2(50, 210), Color.Red);
            }


            spriteBatch.End();
            base.Draw(gameTime);
        }
Ejemplo n.º 6
0
        public void StartGame()
        {
            Console.Title = GameTitle;
            DisplayStartScreen();

            while (!board.IsGameOver())
            {
                board.CheckUserInput();
                board.Update();
                board.Draw();
                Thread.Sleep(TimeStep);
            }

            Console.SetCursorPosition(Console.WindowWidth / 2 - GameOverMsg.Length / 2, Console.WindowHeight / 2);
            Console.ForegroundColor = ConsoleColor.Black;
            Console.BackgroundColor = ConsoleColor.White;
            Console.Write(GameOverMsg);
            Console.ReadLine();
        }
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);
            spriteBatch.Begin();

            if (GameState == STATE_MENU || GameState == STATE_PAUSED)
            {
                spriteBatch.Draw(logo, new Rectangle(104, 80, 1472, 224), Color.White);
            }
            buttonStart.Draw(spriteBatch);
            buttonExit.Draw(spriteBatch);
            buttonResume.Draw(spriteBatch);
            buttonOutline.Draw(spriteBatch);
            buttonRestart.Draw(spriteBatch);

            if (GameState == STATE_PLAYING)
            {
                spriteBatch.Draw(background, new Rectangle(320 * 3 / 2, 0, 480 * 3 / 2, 640 * 3 / 2), Color.White);
                spriteBatch.Draw(goal, new Rectangle((1120 - 320) * 3 / 2, endHeight, 160 * 3 / 2, 160 * 3 / 2), Color.White);
                // spriteBatch.Draw(ground, new Vector2(250, 940), Color.White);
                // spriteBatch.Draw(ground, new Vector2(0, 940), Color.White);
                // spriteBatch.Draw(ground1, new Vector2(570, 808), Color.White);
                spriteBatch.Draw(StartBackground, new Rectangle(160 * 3 / 2, (640 - 160) * 3 / 2, 160 * 3 / 2, 160 * 3 / 2), Color.White);
                spriteBatch.Draw(startPlace, new Rectangle(160 * 3 / 2, (640 - 160) * 3 / 2, 160 * 3 / 2, 160 * 3 / 2), Color.White);
                spriteBatch.Draw(nextPiece, new Rectangle(32 * 3 / 2, 32 * 3 / 2, 256 * 3 / 2, 256 * 3 / 2), Color.White);
                spriteBatch.Draw(skipBoard, new Rectangle(32 * 3 / 2, 320 * 3 / 2, 256 * 3 / 2, 128 * 3 / 2), Color.White);
                if (skip == 0)
                {
                    spriteBatch.Draw(skip1, new Rectangle(32 * 3 / 2, 320 * 3 / 2, 256 * 3 / 2, 128 * 3 / 2), Color.White);
                }
                if (skip <= 1)
                {
                    spriteBatch.Draw(skip2, new Rectangle(32 * 3 / 2, 320 * 3 / 2, 256 * 3 / 2, 128 * 3 / 2), Color.White);
                }
                if (skip <= 2)
                {
                    spriteBatch.Draw(skip3, new Rectangle(32 * 3 / 2, 320 * 3 / 2, 256 * 3 / 2, 128 * 3 / 2), Color.White);
                }

                // Draw the board
                gameBoard.Draw(spriteBatch, BoardLocation, texture1px);
                for (int k = 0; k < nextBlockBoards.Length; k++)
                {
                    nextBlockBoards[k].Draw(spriteBatch, nextBlockBoardsLocation[k], texture1px);
                }

                // Draw the player
                // player.Draw(spriteBatch);
                player.Draw(gameTime, spriteBatch);
            }

            if (GameState == STATE_GAMEOVER)
            {
                // Draw game over screen
                spriteBatch.DrawString(GameFont, "You Lose!", new Vector2(450 * 3 / 2, 30 * 3 / 2), Color.Red);
                if (totalTime % 60 < 10)
                {
                    spriteBatch.DrawString(GameFont, "Time: " + Math.Truncate(totalTime / 60) + " : 0" + Math.Round(totalTime % 60, 2, MidpointRounding.ToEven), new Vector2(450 * 3 / 2, 110 * 3 / 2), Color.White);
                }
                else if (totalTime % 60 >= 10)
                {
                    spriteBatch.DrawString(GameFont, "Time: " + Math.Truncate(totalTime / 60) + " : " + Math.Round(totalTime % 60, 2, MidpointRounding.ToEven), new Vector2(450 * 3 / 2, 110 * 3 / 2), Color.White);
                }
                spriteBatch.DrawString(GameFont, "Lines: " + Lines, new Vector2(450 * 3 / 2, 190 * 3 / 2), Color.White);
                spriteBatch.Draw(win, new Rectangle(480 * 3 / 2, 260 * 3 / 2, 160 * 3 / 2, 160 * 3 / 2), Color.White);
            }

            // Display the debug Window
            // DrawDebugWindow(spriteBatch);

            if (GameState == STATE_GAMEWON)
            {
                // Draw game over screen
                spriteBatch.DrawString(GameFont, "You Win!", new Vector2(450 * 3 / 2, 30 * 3 / 2), Color.Yellow);
                if (totalTime % 60 < 10)
                {
                    spriteBatch.DrawString(GameFont, "Time: " + Math.Truncate(totalTime / 60) + " : 0" + Math.Round(totalTime % 60, 2, MidpointRounding.ToEven), new Vector2(450 * 3 / 2, 110 * 3 / 2), Color.White);
                }
                else if (totalTime % 60 >= 10)
                {
                    spriteBatch.DrawString(GameFont, "Time: " + Math.Truncate(totalTime / 60) + " : " + Math.Round(totalTime % 60, 2, MidpointRounding.ToEven), new Vector2(450 * 3 / 2, 110 * 3 / 2), Color.White);
                }
                spriteBatch.DrawString(GameFont, "Lines: " + Lines, new Vector2(450 * 3 / 2, 190 * 3 / 2), Color.White);
                spriteBatch.Draw(lose, new Rectangle(480 * 3 / 2, 260 * 3 / 2, 160 * 3 / 2, 160 * 3 / 2), Color.White);
            }

            spriteBatch.End();
            base.Draw(gameTime);
        }