Thread: "Pong" NOTE: In Visual Basics!!! Needed Formula

  1. #1
    Helpmeplease
    Guest

    Question "Pong" NOTE: In Visual Basics!!! Needed Formula

    I am not sure about the coding for the physics of the game, such as when the ball hits the paddle how do you change it to bounce in the opposite direction, at the appropriate angle. If you have the answer e-mail me at [email protected]

    Thanks - I guess it doesn't apply to VB that much but a formula would be helpful. THANKS!

  2. #2
    Registered User
    Join Date
    Sep 2002
    Posts
    22

    Cool

    Well, most pong game physics can be pretty unrealistic... =P

    The simplest thing to think about is this: You have its horizontal speed and direction and its vertical speed and direction. They should not affect eachother at all. Picture the basic pong screen (a "ceiling" wall and a "floor" wall with nothing on the right or left except for two paddles.) You might start the ball moving at a 45 degree angle, meaning that the horizontal and vertical speed are the same. If the ball bounces up and hits the ceiling, the horizontal speed and directions shouldn't be affected at all. Really, neither would the vertical speed. The only thing that would happen would be that the vertical direction would be reversed. It's quite nifty. In the same way, if the ball hits a paddle, the horizontal direction is reversed, but nothing else. Keep in mind, you only need left or right (perhaps true or false) for the horizontal direction; the combination of horizontal (x) and verticle (y) direction and x and y speed all decide what angle the ball is moving together.
    In other words, you're not going to have an actual "angle" variable, because the combination of the horizontal and verticle speeds will decide all of that (specificly vert speed/horiz speed is the slope)

    *whew* Okay, now, if you make a pong game like that, it will be pretty boring. In most (good) games of pong, the speed and angle of the ball both change on the fly. It can be difficult to decide for what reasons this happens, though. In the real world, pong most closely resembles an air hockey table, except that instead of a circle you have a flat paddle that is always 90 degrees from the walls. And there's no friction.

    One realistic and strategic way to change the angle and even speed is "spin." What you would do is when the the ball is going to hit the paddle, you check the speed and direction that the PADDLE is moving by seeing where the paddle was a couple of frames ago. (Perhaps you could even be more exact by using Calculus but... naw =P) Think about this: If the left paddle is moving quickly upwards when the ball hits it (coming with a downward velocity), the ball gets some clockwise spin. When the ball hits the floor, it's rotating clockwise and moving to the right, so the horizontal speed is increased at that point.

    But that's pretty complicated. There are other ways. For example, you could just have speed increase steadily until someone loses, and have a cool "time mode" where you go as long as you can against a perfect computer. You could even add thsi additionally to spin.

    In popular games like DXBall and DXBall 2, which is like Breakout (the paddle is on the "floor" and you're breaking blocks at the top of the screen), they use a very unrealistic way to change angles but it works really well. Basicly, if the ball hits the left side of the paddle while the ball is moving left, the horizontal velocity increases. If the ball hits the paddle on the opposite side of the paddle from the direction the ball is moving, the horizontal velocity slows down. It doesn't make much sense but it's great fun to play.

    Ultimately, the best way to change the vector components in Pong is to let the user indirectly do it somehow, so that they can use some strategy. Heck, in the first pong game I made, I just looked at the last direction that the paddle moved, even if it was 10 minutes ago. If it moved with the ball, the ball got faster. If it moved opposite the ball, the ball got slower.

    The key is to make the user have some control over it somehow, even if the way it does that doesn't make sense in real life.

    Hope that helps! =0

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    22
    wait, actually, I got that DXBall thing wrong. In that game, the angle of the ball depends on where the ball hits on the paddle, but not in the way I described. If the ball hits the center of the paddle, it goes straight up. If it hits on the very right edge, it goes very sharply to the right, and anywehre inbetween it goes somewhere in between. it still works quite well.

  4. #4
    Registered User -Xp-'s Avatar
    Join Date
    Nov 2002
    Posts
    28
    wow, nice description, but of course its completly different in games liek 3d-breakout and 3d-pong, which make it much more complicated
    No I DIDN'T steal my name from Misro$ofts OS, it's pure coincidence.

    The lines around my name (-) are only there because i needed a name over the 3 character minimum letter limit

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Templates and Macros plus more...
    By Monkeymagic in forum C++ Programming
    Replies: 8
    Last Post: 01-20-2007, 05:53 PM
  2. Help needed in customizing MS Visual Studio.net
    By Kaminaga in forum C++ Programming
    Replies: 5
    Last Post: 06-26-2005, 03:41 PM
  3. Replies: 6
    Last Post: 04-04-2003, 10:09 PM
  4. odd errors from msvc std library files
    By blight2c in forum C++ Programming
    Replies: 6
    Last Post: 04-30-2002, 12:06 AM
  5. Visual J#
    By mfc2themax in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 10-08-2001, 02:41 PM