Computer Science Canada How to make it so that game exits when circles hit mouse |
Author: | Confused Child [ Wed Nov 26, 2008 12:11 pm ] | ||
Post subject: | How to make it so that game exits when circles hit mouse | ||
Hey guys I made a game that has circles bouncing around the screen and the point is to dodge them. However I want to make it so that when one circle hits the mouse (which has a small circle on it) the game exits and you lose. That is what I am having trouble on. Please do help me because it is my ISU Here's the code:
I have an exit statement too but it only exits when the two bouncing circles hit. Here it is: distance_between_centres := sqrt ((circle_2_x - circle_1_x) ** 2 + (circle_2_y - circle_1_y) ** 2) exit when distance_between_centres <= circle_1_radius + circle_2_radius Please help me change this so that it exits when the circles hit the mouse. Thank you in advance! ![]() MOD EDIT: Remember the code tags! |
Author: | S_Grimm [ Wed Nov 26, 2008 12:47 pm ] | ||
Post subject: | Re: How to make it so that game exits when circles hit mouse | ||
Confused Child @ Wed Nov 26, 2008 12:11 pm wrote: Please do help me because it is my ISU Ummmmm........................ Just because it's your ISU does not mean we should help you. If anything, I think it means we should post advice and let you go from there. Another thing: CODE TAGS.
Third. Mouse.Where (x,y,z) use it to determine if the location is inside or touching one of your circles. |
Author: | MihaiG [ Wed Nov 26, 2008 3:05 pm ] | ||
Post subject: | Re: How to make it so that game exits when circles hit mouse | ||
essentially to detect when a circle hits a mouse, you need two know 5things the x coordinate of the circle, the y coordinate of the circle, the x coordinate of the mouse and the y coordinate of the mouse and the radius using this we can use the Pythagorean theorem to find the distance between the two points and compare it to the radius such as...
so i take the distance between the two points and subtract 25 from it, and compare it to 0.01 , if i do sqrt((px-cx)**2 + (py-cy)**2) -25 =0, there can be errors in the code which can screw it up, and this guarantees for any error in onscreen drawing of the circle you basically had the samething in your code, i |
Author: | Parker [ Wed Nov 26, 2008 3:20 pm ] | ||
Post subject: | RE:How to make it so that game exits when circles hit mouse | ||
Mihai, in my opinion that sounds a bit confusing. Probably more accurate the what I just did but I will give him another option. I am going to post the code for him to use because I believe he was on the right track and this was just a minor logic error. For your own good find out what you did wrong and what I fixed. Here is the new code :
|
Author: | Jurica [ Wed Nov 26, 2008 5:59 pm ] | ||
Post subject: | RE:How to make it so that game exits when circles hit mouse | ||
Made it a little better:
Mod Edit: Put in a missing ] in the tags |
Author: | Clayton [ Wed Nov 26, 2008 6:51 pm ] |
Post subject: | RE:How to make it so that game exits when circles hit mouse |
Careful on giving away full solutions guys. |
Author: | Parker [ Thu Nov 27, 2008 8:11 am ] | ||
Post subject: | RE:How to make it so that game exits when circles hit mouse | ||
Sorry Clayton, forgot that it was for Final Project. Confused, the best I can do is try to tell you what you are missing. You have this line:
That is an important part of your collision. So you are giving distance_between_centres a value but then are doing nothing with it. Use that variable with an if statement to check if the circles are touching. Hope I helped, Parker. |