Button check function?

Hello everyone,

I'm making a small game for my application to a college, but I'm quite new to C++.

The game is going to be a Win32 Console game for now. It's a 2D real-time game in which a player tries to reach the top of the room by climbing boxes and tries to avoid getting crushed under falling boxes.

I want to make the player move by checking if an arrow button is pressed, but I need some help. Is there some function which checks for a pressed button without pausing the program?

I'm going to make the game for Windows only now, so using Windows OS libraries is not a problem.

Thanks in advance!
Use a loop, something like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
bool running = true;

while( running )
{
    while( ! _kbhit() ) // conio libary // while no key is being pressed
    {
        update(); // run falling boxes updates etc.
    }

    //catch the key that was pressed
    char key = _getch(); // also conio

    // convert to lower case
    key = tolower( key );

    switch( key )
    {
        // a key pressed
        case 'a':
            break;
    }
}


I just wrote this in FireFox, so it may not compile.

Hope this helps. (:
Looks good, I'll check if I can get it running this afternoon.
Topic archived. No new replies allowed.