Add key repeat
This commit is contained in:
parent
57097c57bb
commit
60cf16c8de
2 changed files with 14 additions and 3 deletions
15
game.h
15
game.h
|
@ -1366,6 +1366,17 @@ void LCR_gameSaveReplay(void)
|
|||
LCR_gamePopupMessage(LCR_texts[LCR_TEXTS_SAVED]);
|
||||
}
|
||||
|
||||
/**
|
||||
Checks if given key is either immediately pressed or repeated after being
|
||||
held for some time.
|
||||
*/
|
||||
uint8_t LCR_gameKeyActive(uint8_t key)
|
||||
{
|
||||
return LCR_game.keyStates[key] == 1 ||
|
||||
(LCR_game.keyStates[key] >= (1200 / LCR_SETTING_FPS)
|
||||
&& ((LCR_game.frame & 0x03) == 0));
|
||||
}
|
||||
|
||||
/**
|
||||
Helper subroutine, handles user input during main loop frame, EXCEPT for the
|
||||
driving input (that is handled in the loop itself).
|
||||
|
@ -1470,7 +1481,7 @@ void LCR_gameHandleInput(void)
|
|||
LCR_game.menu.selectedItem = 0;
|
||||
LCR_audioPlaySound(LCR_SOUND_CLICK);
|
||||
}
|
||||
else if (LCR_game.keyStates[LCR_KEY_UP] == 1)
|
||||
else if (LCR_gameKeyActive(LCR_KEY_UP))
|
||||
{
|
||||
LCR_LOG1("menu item up");
|
||||
|
||||
|
@ -1487,7 +1498,7 @@ void LCR_gameHandleInput(void)
|
|||
scrolled = -1;
|
||||
}
|
||||
}
|
||||
else if (LCR_game.keyStates[LCR_KEY_DOWN] == 1)
|
||||
else if (LCR_gameKeyActive(LCR_KEY_DOWN))
|
||||
{
|
||||
LCR_LOG1("menu item down");
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue