Computer Science Canada Ball Moving Towards Mouse |
Author: | mike200015 [ Sat Apr 09, 2005 4:35 pm ] | ||
Post subject: | Ball Moving Towards Mouse | ||
Im working on a pong game, and what i have now is you can move the ball around on the paddle, and then when u press UP then the ball releases, but it always goes in the same direction because i have the ballx + 1 and bally + 1 , but i want to change it so that the user moves their mouse somewhere on the screen , and the ball shoots in that direction. Heres the paddle and ball part of my game: There is also a little problem with this, dont know how to fix it; if the paddle is moving and the ball hits it, then for some reason the ball doesnt bounce off, it stays on it and moves with it ![]()
|
Author: | Cervantes [ Sat Apr 09, 2005 5:17 pm ] | ||
Post subject: | |||
I didn't feel like working with your code, so I started fresh:
As for your collision problem, my first suggestion would be to use something other than whatdotcolour. Coordinate comparisons would be nice and easy. |
Author: | mike200015 [ Sat Apr 09, 2005 5:23 pm ] |
Post subject: | |
lol .. so confused with that ![]() wats the hyp, vx and vy for? And dnt understand the whole section when btn=1 |
Author: | Cervantes [ Sat Apr 09, 2005 6:04 pm ] |
Post subject: | |
the vx and vy are the x and y velocities of the ball. hyp = hypoteneuse. I calculated it by Pythagoras. given the point (ball.x, ball.y) and (mx, my), you can draw a hypotenuse from the one point to the other and then make a right angle triangle based on the hyp. If you take the horizontal side (deltaX) and divide it by the hyp, you'll get a decimal that is proportional to the length of deltaX. Therefore, the bigger deltaX, the bigger the ball.vx will be. Do the same for the verticle. I multiplied by ball.speed to make the ball move a bit faster. |
Author: | mike200015 [ Sat Apr 09, 2005 8:48 pm ] |
Post subject: | |
![]() |
Author: | Cervantes [ Sat Apr 09, 2005 9:09 pm ] |
Post subject: | |
Yes, unless you've got some curved surfaces, and account for those in your collisions. So, if the user chooses to fire it straight up, they lose. ![]() |