Add gamepad support and hook it up with movement
This commit is contained in:
parent
f9f3cec9cc
commit
a2dc1a2158
@ -638,6 +638,8 @@ void FP_GameUpdate(TELY_Platform *platform, FP_Game *game, TELY_Renderer *render
|
|||||||
game->clicked_entity = game->prev_active_entity;
|
game->clicked_entity = game->prev_active_entity;
|
||||||
|
|
||||||
Dqn_V2 dir_vector = {};
|
Dqn_V2 dir_vector = {};
|
||||||
|
|
||||||
|
// NOTE: Keyboard movement input
|
||||||
if (TELY_Platform_InputScanCodeIsDown(input, TELY_PlatformInputScanCode_W))
|
if (TELY_Platform_InputScanCodeIsDown(input, TELY_PlatformInputScanCode_W))
|
||||||
dir_vector.y = -1.f;
|
dir_vector.y = -1.f;
|
||||||
if (TELY_Platform_InputScanCodeIsDown(input, TELY_PlatformInputScanCode_A))
|
if (TELY_Platform_InputScanCodeIsDown(input, TELY_PlatformInputScanCode_A))
|
||||||
@ -647,6 +649,15 @@ void FP_GameUpdate(TELY_Platform *platform, FP_Game *game, TELY_Renderer *render
|
|||||||
if (TELY_Platform_InputScanCodeIsDown(input, TELY_PlatformInputScanCode_D))
|
if (TELY_Platform_InputScanCodeIsDown(input, TELY_PlatformInputScanCode_D))
|
||||||
dir_vector.x = +1.f;
|
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) {
|
if (dir_vector.x && dir_vector.y) {
|
||||||
dir_vector.x *= 0.7071067811865475244f;
|
dir_vector.x *= 0.7071067811865475244f;
|
||||||
dir_vector.y *= 0.7071067811865475244f;
|
dir_vector.y *= 0.7071067811865475244f;
|
||||||
|
Loading…
Reference in New Issue
Block a user