( search forums )
VB.NET Collision Detection
Soldat Forums - Misc - The Lounge
wormdundee
January 17, 2006, 12:48 am
Well I think it's pretty self-explanatory. I was wondering how you could get the program to detect whether a picture box is colliding with another picture box.

I had thought up one way involving checking x and y coordinates but that didn't work so well and I can't find a damn thing using google. I'm sure somebody here knows.

Elephant_Hunter
January 17, 2006, 6:20 am
I'll draw out some pseudo code for ya.

You have two picture boxes... let's say the tortoise and the car. The car has four points that could possibly get inside the square area of the tortoise.

function boxCollide(tortoise, car)
' Check all four points of the car
if (pointInsideBox(car.X, car.Y, tortoise) or pointInsideBox(car.X + car.Width, car.Y, tortoise) or pointInsideBox(car.X, car.Y + car.Height, tortoise) or pointInsideBox(car.X + car.Width, car.Y + car.Height, tortoise))
return true
else
return false
end if
end function

function pointInsideBox(pointX, pointY, box)
if ((pointX > box.X) and (pointY > box.Y) and (pointX < box.X + box.Width) and (pointY < box.Y + box.Height)) then
return true
else
return false
end if
end function

Guess I'll send you a .vb file.

Here

wormdundee
January 17, 2006, 5:50 pm
Looks like that makes sense, thanks.

Right now I have it colliding just in a really retarded way. This should probably work better.