示例#1
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.CornflowerBlue);

            // TODO: Add your drawing code here
            spriteBatch.Begin();


            spriteBatch.Draw(background, new Vector2(0, 0), Color.White);

            for (int i = 0; i < columns.Count; i++)
            {
                columns[i].Draw(spriteBatch);
            }

            bird.Draw(spriteBatch);

            if (isGameOver)
            {
                spriteBatch.Draw(gameOver, new Vector2((graphics.PreferredBackBufferWidth / 2) - gameOver.Width / 2, (graphics.PreferredBackBufferHeight / 2) - gameOver.Height / 2), Color.White);
            }

            spriteBatch.End();
            base.Draw(gameTime);
        }
示例#2
0
        static int RunGame()
        {
            int         count    = 0;
            List <Pipe> PipeList = new List <Pipe>();



            Bird aBird = new Bird();

            aBird.X     = (ScreenW / 2) - 20;
            aBird.Y     = (ScreenH / 2) - 2;
            aBird.H     = 3;
            aBird.W     = 5;
            aBird.Lives = 1;
            aBird.Score = 0;

            bool Running = true;



            LogoDraw();
            Console.SetCursorPosition((ScreenW / 2) - 15, ScreenH / 2);
            Console.WriteLine("===Press Space bar to start===");
            if (Console.ReadKey(true).Key == ConsoleKey.Spacebar)
            {
                Console.SetCursorPosition(0, ScreenH / 2 + 10);
                Console.Write("====================================================================================================");
                Console.SetCursorPosition(0, ScreenH / 2 + 12);
                Console.Write("====================================================================================================");
                Console.SetCursorPosition(0, ScreenH / 2 + 11);
                for (int i = 0; i <= 100; i++)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.Write("#");
                    Thread.Sleep(10);
                }
                Console.Clear();


                // Game loop
                while (Running)
                {
                    if (count % 40 == 0)
                    {
                        //Update Pipe
                        Pipe aPipe = new Pipe();
                        aPipe.X  = ScreenW - 8;
                        aPipe.H  = Rd.Next(9, ScreenH - 10);
                        aPipe.W  = 6;
                        aPipe.WP = Rd.Next(6, 8);
                        PipeList.Add(aPipe);
                    }
                    //Move Pipe
                    List <Pipe> NewPipeList = new List <Pipe>();
                    for (int i = 0; i < PipeList.Count; i++)
                    {
                        Pipe OldPipe = PipeList[i];

                        if (OldPipe.X > 3)
                        {
                            Pipe MovedPipe = new Pipe();
                            MovedPipe.X  = OldPipe.X - 1;
                            MovedPipe.H  = OldPipe.H;
                            MovedPipe.W  = OldPipe.W;
                            MovedPipe.WP = OldPipe.WP;

                            NewPipeList.Add(MovedPipe);
                        }
                    }
                    PipeList = NewPipeList;
                    //collide check
                    for (int i = 0; i < PipeList.Count; i++)
                    {
                        if ((PipeList[i].X - 3 <= aBird.X + aBird.W && aBird.Y <= PipeList[i].H - PipeList[i].WP + 1 && PipeList[i].X + 3 >= aBird.X) ||
                            (PipeList[i].X - 3 <= aBird.X + aBird.W && aBird.Y + aBird.H >= PipeList[i].H + PipeList[i].WP && PipeList[i].X + 3 >= aBird.X))
                        {
                            if (aBird.Lives > 0)
                            {
                                aBird.Lives--;
                            }
                            if (aBird.Lives == 0)
                            {
                                Running = false;
                                break;
                            }
                        }

                        //update score
                        if (PipeList[i].X < aBird.X + aBird.W && PipeList[i].X + 1 >= aBird.X + aBird.W)
                        {
                            aBird.Score++;
                        }
                    }

                    //Move Bird
                    if (Console.KeyAvailable)
                    {
                        aBird.Move();
                    }


                    aBird.Y++;

                    // Clear
                    Console.Clear();

                    //Draw Pipe
                    for (int i = 0; i < PipeList.Count; i++)
                    {
                        Pipe ThisPipe = PipeList[i];
                        ThisPipe.Draw();
                    }

                    //Draw Bird
                    aBird.Draw();

                    //Show Score
                    Console.SetCursorPosition(1, 1);
                    Console.WriteLine("Score : {0}", aBird.Score);



                    //Count
                    count++;

                    //SetCurSor to 0,0
                    Console.SetCursorPosition(0, 0);

                    Thread.Sleep(50);
                }
            }
            return(aBird.Score);
        }
示例#3
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)
        {
            // Clear the graphics
            GraphicsDevice.Clear(Color.White);

            // Draw the base class
            base.Draw(gameTime);

            // Draw the background
            _SpriteBatch.Begin();
            _SpriteBatch.Draw(_Background, new Rectangle(0, 0, ScreenWidth, ScreenHeight), Color.White);
            _SpriteBatch.End();

            // Draw the bird
            _Bird.Draw(_SpriteBatch);

            // Draw the pipes
            foreach (Pipe pipe in _Pipes)
            {
                pipe.Draw(_SpriteBatch);
            }

            // Draw the floors
            foreach (Floor floor in _Floors)
            {
                floor.Draw(_SpriteBatch);
            }


            // Check the game state
            switch (_GameState)
            {
            case GameState.Ready:
            {
                // Draw the ready cover
                _SpriteBatch.Begin();
                _SpriteBatch.Draw(_ReadyCover, new Rectangle(0, 0, ScreenWidth, ScreenHeight), Color.White);
                _SpriteBatch.End();

                // Draw the tips
                _TipsFontRenderer.DrawText(_SpriteBatch, 10, ScreenHeight - 50, "Press [Space] to start...", Color.Black);
            }
            break;


            case GameState.Start:
            {
                // Draw the score
                _ScoreFontWidth = _ScoreFontRenderer.DrawText(_SpriteBatch, ScreenWidth / 2 - _ScoreFontWidth / 2, 80, _Score.ToString(), Color.White);
            }
            break;


            case GameState.GameOver:
            {
                // Draw the game over cover
                _SpriteBatch.Begin();
                _SpriteBatch.Draw(_GameoverCover, new Rectangle(0, 0, ScreenWidth, ScreenHeight), Color.White);
                _SpriteBatch.End();
                _ScoreFontWidth = _ScoreFontRenderer.DrawText(_SpriteBatch, 300 - _ScoreFontWidth, 250, _Score.ToString(), Color.White);

                // Draw the tips
                _TipsFontRenderer.DrawText(_SpriteBatch, 10, ScreenHeight - 50, "Press [Enter] to get ready...", Color.Black);
            }
            break;
            }
        }