Computer Science Canada Need Help- ball won't stay on scroll bar |
Author: | The_Triangle [ Sat Nov 12, 2005 7:38 am ] | ||
Post subject: | Need Help- ball won't stay on scroll bar | ||
i been trying forever to make this ball bounce off of the paddle (its not pong, but something like it) and its just not happening. i tried to make that if the ball_x is equal to the scroll's x, the ball_y would remain on the same y cordinate as the scrolls y. New Code:
|
Author: | MysticVegeta [ Sat Nov 12, 2005 12:55 pm ] |
Post subject: | |
Please post the necessary images and zip it please. Thank you. |
Author: | Cervantes [ Sat Nov 12, 2005 1:20 pm ] |
Post subject: | |
Think about storing the velocity of the ball in variables. ball_x ball_y ball_vx ball_vy That way, you can use a little Collision Detection to check if the ball has hit the paddle. If it has, you reverse the velocity that is perpendicular to the plane of the paddle. In other words, if the paddle moves from left to right and the ball hits the top of it, reverse its y velocity. |
Author: | The_Triangle [ Sat Nov 12, 2005 3:31 pm ] |
Post subject: | |
Cervantes wrote: Think about storing the velocity of the ball in variables.
ball_x ball_y ball_vx ball_vy That way, you can use a little Collision Detection to check if the ball has hit the paddle. If it has, you reverse the velocity that is perpendicular to the plane of the paddle. In other words, if the paddle moves from left to right and the ball hits the top of it, reverse its y velocity. that would help if i knew what velocity was... |
Author: | The_Triangle [ Sat Nov 12, 2005 3:32 pm ] |
Post subject: | |
MysticVegeta wrote: Please post the necessary images and zip it please. Thank you.
I'll re-edit the code , so that there are no pictures |
Author: | [Gandalf] [ Sat Nov 12, 2005 4:26 pm ] |
Post subject: | |
Please don't double post. Velocity is just speed with direction. So if you had a speed of 10km/h then an equal velocity could be 10km/h east. Translating this to more programmable terms, you have an x velocity and a y velocity. Now, each of those has a direction, so it can be either + or -. Lets say your ball hits the paddle going vy=0 and vx=4, then once it hits the paddle vx=vx*-1 or vx=-4. |
Author: | The_Triangle [ Sun Nov 13, 2005 9:23 am ] |
Post subject: | |
[Gandalf] wrote: Please don't double post.
Velocity is just speed with direction. So if you had a speed of 10km/h then an equal velocity could be 10km/h east. Translating this to more programmable terms, you have an x velocity and a y velocity. Now, each of those has a direction, so it can be either + or -. Lets say your ball hits the paddle going vy=0 and vx=4, then once it hits the paddle vx=vx*-1 or vx=-4. Ok, say I use ball_vx and ball_vy. What use would I have for my ball_x and my ball_y variables ? |
Author: | Cervantes [ Sun Nov 13, 2005 10:17 am ] | ||
Post subject: | |||
You would add the x velocity to the x position and the y velocity to the y position, each time though the loop:
|
Author: | Albrecd [ Mon Nov 14, 2005 2:54 pm ] | ||
Post subject: | |||
Right now, your only collision detection is that if the ball hits the bottom of the screen then it puts "you lose." You need another procedure or proc or whatever you want to use (procedure would be the best) to determine if the ball has hit the paddle. Ex:
Also, you should probably not have x_ball be equal to x_paddle (which it currently is) or you can't lose. |
Author: | Albrecd [ Mon Nov 14, 2005 3:03 pm ] |
Post subject: | |
Sorry, that "any" in the code is supposed to be "and." I would have edited it but for some reason It won't give me that option sorry |
Author: | do_pete [ Mon Nov 14, 2005 3:04 pm ] | ||
Post subject: | |||
or you could go
|