Joypad controls (hardcoded, for now).

This commit is contained in:
Steve 2018-02-07 19:20:36 +00:00
parent c287a1333e
commit 3afbfabeb5
4 changed files with 45 additions and 6 deletions

View File

@ -135,6 +135,13 @@ enum
#define GRAVITY_POWER 0.5f #define GRAVITY_POWER 0.5f
#define FRICTION 0.75f #define FRICTION 0.75f
enum
{
JOYPAD_AXIS_X,
JOYPAD_AXIS_Y,
JOYPAD_AXIS_MAX
};
enum enum
{ {
FACING_RIGHT, FACING_RIGHT,

View File

@ -320,6 +320,7 @@ typedef struct {
SDL_Joystick *joypad; SDL_Joystick *joypad;
int keyboard[MAX_KEYBOARD_KEYS]; int keyboard[MAX_KEYBOARD_KEYS];
int joypadButton[SDL_CONTROLLER_BUTTON_MAX]; int joypadButton[SDL_CONTROLLER_BUTTON_MAX];
int joypadAxis[JOYPAD_AXIS_MAX];
SDL_Texture *backBuffer; SDL_Texture *backBuffer;
SDL_Renderer *renderer; SDL_Renderer *renderer;
SDL_Window *window; SDL_Window *window;

View File

@ -37,12 +37,38 @@ void initControls(void)
{ {
game.config.joypadControls[i] = -1; game.config.joypadControls[i] = -1;
} }
game.config.joypadControls[CONTROL_JUMP] = 1;
game.config.joypadControls[CONTROL_FIRE] = 3;
game.config.joypadControls[CONTROL_JETPACK] = 2;
} }
int isControl(int type) int isControl(int type)
{ {
int key = game.config.keyControls[type]; int key, btn;
int btn = game.config.joypadControls[type];
key = game.config.keyControls[type];
btn = game.config.joypadControls[type];
if (type == CONTROL_LEFT && app.joypadAxis[JOYPAD_AXIS_X] <= -16384)
{
return 1;
}
if (type == CONTROL_RIGHT && app.joypadAxis[JOYPAD_AXIS_X] >= 16384)
{
return 1;
}
if (type == CONTROL_UP && app.joypadAxis[JOYPAD_AXIS_Y] <= -16384)
{
return 1;
}
if (type == CONTROL_DOWN && app.joypadAxis[JOYPAD_AXIS_Y] >= 16384)
{
return 1;
}
return ((key != 0 && app.keyboard[key]) || (btn != -1 && app.joypadButton[btn])); return ((key != 0 && app.keyboard[key]) || (btn != -1 && app.joypadButton[btn]));
} }

View File

@ -163,4 +163,9 @@ void handleInput(void)
{ {
app.joypadButton[i] = SDL_JoystickGetButton(app.joypad, i); app.joypadButton[i] = SDL_JoystickGetButton(app.joypad, i);
} }
for (i = 0 ; i < JOYPAD_AXIS_MAX ; i++)
{
app.joypadAxis[i] = SDL_JoystickGetAxis(app.joypad, i);
}
} }