Computer Science Canada collision detection/eating another bubble help |
Author: | Turing_Noob [ Sun May 10, 2009 9:48 am ] | ||
Post subject: | collision detection/eating another bubble help | ||
I have an assignment due 2morrow that involves a yellow circle eating some other smaller circles. <Answer Here> So far, i've been able to make the circles poped up and make the yellow circle move but not i need to find out how to make the yellow bubble grow by 5 pixals if i get the little red bubble. This is my code so far so can some please tell me how to make the yellow bubble eat the red bubble and then having the yellow bubble incrase by 5 pixals every time it eats the red bubble thx.
|
Author: | TheGuardian001 [ Sun May 10, 2009 12:23 pm ] | ||
Post subject: | Re: collision detection/eating another bubble help | ||
Okay, having looked over your code properly this time, I can now safely say it does matter where you put your collision detection. you currently have it inside an if statement (if counter > 50) that will only run once each time the cookie shows up. this means that unless the cookie shows up on top of them, you won't see the collision. Next up, you seem to be going at collisions in a very roundabout way. done properly, collisions should look something like this
if you use that formula (OUTSIDE of your if counter > 50 statement) then you should be able to detect collisions, and do whatever you want based on that collision. Oh, and as a note, this means that you don't need the collision detection stuff inside of the (if counter > 50) statement. Take that out entirely and use this method outside of that if statement. |
Author: | OneTwo [ Sun May 10, 2009 12:43 pm ] |
Post subject: | Re: collision detection/eating another bubble help |
Edit: The solution up top was much better. |
Author: | Turing_Noob [ Sun May 10, 2009 12:55 pm ] |
Post subject: | RE:collision detection/eating another bubble help |
TheGuardian001, your solution doesn't work. I still need help |
Author: | OneTwo [ Sun May 10, 2009 3:03 pm ] | ||||||
Post subject: | Re: collision detection/eating another bubble help | ||||||
TheGuardian001's solution is correct, here's his solution:
Explanation Your original code had the collision detection inside an if statement which in-turn doens't work because it only checks when new dots are drawn not when your yellow oval moves. To fix that problem, you have to move the collision detection code outside of the if statement like so:
Every single time the oval moves, it checks for collisions. As for the other code:
The Draw.Oval draws a black oval on the red cookie when the yellow oval touches it. Also, it sets the x, y co-ordinates of the red cookie to 0 or else you would see a black dot over your yellow oval as you pass over the cookie. |