[Fix] Prevent acceleration from sticking sometimes.

This commit is contained in:
Allanis 2013-05-23 16:24:44 +01:00
parent 71b68003f9
commit ef103b6548
2 changed files with 21 additions and 1 deletions

View File

@ -113,6 +113,20 @@ void input_setKeybind(char* keybind, KeybindType type, int key, int reverse) {
WARN("Unable to set keybind '%s', That command does not exist.", keybind);
}
// Get the value of a keybind.
int input_getKeybind(char* keybind, KeybindType* type, int* reverse) {
int i;
for(i = 0; strcmp(keybindNames[i], "end"); i++)
if(strcmp(keybind, input_keybinds[i]->name)==0) {
if(type != NULL) (*type) = input_keybinds[i]->type;
if(reverse != NULL) (*reverse) = input_keybinds[i]->reverse;
return input_keybinds[i]->key;
}
WARN("Unable to get keybinding '%s', that command doesn't exist", keybind);
return -1;
}
// == Run input method. ================================================
// keynum : Index of the input_keybinds keybind.
// value : Value of keypress (defined above).
@ -131,7 +145,12 @@ static void input_key(int keynum, double value, int abs) {
// Accelerating.
if(INGAME() && KEY("accel")) {
if(abs)player_acc = value;
else player_acc += value;
else {
// Prevent it from getting stuck.
if(value == KEY_PRESS) player_acc = 1.;
else if(value == KEY_RELEASE) player_acc = 0.;
}
// Double tap accel = afterburn!
t = SDL_GetTicks();
if((value == KEY_PRESS) && (t-input_accelLast <= input_afterburnSensibility)) {

View File

@ -12,6 +12,7 @@ typedef enum {
// Set input.
void input_setDefault(void);
void input_setKeybind(char* keybind, KeybindType type, int key, int reverse);
int input_getKeybind(char* keybind, KeybindType* type, int* reverse);
// Handle the events.
void input_handle(SDL_Event* event);