# It is possible to react of a collision from a shape and the turtle?

• ### Question

• It is possible to  react of a collision from a shape and the turtle?

I need the code for this for my play MAZY (PID: ZTD270). Thank you and

Best Regards Martin
Thursday, July 1, 2010 7:07 AM

• If we have 2 shapes and we know their top (Y) and left (X) coordinates and their width (W) and height (H).

So for shape 1 we have X1, Y1, W1, H1 and for shape 2 we have X2, Y2, W2, H2

Then they overlap if:

X1+W1 >= X2 And X1 <= X2+W2 And Y1+H1 >= Y2 And Y1 <= Y2+H2

Overlapping works well for rectangular basic shapes.

Separation distance of the shape centres works well for circular shapes.

• Marked as answer by Friday, July 2, 2010 3:43 AM
Thursday, July 1, 2010 9:58 PM

### All replies

• Not other than using the same methods as other SmallBasic collision detection.

That is: you know where the Turtle is at any time (Turtle.X and Turtle.Y) and where any other shape is, so you can calculate this distance between them or check for a shape overlap using the coordinates of the turtle and other shape.  When a collision is detected (overlap of shapes or distance between them less than some limit), then change the behaviour of the shape or Turtle - bounce it or stop it or score a point etc.

Thursday, July 1, 2010 5:49 PM
• I do not saw the command shapes.gettop and getleft for the position from a shape. So it is easy. But i do not know the command for overlap. Please sent me a notice.

Best Regards Martin
Thursday, July 1, 2010 9:14 PM
• If we have 2 shapes and we know their top (Y) and left (X) coordinates and their width (W) and height (H).

So for shape 1 we have X1, Y1, W1, H1 and for shape 2 we have X2, Y2, W2, H2

Then they overlap if:

X1+W1 >= X2 And X1 <= X2+W2 And Y1+H1 >= Y2 And Y1 <= Y2+H2

Overlapping works well for rectangular basic shapes.

Separation distance of the shape centres works well for circular shapes.

• Marked as answer by Friday, July 2, 2010 3:43 AM
Thursday, July 1, 2010 9:58 PM