Thread: pong

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    380

    pong

    I need alot of help on my very simple pong clone that I am creating using the Windows API.

    How do I give the paddles limited movement? I want it limited between the players stats and the bottom.

    How do I stop the ball from disappearing off into the bottom and right side of the playing field?

    What type of AI would pong use?

    The ball bounces at a 45 degree angle. Is that the type of psyhics that pong uses?

    Thank you
    Don't you dare hit me on the head, you know I'm not normal.
    A Stooge Site
    Green Frog Software

  2. #2
    GA ichijoji's Avatar
    Join Date
    Nov 2002
    Posts
    179
    How do I give the paddles limited movement? I want it limited between the players stats and the bottom.
    Before you do keyboard input, store paddle x,y into temp vars, then after you do the keyboard input, determine a minx, miny, maxx, maxy with your values for player stats and the bottom. If the paddle has exceeded minx or maxx, set paddle.x to the pre-movement value, same for y.

    How do I stop the ball from disappearing off into the bottom and right side of the playing field?
    Since you're using dx and dy this is easy,
    Code:
    if (ball.x < ball.radius || ball.x > the width of the screen - ball.radius)
        ball.x *= -1;
    once again, repeat for y

    What type of AI would pong use?
    I don't know about everybody else, but I like to limit the possible values of dx somehow (like with the deflection from the paddles, see below), then make the ai paddle move a little bit slower than that.

    The ball bounces at a 45 degree angle. Is that the type of psyhics that pong uses?
    Once again, I can't speak for everybody, but I like to build this with two parts: First, put in collisions on the "walls" (the sides that don't have paddles) that just multiply d-whatever by -1 to make the ball bounce off (see above). Second, I like to put in code to make it that so the ball's speed between the paddle-sides is determined by where it hits the paddle, something like this:
    Code:
    const int maxdx = 4;
    if (ball.x >= paddle.x && ball.x <= paddle.x + paddle.width)
        ball.dx = (ball.x - paddle.x) / (paddle.width / 2 / maxdx);
    I'm not sure if that was what you were looking for, but I hope it helps.
    Illusion and reality become impartiality and confidence.

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    380
    Thanks for the help. Yes, that is the type of help I was looking for.
    Don't you dare hit me on the head, you know I'm not normal.
    A Stooge Site
    Green Frog Software

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Cant get a PONG
    By x77 in forum Networking/Device Communication
    Replies: 7
    Last Post: 07-25-2007, 09:48 AM
  2. Space Pong (Debug) Release
    By Jeremy G in forum Game Programming
    Replies: 6
    Last Post: 10-02-2005, 07:14 PM
  3. The Story Of Pong (my game cookie)
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 05-16-2005, 11:14 PM
  4. Battle Pong
    By DOlson in forum Game Programming
    Replies: 13
    Last Post: 01-08-2003, 11:32 PM
  5. God pong -update
    By gamegod3001 in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 09-03-2001, 09:16 PM