add basic gamepad support
This commit is contained in:
parent
19e75d3807
commit
d9bf936f0d
25
src/main.cpp
25
src/main.cpp
@ -1094,7 +1094,7 @@ int main(int argc, char **argv) {
|
|||||||
SDL_SetHint(SDL_HINT_VIDEO_DRIVER, "wayland,x11");
|
SDL_SetHint(SDL_HINT_VIDEO_DRIVER, "wayland,x11");
|
||||||
#endif
|
#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());
|
log_error("Failed to initialize SDL (%s). Exiting.", SDL_GetError());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -1488,7 +1488,28 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dragging_tile_change = false;
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user