diff options
-rw-r--r-- | src/controls.c | 16 | ||||
-rw-r--r-- | src/pong.h | 9 |
2 files changed, 24 insertions, 1 deletions
diff --git a/src/controls.c b/src/controls.c index ac5aa3d..544813e 100644 --- a/src/controls.c +++ b/src/controls.c @@ -1,5 +1,19 @@ #include "pong.h" +/* Checks what button the player is pressing amongst all control inputs. */ int player_controls() { - return(0); + if( IsMouseButtonDown(MOUSE_LEFT_BUTTON) || IsKeyDown(KEY_SPACE) || IsGamepadButtonDown(1, GAMEPAD_BUTTON_RIGHT_FACE_DOWN) ) { + return(CONTROLLER_ACTIVATE); + } else if( IsKeyDown(KEY_ESCAPE) || IsGamepadButtonDown(1, GAMEPAD_BUTTON_MIDDLE_RIGHT) ) { + return(CONTROLLER_PAUSE); + } else if( IsKeyDown(KEY_A) || IsGamepadButtonDown(1, GAMEPAD_BUTTON_LEFT_FACE_LEFT) ) { + return(CONTROLLER_LEFT); + } else if( IsKeyDown(KEY_D) || IsGamepadButtonDown(1, GAMEPAD_BUTTON_LEFT_FACE_RIGHT) ) { + return(CONTROLLER_RIGHT); + } else if( IsKeyDown(KEY_W) || IsGamepadButtonDown(1, GAMEPAD_BUTTON_LEFT_FACE_UP) ) { + return(CONTROLLER_UP); + } else if( IsKeyDown(KEY_S) || IsGamepadButtonDown(1, GAMEPAD_BUTTON_LEFT_FACE_DOWN) ) { + return(CONTROLLER_DOWN); + } + return(-1); } diff --git a/src/pong.h b/src/pong.h index 310c45f..fb7cc93 100644 --- a/src/pong.h +++ b/src/pong.h @@ -23,6 +23,14 @@ #define LEFT 0 #define RIGHT 1 +/* Controller Macros */ +#define CONTROLLER_ACTIVATE 1 +#define CONTROLLER_LEFT 2 +#define CONTROLLER_RIGHT 3 +#define CONTROLLER_UP 4 +#define CONTROLLER_DOWN 5 +#define CONTROLLER_PAUSE 6 + struct Players { float Y; Rectangle HitBox; @@ -65,5 +73,6 @@ void versus_main(); void marathon_main(); void set_screen_mode(); bool pause_screen(Camera2D *MainCamera); +int player_controls(); #endif |