From 2581f03c00f5a14f49081d82eb8e1a31c31aae88 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Sat, 13 Mar 2021 09:38:05 -0500 Subject: Player can move cursor on pause menu #7 --- res/sfx/vertical_menu.wav | Bin 0 -> 31152 bytes src/input_system.cpp | 8 ++++++++ src/menu_system.cpp | 20 ++++++++++++++++++++ src/menu_system.h | 4 ++++ 4 files changed, 32 insertions(+) create mode 100644 res/sfx/vertical_menu.wav diff --git a/res/sfx/vertical_menu.wav b/res/sfx/vertical_menu.wav new file mode 100644 index 0000000..9890c15 Binary files /dev/null and b/res/sfx/vertical_menu.wav differ diff --git a/src/input_system.cpp b/src/input_system.cpp index fd7889d..0c68c49 100644 --- a/src/input_system.cpp +++ b/src/input_system.cpp @@ -126,6 +126,14 @@ void InputSystem::tick(double dt) { if (game_.getSystem().isChoiceActive()) { game_.getSystem().selectSecondChoice(); } + } else if (e.key.keysym.sym == SDLK_UP) { + if (game_.getSystem().isMenuOpen()) { + game_.getSystem().pressedUp(); + } + } else if (e.key.keysym.sym == SDLK_DOWN) { + if (game_.getSystem().isMenuOpen()) { + game_.getSystem().pressedDown(); + } } } else if (e.type == SDL_KEYUP && (e.key.keysym.sym == SDLK_LSHIFT || e.key.keysym.sym == SDLK_RSHIFT)) { if (game_.isGameplayPaused()) continue; diff --git a/src/menu_system.cpp b/src/menu_system.cpp index acbfd76..d3a310e 100644 --- a/src/menu_system.cpp +++ b/src/menu_system.cpp @@ -49,3 +49,23 @@ void MenuSystem::closePauseMenu() { pauseAnimation_.start(125, 0.0); openState_ = OpenState::Animating; } + +void MenuSystem::pressedUp() { + if (cursor_ > 0) { + cursor_--; + cursorBob_ = 0; + cursorBobDown_ = true; + + game_.getMixer().playSound("../res/sfx/vertical_menu.wav"); + } +} + +void MenuSystem::pressedDown() { + if (cursor_ < menu_.size() - 1) { + cursor_++; + cursorBob_ = 0; + cursorBobDown_ = true; + + game_.getMixer().playSound("../res/sfx/vertical_menu.wav"); + } +} diff --git a/src/menu_system.h b/src/menu_system.h index 9cbd1f0..fa373cb 100644 --- a/src/menu_system.h +++ b/src/menu_system.h @@ -24,6 +24,10 @@ public: void closePauseMenu(); + void pressedUp(); + + void pressedDown(); + // Info double getPauseAnimationProgress() const { return pauseAnimation_.getProgress(); } -- cgit 1.4.1