Mulitple movements with keyboard in C++

Posted by DDukesterman on Programmers See other posts from Programmers or by DDukesterman
Published on 2012-09-26T23:52:41Z Indexed on 2012/09/27 3:48 UTC
Read the original article Hit count: 162

Filed under:
|
|

Im trying to get my movement of a ball to just move in a fluid like motion. How can I have it that when I press the up key, down key, left key, or right key, it doesnt move up one unit, stop, then keep moving. Also, how can i have it move in two directions at the same time wthout stopping another direction when letting off a key? Thanks

if(GetAsyncKeyState(VK_UP)) 
{
    if(g_nGameState == SETTINGUPSHOT_GAMESTATE || g_nGameState == INITIAL_GAMESTATE)
    {
        g_cObjectWorld.AdjustCueBallY(MOVEDELTA); 
        g_cObjectWorld.ResetImpulseVector();
    }
}
if(GetAsyncKeyState(VK_DOWN)) 
{
    if(g_nGameState == SETTINGUPSHOT_GAMESTATE || g_nGameState == INITIAL_GAMESTATE)
    {
        g_cObjectWorld.AdjustCueBallY(-MOVEDELTA); 
        g_cObjectWorld.ResetImpulseVector();
    }
}

if(GetAsyncKeyState(VK_LEFT)) 
{
    if(g_nGameState == SETTINGUPSHOT_GAMESTATE || g_nGameState == INITIAL_GAMESTATE)
    {
        g_cObjectWorld.AdjustCueBallX(-MOVEDELTA); 
        g_cObjectWorld.ResetImpulseVector();
    }
}

if(GetAsyncKeyState(VK_RIGHT)) 
{
    if(g_nGameState == SETTINGUPSHOT_GAMESTATE || g_nGameState == INITIAL_GAMESTATE)
    {
        g_cObjectWorld.AdjustCueBallX(MOVEDELTA); 
        g_cObjectWorld.ResetImpulseVector();
    }
}

© Programmers or respective owner

Related posts about c++

Related posts about Windows