From ec404953287e733e28f5a639e7897544dbf943ca Mon Sep 17 00:00:00 2001 From: zulianc Date: Sat, 29 Mar 2025 11:49:19 +0100 Subject: [PATCH] change volume to start timer --- .../AppMenus/GamePlayingAppMenu.cpp | 18 +++++++++----- .../AppMenus/SettingsKeybindsAppMenu.cpp | 2 +- .../AppMenus/SettingsMainAppMenu.cpp | 6 ++--- src/GraphicalUI/Settings.cpp | 24 +++++++++---------- src/GraphicalUI/Settings.h | 8 +++---- src/GraphicalUI/main.cpp | 4 ++-- 6 files changed, 34 insertions(+), 28 deletions(-) diff --git a/src/GraphicalUI/AppMenus/GamePlayingAppMenu.cpp b/src/GraphicalUI/AppMenus/GamePlayingAppMenu.cpp index f3b5aa1..d58845c 100644 --- a/src/GraphicalUI/AppMenus/GamePlayingAppMenu.cpp +++ b/src/GraphicalUI/AppMenus/GamePlayingAppMenu.cpp @@ -9,14 +9,15 @@ #include #include -static const int TIME_BEFORE_STARTING = 60; - GamePlayingAppMenu::GamePlayingAppMenu(std::shared_ptr menuStack, std::shared_ptr settings, std::shared_ptr renderWindow) : AppMenu(menuStack, settings, renderWindow), game(this->settings->getMenu().startGame(this->settings->getGamemode())) { - this->startTimer = TIME_BEFORE_STARTING; + this->startTimer = this->settings->getStartTimerLength() * FRAMES_PER_SECOND; + if (this->startTimer == 0) { + this->game.start(); + } this->paused = false; this->pausePressed = false; this->retryPressed = false; @@ -77,7 +78,10 @@ void GamePlayingAppMenu::computeFrame() { else { if (this->retryPressed) { this->game.reset(); - this->startTimer = TIME_BEFORE_STARTING; + this->startTimer = this->settings->getStartTimerLength() * FRAMES_PER_SECOND; + if (this->startTimer == 0) { + this->game.start(); + } } this->retryPressed = false; } @@ -116,6 +120,8 @@ void GamePlayingAppMenu::drawFrame() const { } } + // end coutdown + if (drawActivePiece) { // ghost piece sf::Color ghostColor = this->getColorOfBlock(this->game.getActivePiece()->getBlockType(), 100); @@ -247,6 +253,7 @@ void GamePlayingAppMenu::drawFrame() const { // game state text.setOutlineColor(sf::Color(255, 255, 255)); text.setOutlineThickness(windowSizeMultiplier / 2.f); + text.setCharacterSize(windowSizeMultiplier * 4); if (this->game.hasWon()) { this->placeTitle(text, {}, "WIN", 25.f, {}); @@ -258,8 +265,7 @@ void GamePlayingAppMenu::drawFrame() const { this->placeTitle(text, {}, "PAUSE", 25.f, {}); } else if (this->startTimer > 0) { - text.setCharacterSize(windowSizeMultiplier * 4); - this->placeTitle(text, {}, std::to_string(((this->startTimer - 1) / (TIME_BEFORE_STARTING / 4))), 25.f, {}); + this->placeTitle(text, {}, std::to_string(((this->startTimer - 1) / ((this->settings->getStartTimerLength() * FRAMES_PER_SECOND) / 4))), 25.f, {}); } this->renderWindow->display(); diff --git a/src/GraphicalUI/AppMenus/SettingsKeybindsAppMenu.cpp b/src/GraphicalUI/AppMenus/SettingsKeybindsAppMenu.cpp index df49705..545f5e5 100644 --- a/src/GraphicalUI/AppMenus/SettingsKeybindsAppMenu.cpp +++ b/src/GraphicalUI/AppMenus/SettingsKeybindsAppMenu.cpp @@ -15,7 +15,7 @@ SettingsKeybindsAppMenu::SettingsKeybindsAppMenu(std::shared_ptr menuStack, std::shared_ptr settings, std::shared_ptr renderWindow) : AppMenu(menuStack, settings, renderWindow), - playerCursor({12, 1}) { + playerCursor({1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}) { this->selectedAnAction = false; diff --git a/src/GraphicalUI/AppMenus/SettingsMainAppMenu.cpp b/src/GraphicalUI/AppMenus/SettingsMainAppMenu.cpp index 8ccb98e..41e1475 100644 --- a/src/GraphicalUI/AppMenus/SettingsMainAppMenu.cpp +++ b/src/GraphicalUI/AppMenus/SettingsMainAppMenu.cpp @@ -37,10 +37,10 @@ void SettingsMainAppMenu::computeFrame() { } case 3 : { if (this->playerCursor.movedLeft()) { - this->settings->lowerMasterVolume(); + this->settings->shortenStartTimer(); } if (this->playerCursor.movedRight()) { - this->settings->raiseMasterVolume(); + this->settings->lengthenStartTimer(); } break; } @@ -73,7 +73,7 @@ void SettingsMainAppMenu::drawFrame() const { this->placeText(text, this->playerCursor, "CHANGE KEYBINDS", 5.f, 15.f, sf::Vector2u{0, 0}); this->placeText(text, this->playerCursor, "CHANGE CONTROLS", 5.f, 25.f, sf::Vector2u{0, 1}); this->placeText(text, this->playerCursor, "< WINDOW SIZE: " + std::to_string(windowSize.x) + "x" + std::to_string(windowSize.y) + " >", 5.f, 35.f, sf::Vector2u{0, 2}); - this->placeText(text, this->playerCursor, "< VOLUME: " + std::to_string(this->settings->getMasterVolume()) + "% >", 5.f, 45.f, sf::Vector2u{0, 3}); + this->placeText(text, this->playerCursor, "< START TIMER: " + std::to_string(this->settings->getStartTimerLength()) + "s >", 5.f, 45.f, sf::Vector2u{0, 3}); this->renderWindow->display(); } diff --git a/src/GraphicalUI/Settings.cpp b/src/GraphicalUI/Settings.cpp index b0ce505..8825788 100644 --- a/src/GraphicalUI/Settings.cpp +++ b/src/GraphicalUI/Settings.cpp @@ -49,9 +49,9 @@ void Settings::loadSettingsFromFile() { settingsFile.get(byte); this->windowSizeMode = byte; - // master volume + // start timer length settingsFile.get(byte); - this->masterVolume = byte; + this->startTimerLength = byte; // gamemode settingsFile.get(byte); @@ -114,8 +114,8 @@ void Settings::saveSettingsToFile() const { byte = this->windowSizeMode; settingsFile.write(&byte, 1); - // master volume - byte = this->masterVolume; + // start timer length + byte = this->startTimerLength; settingsFile.write(&byte, 1); // gamemode @@ -188,17 +188,17 @@ void Settings::changeVideoMode(sf::RenderWindow& window) const { window.setPosition(sf::Vector2i((desktopSize.x / 2) - (windowSize.x / 2), (desktopSize.y / 2) - (windowSize.y / 2))); } -bool Settings::raiseMasterVolume() { - if (this->masterVolume < 100) { - this->masterVolume = std::min(this->masterVolume + 5, 100); +bool Settings::lengthenStartTimer() { + if (this->startTimerLength < 4) { + this->startTimerLength++; return true; } return false; } -bool Settings::lowerMasterVolume() { - if (this->masterVolume > 0) { - this->masterVolume = std::max(this->masterVolume - 5, 0); +bool Settings::shortenStartTimer() { + if (this->startTimerLength > 0) { + this->startTimerLength--; return true; } return false; @@ -260,8 +260,8 @@ int Settings::getWindowSizeMultiplier() const { return WINDOW_SIZE_MULTIPLIERS[this->windowSizeMode]; } -int Settings::getMasterVolume() const { - return this->masterVolume; +int Settings::getStartTimerLength() const { + return this->startTimerLength; } const std::vector>& Settings::getSelectedPieces() const { diff --git a/src/GraphicalUI/Settings.h b/src/GraphicalUI/Settings.h index 1d9200e..1232573 100644 --- a/src/GraphicalUI/Settings.h +++ b/src/GraphicalUI/Settings.h @@ -24,7 +24,7 @@ class Settings { std::vector keybinds; int chosenKeybinds; int windowSizeMode; - int masterVolume; + int startTimerLength; Gamemode gamemode; std::vector> selectedPieces; @@ -47,9 +47,9 @@ class Settings { void changeVideoMode(sf::RenderWindow& window) const; - bool raiseMasterVolume(); + bool lengthenStartTimer(); - bool lowerMasterVolume(); + bool shortenStartTimer(); void setGamemode(Gamemode gamemode); @@ -69,7 +69,7 @@ class Settings { int getWindowSizeMultiplier() const; - int getMasterVolume() const; + int getStartTimerLength() const; const std::vector>& getSelectedPieces() const; }; diff --git a/src/GraphicalUI/main.cpp b/src/GraphicalUI/main.cpp index 8a60631..f01b9f8 100644 --- a/src/GraphicalUI/main.cpp +++ b/src/GraphicalUI/main.cpp @@ -63,8 +63,8 @@ void resetSettingsFile() { byte = 2; settingsFile.write(&byte, 1); - // master volume - byte = 50; + // start timer length + byte = 2; settingsFile.write(&byte, 1); // gamemode