So i was making a game like flappy bird however i am unable to make a proper collison system. The bird is a circular Ellipse while the walls are rectangles.
In my current system the collision works randomly and pointlessly. Basically it is broken.
Visual representation
https://youtu.be/1RElwfCVNZg
Gametimer is part of my update frame function basically every .1 sec a new frame comes up
What I have tried:
How i made the Bird and Rectanglular wall
new Settings();
SolidBrush Yellow = new SolidBrush(Color.Yellow);
Graphics Canvas = e.Graphics;
Canvas.FillEllipse(Yellow, Bird.X, Bird.Y, Settings.WidthBird, Settings.HeightBird);
SolidBrush Black = new SolidBrush(Color.Black);
int MAxHeight = PbCanvas.Size.Height;
MH = MAxHeight - 80;
if (i == 0 || i % j == 1)
{
HeightD = random.Next(10, MAxHeight - 80);
}
HeightU = MH - HeightD;
Bottom = PbCanvas.Bottom;
Canvas.FillRectangle(Black, X, 0, 50, HeightU);
Canvas.FillRectangle(Black, X, Bottom - HeightD, 50, HeightD);
I and J means 2 things. I means how many times a wall has spawned and j is the amount of secodns between each wall being spawned
My idea for collision is
if (Bird.X == X && Bird.Y > HeightD && Bird.Y < HeightU - 80)
{
GameOver = true;
label2.Visible = true;
MessageBox.Show("You Died");
X = 300;
GameTimer.Stop();
}
Here is 2 walls are present. If its more than the height of the top wall it will pass and if the height of bottom wall is less than the it will pass. THe problems i am encountering are that the bird values are in X and Y coords while the wall values are in height. What can be the possible colutions to this