Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
What is the code for something like 'If up'? I am creating a Pong game, and I need the board to move according to the player

What I have tried:

So far I've done some research but nothing really helps. Thanks guys!
Posted
Updated 11-Feb-21 6:18am
Comments
jeron1 11-Feb-21 11:27am    
Richard MacCutchan 11-Feb-21 11:37am    
That is a solution shirley.
jeron1 11-Feb-21 11:46am    
With all the detailed information given in the OP (and all the other posts) I'm not going to assume they are even using Windows. Hell 'they' might be a bot at this point, given previous posts.....and don't call me Shirley! LOL
Rick York 11-Feb-21 11:48am    
I have never seen a pong game that does that. The "board" and walls of the game never move. Only the paddle and ball move in the game. The paddle moves only up and down but the ball moves all over the place.
Richard MacCutchan 11-Feb-21 11:51am    
This is the fourth question on this subject. It really is time you started to do some serious research.

1 solution

C++
int ch;
while ((ch = _getch()) != 27) /* 27 = Esc key */
{
    printf("%d", ch);
    if (ch == 0 || ch == 0xE0)
    {
        ch = _getch();
        printf (", %d - ", ch);
    }
    switch (ch)
    {
    case 0x48:  // up arrow
        printf("up arrow");
        break;
    case 0x50:  // down arrow
        printf("down arrow");
        break;
    case 0x4B:  // left arrow
        printf("left arrow");
        break;
    case 0x4D:  // right arrow
        printf("right arrow");
        break;
    }
    printf("\n");
}

printf("ESC %d\n", ch);
 
Share this answer
 
Comments
W Balboos, GHB 12-Feb-21 13:47pm    
For completeness, could you also add the "ANY" key to the switch?
Richard MacCutchan 13-Feb-21 4:04am    
:laugh:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900