Computer Science Canada How to make a pogram that remembers where you clicked and makes ball goto it |
Author: | zero44 [ Sat Sep 19, 2009 9:14 am ] | ||
Post subject: | How to make a pogram that remembers where you clicked and makes ball goto it | ||
i wanna make a pogram where you click at 2 postions and then it remembers those postions as int variables then makes a ball got to the co-ordinate's in order as saved this is what i tried but failed
[/syntax] |
Author: | andrew. [ Sat Sep 19, 2009 9:45 am ] |
Post subject: | RE:How to make a pogram that remembers where you clicked and makes ball goto it |
You need to put a delay or wait for the mouse up before you get the second x,y coordinates. They show up as the same thing because you can't hold the mouse down for as long as only one loop cycle. |
Author: | zero44 [ Sat Sep 19, 2009 2:06 pm ] |
Post subject: | Re: How to make a pogram that remembers where you clicked and makes ball goto it |
i tried a delay and it didnt work |
Author: | Superskull85 [ Sat Sep 19, 2009 6:02 pm ] | ||||||||||
Post subject: | Re: How to make a pogram that remembers where you clicked and makes ball goto it | ||||||||||
A couple of problems. First, when you are saving the second position you are copying data from the balls position (ballx, bally) instead of the clicked position (x, y). This:
As opposed to this:
Second, in your second loop you have the following code:
Because your second loop is about moving the ball towards the second point (savex2, savey2) you do not need to deal with the first point (savex, savey) (hint: only one set of if statements are needed). I think that is what you want, but you may in fact want to move the ball from point one to point two. If that is the case than you would want to first set the balls position (ballx, bally) to point ones position (savex, savey) and increment the balls position using the vector formed from point one to point two (vectorx=savex2-savex, vectory=savey2-savey). Also, when you want to print the balls position you should use the ball coordinate variables instead of the mouse coordinate variables. So this:
Instead of this:
Hope that helped. |