When two worlds collide
Collision detection in game maker was easy! Unfortunately when things are too easy they fail to explain how things really work! This challenge is designed to help you understand collision detection by looking at some sample code.

Think of items on your page as rectangles. The problem is to test to see if rectangles are intersecting or not. Use this link to get some detail of how the test can be done. The code below shows an example of how collision detection can be done in small basic.
size = 20 rbx = 20 rby = 20 rb_hspeed = 3 rb_vspeed = 3 GraphicsWindow.BrushColor = "red" redBall = Shapes.AddEllipse(size, size) bbx = 200 bby = 20 bb_hspeed = -3 bb_vspeed = 3 GraphicsWindow.BrushColor = "blue" blueBall = Shapes.AddEllipse(size, size) loop = 1 while loop = 1 bbx = bbx + bb_hspeed bby = bby + bb_vspeed Shapes.move(blueBall, bbx, bby) rbx = rbx + rb_hspeed rby = rby + rb_vspeed Shapes.move(blueBall, rbx, rby) if bbx + size > rbx and bbx < rbx + size and bby + size > rby and bby < rby + size then ???????? endif endwhile
Using the above code your task is to get the balls to bounce off each other. They should also bounce off the walls (that is a separate task which should be completed before this one. This task requires you to do some independent research into collision detection. This is reflected in the reward!

You need to log in or create an account to submit code!











