diff --git a/src/main.cpp b/src/main.cpp index a7c0514..a09ef95 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1094,7 +1094,7 @@ int main(int argc, char **argv) { SDL_SetHint(SDL_HINT_VIDEO_DRIVER, "wayland,x11"); #endif - if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS)) { + if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_GAMEPAD)) { log_error("Failed to initialize SDL (%s). Exiting.", SDL_GetError()); return 1; } @@ -1488,7 +1488,28 @@ int main(int argc, char **argv) { } dragging_tile_change = false; - } break;; + } break; + + case SDL_EVENT_GAMEPAD_BUTTON_DOWN: { + if (io.WantCaptureKeyboard) + continue; + + if (event.gbutton.button == SDL_GAMEPAD_BUTTON_DPAD_UP) { + player.pos_y = clamp(0, player.pos_y + 1, map_height - 2); + } + + if (event.gbutton.button == SDL_GAMEPAD_BUTTON_DPAD_LEFT) { + player.pos_x = clamp(0, player.pos_x - 1, map_width - 2); + } + + if (event.gbutton.button == SDL_GAMEPAD_BUTTON_DPAD_DOWN) { + player.pos_y = clamp(0, player.pos_y - 1, map_height - 2); + } + + if (event.gbutton.button == SDL_GAMEPAD_BUTTON_DPAD_RIGHT) { + player.pos_x = clamp(0, player.pos_x + 1, map_width - 2); + } + } break; } } }