Click here to Skip to main content
15,912,932 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
//Bird
               new Settings();
               //Bird
               //Set Colour Bird
               SolidBrush Yellow = new SolidBrush(Color.Yellow);
               Graphics Canvas = e.Graphics;
               //Make Bird
               Canvas.FillEllipse(Yellow, Bird.X, Bird.Y, Settings.WidthBird, Settings.HeightBird);

               SolidBrush Black = new SolidBrush(Color.Black);

               //Max Height
               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;
               //Walls
               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; //Defauly X value of wall
                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
Posted
Updated 27-Dec-18 7:19am
v3
Comments
Richard MacCutchan 27-Dec-18 12:19pm    
You need to use the same co-ordinate system for both bird and walls.

1 solution

Here is an example using .IntersectsWith():
Collision detection in C#.Net & Java example | Bits and Pieces of Code[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900