Computer Science Canada Pong Help |
Author: | landfarm [ Mon Apr 19, 2010 7:20 pm ] | ||
Post subject: | Pong Help | ||
What is it you are trying to achieve? I am currently trying to make Pong more lively. What is the problem you are having? I believe that I am almost done the project, but I have no clue how to add trigonometry or an alternative to add "physics" into the game of Pong. I know it sounds easy, but I have absolutely no idea how to do it. For example, when you hit the ball with the paddle to hit it further to the left, I have no clue how to do this. I'm hoping for a tutorial to help teach me the concept, rather than having someone doing it for me. Btw, I searched on the forums, but I couldn't find what I was looking for. Post any relevant code (You may choose to attach the file instead of posting the code if it is too long) Here is my code so far.
Please specify what version of Turing you are using Version 4.1.1 |
Author: | DtY [ Mon Apr 19, 2010 7:27 pm ] |
Post subject: | RE:Pong Help |
I don't get what the problem is? Is this an assignment with the requirement of using physics or trigonometry? If that's all you need to do, you could add a display that tells you what angle the ball is coming towards your paddle at. |
Author: | landfarm [ Mon Apr 19, 2010 7:45 pm ] |
Post subject: | RE:Pong Help |
Sorry for not being clear. The problem is I don't know how incorporate that into the program. Like, if the ball hits the paddle at 20 degrees, then what? Oh yea, I added an extra "facx *= -1". Also, I just noticed that the ball sometimes gets stuck in the walls and just slides up or down it. What's going on there? |
Author: | TerranceN [ Mon Apr 19, 2010 8:52 pm ] |
Post subject: | RE:Pong Help |
Dont worry about angles, just reverse the y-direction (this will give the same effect) when it hits the paddles (but not the x-direction too). It gets stuck on the wall because of the if statement that stops y-axis movement when the ball is out of a certain range. Make the ball always move (get rid of the if statements), and let the walls take care of keeping the ball in the game. Hope that helps. |
Author: | landfarm [ Wed Apr 21, 2010 4:19 pm ] |
Post subject: | RE:Pong Help |
Oh yea, my bad. I forgot about that. K, I didn't understand what you were getting at TerranceN, but I found a work-around, so that when the ball did touch the walls, it would instantly move away 5, in addition to the negative velocities. Thanks! |
Author: | TerranceN [ Wed Apr 21, 2010 6:13 pm ] | ||
Post subject: | RE:Pong Help | ||
Sorry, I should have been more clear. I meant this part:
Because of these if statements, when it goes out of bounds it will stop moving, and your other out of bounds checking only changes direction so it will not be moved back inside the bounds. |
Author: | landfarm [ Tue May 04, 2010 6:30 pm ] |
Post subject: | RE:Pong Help |
Um, sorry for a late reply. I just checked this thread now. Anyway, thanks TerranceN for helping. Turns out that's what I fixed at the same time. |
Author: | USEC_OFFICER [ Wed May 05, 2010 1:48 pm ] |
Post subject: | RE:Pong Help |
Figures. |