Advertisement
Guest User

Untitled

a guest
Apr 7th, 2020
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.38 KB | None | 0 0
  1. using Microsoft.Xna.Framework;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace FlappyBird
  9. {
  10.     class PlayingState : GameObjectList
  11.     {
  12.         Bird bird;
  13.         GameObjectList pipes;
  14.         int frameCounter;
  15.         public PlayingState()
  16.         {
  17.             this.Add(new SpriteGameObject("spr_background"));
  18.             pipes = new GameObjectList();
  19.             this.Add(pipes);
  20.  
  21.             bird = new Bird();
  22.             this.Add(bird);
  23.         }
  24.         public override void Update(GameTime gameTime)
  25.         {
  26.             base.Update(gameTime);
  27.             if (frameCounter >100)
  28.             {
  29.                 this.Add(new Pipe());
  30.                 frameCounter = 0;
  31.             }
  32.             frameCounter++;
  33.             bool isGameOver = false;
  34.             foreach (Pipe pipe in pipes.Children) {
  35.                 if (pipe.Overlaps(bird))
  36.                 {
  37.                     Console.WriteLine("lol");
  38.                     SetGameOver();
  39.                     //Pipe.Reset();
  40.                 }
  41.             }
  42.             if (isGameOver == true)
  43.             {
  44.                 SetGameOver();
  45.             }
  46.         }
  47.         public void SetGameOver()
  48.         {
  49.             pipes.Children.Clear();
  50.             frameCounter = 0;
  51.             bird.Reset();
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement