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; 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) 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) void clearInput(void)
{ {
SDL_Event event; SDL_Event event;
@ -113,7 +118,6 @@ void clearInput(void)
void handleInput(void) void handleInput(void)
{ {
int i;
SDL_Event event; SDL_Event event;
app.mouse.dx = 0; app.mouse.dx = 0;
@ -155,6 +159,10 @@ void handleInput(void)
doButtonUp(&event.jbutton); doButtonUp(&event.jbutton);
break; break;
case SDL_JOYAXISMOTION:
doJoyAxis(&event.jaxis);
break;
case SDL_QUIT: case SDL_QUIT:
exit(0); exit(0);
break; break;
@ -162,9 +170,4 @@ void handleInput(void)
} }
SDL_GetMouseState(&app.mouse.x, &app.mouse.y); 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) void initAtlasTest(void)
{ {
int test;
dev.cheatStatic = 0; dev.cheatStatic = 0;
dev.cheatBlind = 0; dev.cheatBlind = 0;
dev.cheatNoEnemies = 0; dev.cheatNoEnemies = 0;
@ -32,12 +34,21 @@ void initAtlasTest(void)
loadGame(); loadGame();
/* test = 1;
switch (test)
{
case 0:
initOptions();
break;
case 1:
STRNCPY(game.worldId, "beachFront1", MAX_NAME_LENGTH); STRNCPY(game.worldId, "beachFront1", MAX_NAME_LENGTH);
initWorld(); initWorld();
*/ break;
/*initHub();*/ case 2:
initHub();
initOptions(); break;
}
} }

View File

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