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

View File

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

View File

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