Joypad controls (hardcoded, for now).
This commit is contained in:
parent
c287a1333e
commit
3afbfabeb5
|
@ -135,6 +135,13 @@ enum
|
|||
#define GRAVITY_POWER 0.5f
|
||||
#define FRICTION 0.75f
|
||||
|
||||
enum
|
||||
{
|
||||
JOYPAD_AXIS_X,
|
||||
JOYPAD_AXIS_Y,
|
||||
JOYPAD_AXIS_MAX
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
FACING_RIGHT,
|
||||
|
|
|
@ -320,6 +320,7 @@ typedef struct {
|
|||
SDL_Joystick *joypad;
|
||||
int keyboard[MAX_KEYBOARD_KEYS];
|
||||
int joypadButton[SDL_CONTROLLER_BUTTON_MAX];
|
||||
int joypadAxis[JOYPAD_AXIS_MAX];
|
||||
SDL_Texture *backBuffer;
|
||||
SDL_Renderer *renderer;
|
||||
SDL_Window *window;
|
||||
|
|
|
@ -37,12 +37,38 @@ void initControls(void)
|
|||
{
|
||||
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 key = game.config.keyControls[type];
|
||||
int btn = game.config.joypadControls[type];
|
||||
int key, btn;
|
||||
|
||||
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]));
|
||||
}
|
||||
|
|
|
@ -163,4 +163,9 @@ void handleInput(void)
|
|||
{
|
||||
app.joypadButton[i] = SDL_JoystickGetButton(app.joypad, i);
|
||||
}
|
||||
|
||||
for (i = 0 ; i < JOYPAD_AXIS_MAX ; i++)
|
||||
{
|
||||
app.joypadAxis[i] = SDL_JoystickGetAxis(app.joypad, i);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue