I am developing a game and am trying to accomplish collision detection for 2 picture boxes. I have a timer control that is responsible for moving a spike (enemy) towards a box (my character).
Here is my code:
private void tmrSpike_Tick(object sender, EventArgs e)
{
// Spike moving left interval
spike1.Left -= 6;
if (picSquare.ClientRectangle.IntersectsWith(spike1.ClientRectangle))
MessageBox.Show("sd");
if (spike1.Left + spike1.Width < 0)
spike1.Left = ActiveForm.Width;
}
PicturesBoxes:
spike1
picSquare
How do I make it so when the box (character) hits the spike (enemy), it shows an alert?
Note: Only the spike is moving towards the box. The box only jumps up and drops down when the up key is pressed. My game concept is VERY similar to this: http://www.flukedude.com/theimpossiblegame/
You are using the wrong property. ClientRectangle is the rectangle relative from the control. You want to use the Bounds property, relative from the container. Easy to see in the debugger btw, do practice using it.