diff options
author | Charadon <dev@iotib.net> | 2022-09-11 12:56:50 -0400 |
---|---|---|
committer | Charadon <dev@iotib.net> | 2022-09-11 12:56:50 -0400 |
commit | 6e4baef8f260e18dc4ca2e39eb4a84c1e16add7e (patch) | |
tree | c3d087b0a9a67663fa7c7e72efcabee34d5f70ef /src | |
parent | 206d9bf191a8ac90ebeb47273a25c0daac410774 (diff) | |
download | Pong-C-6e4baef8f260e18dc4ca2e39eb4a84c1e16add7e.tar.gz |
Added player_controls_pressed, to check between a button being held vs a button being pressed.
Diffstat (limited to 'src')
-rw-r--r-- | src/controls.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/controls.c b/src/controls.c index 544813e..fca64da 100644 --- a/src/controls.c +++ b/src/controls.c @@ -17,3 +17,21 @@ int player_controls() { } return(-1); } + +/* Same as player_controls() but check if the button was pressed, rather than held down. */ +int player_controls_pressed() { + if( IsMouseButtonPressed(MOUSE_LEFT_BUTTON) || IsKeyPressed(KEY_SPACE) || IsGamepadButtonPressed(1, GAMEPAD_BUTTON_RIGHT_FACE_DOWN) ) { + return(CONTROLLER_ACTIVATE); + } else if( IsKeyPressed(KEY_ESCAPE) || IsGamepadButtonPressed(1, GAMEPAD_BUTTON_MIDDLE_RIGHT) ) { + return(CONTROLLER_PAUSE); + } else if( IsKeyPressed(KEY_A) || IsGamepadButtonPressed(1, GAMEPAD_BUTTON_LEFT_FACE_LEFT) ) { + return(CONTROLLER_LEFT); + } else if( IsKeyPressed(KEY_D) || IsGamepadButtonPressed(1, GAMEPAD_BUTTON_LEFT_FACE_RIGHT) ) { + return(CONTROLLER_RIGHT); + } else if( IsKeyPressed(KEY_W) || IsGamepadButtonPressed(1, GAMEPAD_BUTTON_LEFT_FACE_UP) ) { + return(CONTROLLER_UP); + } else if( IsKeyPressed(KEY_S) || IsGamepadButtonPressed(1, GAMEPAD_BUTTON_LEFT_FACE_DOWN) ) { + return(CONTROLLER_DOWN); + } + return(-1); +} |