Thread: Need help in my ping pong game.

  1. #1
    Registered User
    Join Date
    May 2016
    Posts
    4

    Need help in my ping pong game.

    Hello guys, i managed to make the bat move up and down, but i also have to make it move to the right and left.
    Code:
    void p1Move()
    {     p1_tempY = p1_y;     
    if( key[KEY_W] && p1_y > 0){
                 --p1_y;
                      } else if( key[KEY_S] && p1_y < 420){
                 ++p1_y;                  }
    So can anybody please help me on how to make the ball move right and left, i know i should do this
    Code:
    } else if( key[KEY_A] && p1_y < 420){
                 ++p1_y;
                      }
    But what do i place instead of the 420?

  2. #2
    Registered User
    Join Date
    Jun 2015
    Posts
    1,640
    420 is a good number. A very good number. I'm all for that.

    However, to move horizontally you will want to modify the x coordinate. Try copying the vertical code and changing the y's to x's (and change the keys as well). And you may not want the high value to be 420. If the paddle is allowed to travel anywhere in the window then you would use the horizontal window size, which is presumably different from the vertical size. But you may want to limit it to something less than that.

    The above is for the left-hand paddle. For the right-side paddle you'll want to use the vertical size instead of 0, and 0 (or whatever you want to limit it to) for the other value.

  3. #3
    Registered User
    Join Date
    May 2016
    Posts
    4
    So is this correct?
    Code:
    } elseif( key[KEY_A] && p1_x < 75){
                 --p1_x;
                      }

  4. #4
    Registered User
    Join Date
    May 2016
    Posts
    4
    Quote Originally Posted by algorism View Post
    420 is a good number. A very good number. I'm all for that.

    However, to move horizontally you will want to modify the x coordinate. Try copying the vertical code and changing the y's to x's (and change the keys as well). And you may not want the high value to be 420. If the paddle is allowed to travel anywhere in the window then you would use the horizontal window size, which is presumably different from the vertical size. But you may want to limit it to something less than that.
    The above is for the left-hand paddle. For the right-side paddle you'll want to use the vertical size instead of 0, and 0 (or whatever you want to limit it to) for the other value.
    Ok thank you, i managed to do it, but i need to buffer because, the "bat" is sticking to the screen while i move.

    Code:
    acquire_screen();
        rectfill( buffer, p1_tempX, p1_tempY, p1_tempX + 10, p1_tempY + 60, makecol ( 0, 0, 0));
        rectfill( buffer, p1_x, p1_y, p1_x + 10, p1_y + 60, makecol ( 0, 0, 255));
        release_screen();

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ping-pong game
    By benjaminp in forum C Programming
    Replies: 1
    Last Post: 10-23-2012, 10:39 AM
  2. Hi!!Regarding 3D Ping Pong 2 players
    By stylish_guy in forum Linux Programming
    Replies: 1
    Last Post: 05-12-2009, 09:01 AM
  3. Ping Pong remake
    By Akkernight in forum Game Programming
    Replies: 3
    Last Post: 02-25-2009, 07:56 AM
  4. ping pong buffering scheme
    By cblix in forum Tech Board
    Replies: 0
    Last Post: 11-23-2005, 05:26 PM

Tags for this Thread