blah blah blah is here! blah blah » Close

up0down
link

I was looking to find a collision detector, For my first 2-D game, And found that code:
private bool collide()
{
return !(Box1.Location.X > Box2.Location.X + Box2.Size.Width
|| Box1.Location.X + Box1.Size.Width < Box2.Location.X
|| Box1.Location.Y > Box2.Location.Y + Box2.Size.Height
|| Box1.Location.Y + Box1.Size.Height < Box2.Location.Y);
}
First off, Please explain me what It does. I like to write code only when I understand every single char. Second, I want to make a maze game. I need to check collision with the walls, which will be some squares one near each other. I want to detect collision with ANY of the squares. How can I do it?
thanks! (Michael)

last answered 2 years ago

1 answers

up0down
link

since you are doing a 2d collision detection, the case will be of 2 boxes colliding to each other, the box might be a square or a rectangle. so you measure the 4 box borders if they collide to each other(upper boder,bottom border,left border and right border). This way you are doing 2d collision detection.

This post was imported from csharpfriends, if you have a similiar question please ask it again.

All previous members have been migrated, hope you enjoy the new platform!

Feedback