Fixed double-controls.

This commit is contained in:
Layla Marchant 2020-07-27 11:41:40 -04:00
parent ca11cdea27
commit cf7a82515d
3 changed files with 145 additions and 127 deletions

View File

@ -266,7 +266,6 @@ void engine_setMode()
int radioLife = DEFAULT_RADIO_LIFE;
char lang[STRMAX_SHORT];
int i;
int use_gc;
strcpy(lang, "default");
@ -333,22 +332,24 @@ void engine_setMode()
SDL_EventState(SDL_MOUSEMOTION, SDL_DISABLE);
// Determine if the GameController API can be used
use_gc = 1;
engine.useController = 1;
for (i=0; i<SDL_NumJoysticks(); i++) {
if (!SDL_IsGameController(i)) {
use_gc = 0;
engine.useController = 0;
break;
}
}
if (use_gc)
if (engine.useController) {
SDL_GameControllerEventState(SDL_ENABLE);
else
}
else {
SDL_JoystickEventState(SDL_ENABLE);
}
// Open controllers
for (i=0; i<SDL_NumJoysticks(); i++) {
if (use_gc)
if (engine.useController)
SDL_GameControllerOpen(i);
else
SDL_JoystickOpen(i);

View File

@ -98,6 +98,8 @@ typedef struct Engine_ {
double xaxis;
double yaxis;
int useController;
int cheat; // overall cheat
int cheatShield;
int cheatCash;

View File

@ -287,6 +287,8 @@ void player_getInput()
case SDL_JOYBUTTONDOWN:
case SDL_JOYBUTTONUP:
if (!engine.useController)
{
switch (engine.event.jbutton.button)
{
case 0:
@ -315,10 +317,13 @@ void player_getInput()
engine.event.jbutton.state);
break;
}
}
break;
case SDL_CONTROLLERBUTTONDOWN:
case SDL_CONTROLLERBUTTONUP:
if (engine.useController)
{
switch (engine.event.cbutton.button)
{
case SDL_CONTROLLER_BUTTON_A:
@ -361,16 +366,22 @@ void player_getInput()
engine.event.cbutton.state);
break;
}
}
break;
case SDL_JOYHATMOTION:
if (!engine.useController)
{
engine.keyState[KEY_UP] = (engine.event.jhat.value & SDL_HAT_UP ? 1 : 0);
engine.keyState[KEY_DOWN] = (engine.event.jhat.value & SDL_HAT_DOWN ? 1 : 0);
engine.keyState[KEY_LEFT] = (engine.event.jhat.value & SDL_HAT_LEFT ? 1 : 0);
engine.keyState[KEY_RIGHT] = (engine.event.jhat.value & SDL_HAT_RIGHT ? 1 : 0);
}
break;
case SDL_JOYAXISMOTION:
if (!engine.useController)
{
if (engine.gameSection == SECTION_TITLE) {
if (engine.event.jaxis.axis == 0) {
joyleft = engine.event.jaxis.value < -16384;
@ -397,10 +408,13 @@ void player_getInput()
else if (engine.event.jaxis.axis == 1)
engine.yaxis = copysign(val, engine.event.jaxis.value);
}
}
break;
case SDL_CONTROLLERAXISMOTION:
if (engine.useController)
{
if (engine.gameSection == SECTION_TITLE) {
if (engine.event.caxis.axis == SDL_CONTROLLER_AXIS_LEFTX)
{
@ -430,6 +444,7 @@ void player_getInput()
else if (engine.event.caxis.axis == SDL_CONTROLLER_AXIS_LEFTY)
engine.yaxis = copysign(val, engine.event.caxis.value);
}
}
break;