From 6f4930e920b3f368d0fcb9acfd2824095b101681 Mon Sep 17 00:00:00 2001 From: Uneven Prankster Date: Tue, 25 Jul 2023 17:29:32 -0300 Subject: Controller and Rumble stuff. --- src/controller.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/controller.c (limited to 'src/controller.c') 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 + +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}; +} -- cgit v1.2.3