From 8ac5b66a3f174e535fffaaef4b3f45b4a55559b9 Mon Sep 17 00:00:00 2001 From: Joshalosh Date: Sat, 23 Sep 2023 21:09:07 +1000 Subject: [PATCH] Add gamepad support and hook it up with movement --- feely_pona.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/feely_pona.cpp b/feely_pona.cpp index 7724dc0..5c54a3d 100644 --- a/feely_pona.cpp +++ b/feely_pona.cpp @@ -629,6 +629,8 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_Renderer *renderer, game->clicked_entity = game->prev_active_entity; Dqn_V2 dir_vector = {}; + + // NOTE: Keyboard movement input if (TELY_Platform_InputScanCodeIsDown(input, TELY_PlatformInputScanCode_W)) dir_vector.y = -1.f; if (TELY_Platform_InputScanCodeIsDown(input, TELY_PlatformInputScanCode_A)) @@ -638,6 +640,15 @@ void FP_Update(TELY_Platform *platform, FP_Game *game, TELY_Renderer *renderer, if (TELY_Platform_InputScanCodeIsDown(input, TELY_PlatformInputScanCode_D)) dir_vector.x = +1.f; + // NOTE: Gamepad movement input + for (uint32_t gamepad = 0; gamepad < MAX_GAMEPADS; gamepad++) { + if (input->button_codes[gamepad]) { + dir_vector.x += input->left_stick[gamepad].x; + dir_vector.y += input->left_stick[gamepad].y; + } + } + + if (dir_vector.x && dir_vector.y) { dir_vector.x *= 0.7071067811865475244f; dir_vector.y *= 0.7071067811865475244f;