Read joystick axis using events.

This commit is contained in:
Steve 2018-02-20 22:12:07 +00:00
parent 59e8b08fdc
commit 2fabf5302b
4 changed files with 40 additions and 14 deletions

View File

@ -69,6 +69,16 @@ void clearControl(int type)
{
app.joypadButton[btn] = 0;
}
if (type == CONTROL_LEFT || type == CONTROL_RIGHT)
{
app.joypadAxis[JOYPAD_AXIS_X] = 0;
}
if (type == CONTROL_UP || type == CONTROL_DOWN)
{
app.joypadAxis[JOYPAD_AXIS_Y] = 0;
}
}
void clearControls(void)

View File

@ -98,6 +98,11 @@ static void doButtonUp(SDL_JoyButtonEvent *event)
}
}
static void doJoyAxis(SDL_JoyAxisEvent *event)
{
app.joypadAxis[event->axis] = event->value;
}
void clearInput(void)
{
SDL_Event event;
@ -113,7 +118,6 @@ void clearInput(void)
void handleInput(void)
{
int i;
SDL_Event event;
app.mouse.dx = 0;
@ -154,6 +158,10 @@ void handleInput(void)
case SDL_JOYBUTTONUP:
doButtonUp(&event.jbutton);
break;
case SDL_JOYAXISMOTION:
doJoyAxis(&event.jaxis);
break;
case SDL_QUIT:
exit(0);
@ -162,9 +170,4 @@ void handleInput(void)
}
SDL_GetMouseState(&app.mouse.x, &app.mouse.y);
for (i = 0 ; i < JOYPAD_AXIS_MAX ; i++)
{
app.joypadAxis[i] = SDL_JoystickGetAxis(app.joypad, i);
}
}

View File

@ -22,6 +22,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
void initAtlasTest(void)
{
int test;
dev.cheatStatic = 0;
dev.cheatBlind = 0;
dev.cheatNoEnemies = 0;
@ -31,13 +33,22 @@ void initAtlasTest(void)
dev.cheatLevels = 0;
loadGame();
/*
STRNCPY(game.worldId, "beachFront1", MAX_NAME_LENGTH);
initWorld();
*/
/*initHub();*/
initOptions();
test = 1;
switch (test)
{
case 0:
initOptions();
break;
case 1:
STRNCPY(game.worldId, "beachFront1", MAX_NAME_LENGTH);
initWorld();
break;
case 2:
initHub();
break;
}
}

View File

@ -24,6 +24,8 @@ extern void initWorld(void);
extern void initHub(void);
extern void loadGame(void);
extern void initOptions(void);
extern void loadMusic(char *filename);
extern void playMusic(int loop);
extern Dev dev;
extern Game game;