Results 1 to 13 of 13

Thread: Making a pong computer

  1. #1

    Thread Starter
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    Making a pong computer

    Hello,


    I'm finished with my two player pong game. I have no idea how to make a computer to follow the label towards the ball... does anyone know how?


    I searched up examples and tried figuring it out but their code was very confusing

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Making a pong computer

    Moved to Games and Graphics.

  3. #3
    Frenzied Member
    Join Date
    Oct 2003
    Posts
    1,301

    Re: Making a pong computer

    Quote Originally Posted by paralinx
    I searched up examples and tried figuring it out but their code was very confusing
    How so?


    Just make the paddle's vertical position equal to the ball's vertical position and you can never lose.

    If you are going to limit the speed of the computer's paddle then the simplest method is to test if the ball is above or below the paddle and then move the paddle in the appropriate direction.
    This does make it difficult to deal with balls that have a high vertical speed.

    Another option is calculate the path of the ball, where it bounces off the walls and where it will cross the paddle's path.
    Then you place the paddle there and wait for the ball.

    This is for defensive AI.
    Offensive AI would need to decide how to play the ball back to the player.
    Will it go fast and straight?
    Will it bounce up and down rapidly?

  4. #4
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    Re: Making a pong computer

    That shouldn't be too hard. In each loop cycle, simply subtract the paddle's Yval by the Ball's Yval. If the value is negative, move the paddle up, and if the value is positive, move the paddle down (assuming the scale is with 0,0 on the top left corner). The most advance AI will keep with the ball exactly (although that would make it actually impossible to beat), and a lesser difficulty will have a slower moving paddle, or not start calculating until the ball is halfway towards them or something like that.

  5. #5
    Addicted Member makster246's Avatar
    Join Date
    Dec 2004
    Location
    nottingham
    Posts
    187

    Re: Making a pong computer

    This is how i would do it.



    VB Code:
    1. DAmount = ball.top - paddle.top
    2.  
    3. if DAmount <0 then
    4.   paddle.top = paddle.top - 10
    5. elseif DAmount >0 then
    6.   paddle.top = paddle.top + 10
    7. end if

  6. #6
    Frenzied Member
    Join Date
    Oct 2003
    Posts
    1,301

    Re: Making a pong computer

    Or just:
    paddle.top = ball.top

  7. #7
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: Making a pong computer

    Quote Originally Posted by jeroen79
    Or just:
    paddle.top = ball.top
    not a great method because the paddle would appear to jump at the start!

  8. #8
    Frenzied Member
    Join Date
    Oct 2003
    Posts
    1,301

    Re: Making a pong computer

    That's a matter of setting things up properly.

  9. #9
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: Making a pong computer

    yea, but evan so its not the best method in the world no offence intended its just clumsy programming

    Pino

  10. #10
    Frenzied Member
    Join Date
    Oct 2003
    Posts
    1,301

    Re: Making a pong computer

    How is it clumsy?
    You want the paddle to follow the ball.
    This will make it do just that with minimal effort.

    Of course, this will make the game very un-fun as you can't beat the AI.
    But that is a different thing.

  11. #11
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Making a pong computer

    It is clumsy as it does not take into account things such as the speed of the bat, size of the bat/ball, time to change direction, prediction of ball position, etc.

    As you pointed out, it would also be no fun to play against.

  12. #12
    Frenzied Member
    Join Date
    Oct 2003
    Posts
    1,301

    Re: Making a pong computer

    Actually, it doesn't need all those things.

    The difference with other methods is that this one assumes total and direct control over the bat's position.
    Other methods have direct and total control over the bat's position but can merely control the speed (up to a limit) and direction of the bat

    So the 'clumsy' method would be suited for the gods while us mere mortals have to do with other methods of control.

    Just to illustrate that in some cases lesser performance actually requires more work in software.

  13. #13
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    Re: Making a pong computer

    That was incredibly vague, what the heck are you talking about?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width