Esempio n. 1
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            delay += gameTime.ElapsedGameTime.Milliseconds;
            if (delay > 20)
            {
                delay = gameTime.ElapsedGameTime.Milliseconds;
                if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
                {
                    Exit();
                }

                if (columns.Count == 0)
                {
                    columns.Add(new Columns(Content.Load <Texture2D>("pipe-green"), 320));
                }

                if (Keyboard.GetState().IsKeyDown(Keys.Space) && !beforeJumpStatus && !bird.isDead)
                {
                    bird.Jump();
                }
                if (Keyboard.GetState().IsKeyDown(Keys.Space))
                {
                    beforeJumpStatus = true;
                }
                else
                {
                    beforeJumpStatus = false;
                }
                if (!bird.isDead)
                {
                    bird.Move(1);
                }
                for (int i = 0; i < columns.Count; i++)
                {
                    if (columns[i].x + columns[i].columnTexture.Width < 0)
                    {
                        columns.RemoveAt(i);
                    }
                }

                for (int i = 0; i < columns.Count; i++)
                {
                    if (!bird.isDead)
                    {
                        columns[i].Move(1);
                        columns[i].Colide(ref bird);
                    }
                }

                if (bird.isDead)
                {
                    isGameOver = true;
                }

                Console.WriteLine(bird.score);
                delay -= 30;
            }

            base.Update(gameTime);
        }
Esempio n. 2
0
 void Dt_Tick(object sender, EventArgs e)
 {
     player.Move(ActualHeight);
     foreach (Wall o in walls)
     {
         o.Move(ActualWidth, ActualHeight);
         if (player.Collide(o))
         {
             point++;
         }
     }
     InvalidateVisual();
 }
Esempio n. 3
0
 private void Jump()
 {
     if (_jumped)
     {
         if (_jumpIntervalCounter <= JUMP_INTERVAL)
         {
             _bird.Move();
         }
         else
         {
             _jumped = false;
             _jumpIntervalCounter = 0;
         }
         _jumpIntervalCounter++;
     }
     else
     {
         Fall();
     }
 }
Esempio n. 4
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);
        }