Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Numerics;
- using Raylib_cs;
- namespace FlappyBird;
- public class Pipe
- {
- private const int moveSpeed = 2;
- private Vector2 position;
- private readonly int width;
- private readonly int height;
- private readonly int gap;
- private readonly Raylib_cs.Color color;
- public Vector2 Position { get { return position; } }
- public int Width => width;
- public bool Passed { get; set; }
- public Pipe(Vector2 position, int width, int height, int gap, Color color)
- {
- this.position = position;
- this.width = width;
- this.height = height;
- this.gap = gap;
- this.color = color;
- this.Passed = false;
- }
- public void Update()
- {
- position.X -= moveSpeed;
- }
- public void Draw()
- {
- Raylib.DrawRectangle((int)position.X, (int)position.Y, width, height, color);
- Raylib.DrawRectangle((int)position.X, (int)position.Y + height + gap,
- width, Game.screenHeight - height - gap, color);
- }
- public bool IsOffScreen()
- {
- return position.X + width < 0;
- }
- public bool CheckCollision(Vector2 birdPosition)
- {
- bool collisionTopPipe = false;
- bool collisionBottomPipe = false;
- collisionTopPipe = birdPosition.X + Bird.size > position.X &&
- birdPosition.X - Bird.size < position.X + width &&
- birdPosition.Y - Bird.size < position.Y + height;
- collisionBottomPipe = birdPosition.X + Bird.size > position.X &&
- birdPosition.X - Bird.size < position.X + width &&
- birdPosition.Y + Bird.size > position.Y + height + gap;
- return collisionTopPipe || collisionBottomPipe;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement