diff options
Diffstat (limited to 'src/controller.c')
| -rw-r--r-- | src/controller.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/controller.c b/src/controller.c new file mode 100644 index 0000000..cacada3 --- /dev/null +++ b/src/controller.c @@ -0,0 +1,37 @@ +#include "controller.h" + +#include <raylib.h> + +b32 is_button_pressed(i32 btn) +{ + return IsKeyPressed(btn); +} + +b32 is_button_held(i32 btn) +{ + return IsKeyDown(btn); +} + +b32 is_button_released(i32 btn) +{ + return IsKeyReleased(btn); +} + +vec2 get_dir_input(void) +{ + fx32 cont_x = (fx32)(FIXED_POINT_ONE * GetGamepadAxisMovement(0, 0)); + fx32 cont_y = (fx32)(FIXED_POINT_ONE * GetGamepadAxisMovement(0, 1)); + + fx32 key_w = is_button_held(KEY_W) ? FIXED_POINT_ONE : 0; + fx32 key_s = is_button_held(KEY_S) ? FIXED_POINT_ONE : 0; + fx32 key_a = is_button_held(KEY_A) ? FIXED_POINT_ONE : 0; + fx32 key_d = is_button_held(KEY_D) ? FIXED_POINT_ONE : 0; + + // Either Gamepad or Keyboard control, not both! + if(key_w != 0 || key_s != 0 || key_a != 0 || key_d != 0){ + cont_x = key_d - key_a; + cont_y = key_s - key_w; + } + + return (vec2){cont_x, cont_y}; +} |
