
-----------------------------------
TuringStudent
Sun Jun 12, 2011 12:38 pm

Need help doing collision detection for moving objects
-----------------------------------
What is it you are trying to achieve?
I am designing a game involving a moving blue square and moving red circles as enemies. The objective is to move my blue square across a rectangular area and dodge the enemy red circles who move in alternating up/down patterns (i.e. the first enemy moves down-up then the next guy up-down etc.). I am having great difficulty doing collision detection to stop my blue square from moving (and ultimately later on making him restart at the beginning of the level) when he collides with a red circle. 

What is the problem you are having? 
I cannot seem to come up with any proper way of using collisions detection whether by whatdotcolour commands or executing a command to die or something once the coordinates of my blue square are equal to some coordinate aspect of the red circle. 

Describe what you have tried to solve this problem
I have tried multiple solutions on my own without help, those including drawing my enemies as drawfilloval and the colour red (12) and then using a whatdotcolour command whose parameters are all the corners of my blue square so that as soon as any corner comes in contact with a red background essentially, my blue square will "die" and have to start at the beginning again. I have also tried collision detection using the changing Y coordinates of the red circles (they move up to down/ down to up so the position of their Y centre changes in a loop) to check if any corners of my blue square are equal to these Y coordinates. This doesnt work because I only want my blue square to die when he encounters the red circle and not just the coordinate at which the red circle is drawn. This causes me to die without getting close to the circle. 

Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)








Please specify what version of Turing you are using
Turing 4.1.1

-----------------------------------
Raknarg
Wed Jun 15, 2011 8:43 am

RE:Need help doing collision detection for moving objects
-----------------------------------
So im assuming you're trying to make a game that's basically the same as "The World's Hardest Game"?

-----------------------------------
TWizard
Fri Aug 12, 2011 6:07 pm

RE:Need help doing collision detection for moving objects
-----------------------------------
You may have already tried this but, if it were me i would have the box either equal out side or what ever speed your moving at give a negative speed, only when you box coordinated meet your enemy coordinated. Since the Draw.Box, uses 2 positions to draw it, and the Draw.Oval uses only 1 you would have to use the ovals position minus or plus in the direction you want it to detect with using its radius as the amount you want to detect.

if Box_X1 >= Ball_X - "ball radius" and Box_X2 = Ball_Y - "ball radius" and Box_Y2 