pong game. Making the paddles move independly of each other

This is a discussion on pong game. Making the paddles move independly of each other within the C Programming forums, part of the General Programming Boards category; In pong, how can I make the two paddles move independtly of each other? At the moment, when player 1 ...

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    141

    pong game. Making the paddles move independly of each other

    In pong, how can I make the two paddles move independtly of each other? At the moment, when player 1 presses a letter on the keyboard, player 2 can't move and vice versa. I have used a simple getchar()

    Code:
    while ( ( c = getchar()) != 'Q' ){
            if ( c == 'k' ) RIGHT_paddle_up();
            else if ( c == 'm' ) RIGHT_paddle_down();
            else if (c == 's') LEFT_paddle_up();
            else if (c == 'x') LEFT_paddle_down();
    }

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    You need to use some lower level platform specific API which is capable of reading the key state of multiple keys at the same time.

    So, which OS and compiler are you using?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Jan 2011
    Posts
    141
    Quote Originally Posted by Salem View Post
    You need to use some lower level platform specific API which is capable of reading the key state of multiple keys at the same time.

    So, which OS and compiler are you using?
    I see. I am on linux - centos and using gcc to compile.
    What would be a better alternative?
    Last edited by bos1234; 05-21-2012 at 12:49 AM.

  4. #4
    Registered User
    Join Date
    May 2012
    Location
    Bonn, Germany
    Posts
    16
    Try SDL, a multimedia library: Simple DirectMedia Layer
    It will allow you to read each key's state individually (within the limitations of your keyboard).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pong, Need help with paddles and pause
    By trev456 in forum C++ Programming
    Replies: 8
    Last Post: 04-15-2007, 04:45 AM
  2. Making the move
    By cboard_member in forum A Brief History of Cprogramming.com
    Replies: 22
    Last Post: 07-19-2006, 06:14 AM
  3. making camera move with mouse
    By Ti22 in forum Game Programming
    Replies: 13
    Last Post: 01-16-2005, 07:56 AM
  4. Making a character MOVE!
    By unknownUser in forum Linux Programming
    Replies: 5
    Last Post: 05-19-2002, 04:42 PM
  5. Pong game?
    By Titan in forum Game Programming
    Replies: 0
    Last Post: 08-29-2001, 09:16 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21