private void pb_plane2_MouseMove(object sender, MouseEventArgs e)
{
if (moveplane2)
{
pb_plane2.Top = pb_plane2.Top + (e.Y - currentY);
pb_plane2.Left = pb_plane2.Left + (e.X - currentX);
}
if (movingpic)
{
int plane1L, plane2L, plane1R, plane2R, plane1T, plane2T, plane1B, plane2B;
collis = true;
plane1T = pb_plane1.Top;
plane2T = pb_plane2.Top;
plane1B = pb_plane1.Top + pb_plane1.Height;
plane2B = pb_plane2.Top + pb_plane2.Height;
plane1L = pb_plane1.Left; plane2L = pb_plane2.Left;
plane1R = pb_plane1.Left + pb_plane1.Width;
plane2R = pb_plane2.Left + pb_plane2.Width;
//check if there is a collision - collis = flase
if (plane1T > plane2B) collis = false;
if (plane1B < plane2T) collis = false;
if (plane1L > plane2R) collis = false;
if (plane1R < plane2L) collis = false;
if (collis)
{
//note: there is a lag time when this file plays and when the oops shows up
//taking out the sound file gets rid of the lag
tb_collision.Text = "OOPS!!!";
// sound clip
}
}
}
This code works just fine I just need to know how to code it from this to pixel so it colides with each plane and not the boxs around them :)
Danatas GerviPosted Sep 21, 2009, 7:36 AM
I do not think that you can to find the easy way to do this.
I suggest you to think about separating the collision logic and displaying.
I mean – you should create a virtual 2D space (field) – and two (o more) objects on it (planes, missiles …) with its own dimensions (array of points) and made all collisions checking with these virtual models. So display will get sometimes all data needed for drawing your field with all objects on it.