Restored the old digital conversion of analog input for main menu.

This allows using an analog stick to control the main menu once
again. Part of #7.
This commit is contained in:
Layla Marchant 2020-07-27 10:36:10 -04:00
parent eb2c61cd04
commit 21e16c157b
1 changed files with 27 additions and 7 deletions

View File

@ -246,6 +246,8 @@ static enum keys mapkey(int code) {
void player_getInput() void player_getInput()
{ {
static int prevjoyup = 0, prevjoydown = 0, prevjoyleft = 0, prevjoyright = 0;
int joyup, joydown, joyleft, joyright;
double val; double val;
static int px = -1, py = -1; static int px = -1, py = -1;
int x, y, w, h; int x, y, w, h;
@ -317,6 +319,23 @@ void player_getInput()
break; break;
case SDL_JOYAXISMOTION: case SDL_JOYAXISMOTION:
if (engine.gameSection == SECTION_TITLE) {
if (engine.event.jaxis.axis == 0) {
joyleft = engine.event.jaxis.value < -16384;
joyright = engine.event.jaxis.value >= 16384;
if (joyleft != prevjoyleft)
engine.keyState[KEY_LEFT] = prevjoyleft = joyleft;
if (joyright != prevjoyright)
engine.keyState[KEY_RIGHT] = prevjoyright = joyright;
} else if (engine.event.jaxis.axis == 1) {
joyup = engine.event.jaxis.value < -16384;
joydown = engine.event.jaxis.value >= 16384;
if (joyup != prevjoyup)
engine.keyState[KEY_UP] = prevjoyup = joyup;
if (joydown != prevjoydown)
engine.keyState[KEY_DOWN] = prevjoydown = joydown;
}
} else {
val = MIN(1, (double)(abs(engine.event.jaxis.value)) / JS_MAX); val = MIN(1, (double)(abs(engine.event.jaxis.value)) / JS_MAX);
if (val < JS_DEADZONE) if (val < JS_DEADZONE)
val = 0; val = 0;
@ -325,6 +344,7 @@ void player_getInput()
engine.xaxis = copysign(val, engine.event.jaxis.value); engine.xaxis = copysign(val, engine.event.jaxis.value);
else if (engine.event.jaxis.axis == 1) else if (engine.event.jaxis.axis == 1)
engine.yaxis = copysign(val, engine.event.jaxis.value); engine.yaxis = copysign(val, engine.event.jaxis.value);
}
break; break;