diff --git a/src/defs.h b/src/defs.h index 7ba012b..d9450cd 100644 --- a/src/defs.h +++ b/src/defs.h @@ -38,8 +38,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define SAVE_FILENAME "game.save" #define CONFIG_FILENAME "config.json" -#define SCREEN_WIDTH 1280 -#define SCREEN_HEIGHT 720 +#define SCREEN_WIDTH 1280 +#define SCREEN_HEIGHT 720 #define MAX_KEYBOARD_KEYS 350 #define MAX_MOUSE_BUTTONS 6 @@ -53,7 +53,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define MAX_NAME_LENGTH 32 #define MAX_DESCRIPTION_LENGTH 512 -#define MAX_LINE_LENGTH 1024 +#define MAX_LINE_LENGTH 1024 #define MAX_FILENAME_LENGTH 1024 #define NUM_TEXTURE_BUCKETS 32 @@ -113,7 +113,7 @@ enum }; #define EF_NONE 0 -#define EF_WEIGHTLESS (2 << 0) +#define EF_WEIGHTLESS (2 << 0) #define EF_BOUNCES (2 << 1) #define EF_TELEPORTING (2 << 2) #define EF_NO_ENVIRONMENT (2 << 3) @@ -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, diff --git a/src/structs.h b/src/structs.h index 9af569c..6409592 100644 --- a/src/structs.h +++ b/src/structs.h @@ -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; diff --git a/src/system/controls.c b/src/system/controls.c index 0f0e2b7..4e58e6f 100644 --- a/src/system/controls.c +++ b/src/system/controls.c @@ -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])); } diff --git a/src/system/input.c b/src/system/input.c index fc61276..8c8536b 100644 --- a/src/system/input.c +++ b/src/system/input.c @@ -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); + } }