Advertisement
Cassimus

PipeManager

Jun 21st, 2025
429
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 KB | None | 0 0
  1. using System.Numerics;
  2. using Raylib_cs;
  3.  
  4. namespace FlappyBird;
  5.  
  6. public class PipeManager
  7. {
  8.     private const int pipeWidth = 80;
  9.     private const int spawnInterval = 90;
  10.     private int frameCounter;
  11.     private Color pipeColor;
  12.     private bool passed;
  13.  
  14.     public List<Pipe> Pipes { get; private set; }
  15.  
  16.     public PipeManager()
  17.     {
  18.         pipeColor = Color.Green;
  19.         Pipes = new List<Pipe>();
  20.         frameCounter = 0;
  21.     }
  22.  
  23.     private void AddPipe()
  24.     {
  25.         int pipeGap = Raylib.GetRandomValue(150, 250);
  26.  
  27.         int pipeHeight =
  28.             Raylib.GetRandomValue(100, Game.screenHeight - pipeGap - 100);
  29.  
  30.         Vector2 pipePosition = new Vector2(Game.screenWidth, 0);
  31.  
  32.         var pipe = new Pipe(pipePosition, pipeWidth, pipeHeight, pipeGap, pipeColor);
  33.         Pipes.Add(pipe);
  34.     }
  35.  
  36.     public void Update()
  37.     {
  38.         frameCounter++;
  39.  
  40.         if (frameCounter >= spawnInterval)
  41.         {
  42.             AddPipe();
  43.             frameCounter = 0;
  44.         }
  45.  
  46.         for (int i = 0; i < Pipes.Count; i++)
  47.         {
  48.             Pipes[i].Update();
  49.             if (Pipes[i].IsOffScreen())
  50.             {
  51.                 Pipes.RemoveAt(i);
  52.             }
  53.         }
  54.  
  55.     }
  56.  
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement