-
December 9th, 2012, 08:04 AM
#1
Collision with corners of a picturebox – C#
Hi,
I’m having a problem with collision between 2 pictureboxes.
The situation: I have a picturebox that represents a ball and that bounces around the form. In the middle of the form I’ve got another picturebox which is fixed. When the ball hits either the top or the bottom of the picturebox, it must be ricocheted / thrown back in the opposite Y-direction.
When the ball hits either the left or the right side of the picturebox, it must be thrown back in the opposite X-direction.
I already have the code for the situation above and it works! But I’ve got a problem when the ball hits one of the four corners of the picturebox. Does anyone know how I could fix this??
Code:
private void gameAreaCollisions()
{
if (picBoxBal.Bounds.IntersectsWith(picBoxMidden.Bounds))
{
if (picBoxBal.Top < picBoxMidden.Top && picBoxMidden.Top <= picBoxBal.Bottom)
BalSpeedY = -BalSpeedY;
else if (picBoxBal.Top <= picBoxMidden.Bottom && picBoxMidden.Bottom < picBoxBal.Bottom)
BalSpeedY = -BalSpeedY;
else // collision with left or right side
BalSpeedX = -BalSpeedX;
}
}
thanks in advance !
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|