change volume to start timer

This commit is contained in:
2025-03-29 11:49:19 +01:00
parent e0de2b5f90
commit ec40495328
6 changed files with 34 additions and 28 deletions

View File

@@ -9,14 +9,15 @@
#include <string> #include <string>
#include <SFML/Graphics.hpp> #include <SFML/Graphics.hpp>
static const int TIME_BEFORE_STARTING = 60;
GamePlayingAppMenu::GamePlayingAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow) : GamePlayingAppMenu::GamePlayingAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow) :
AppMenu(menuStack, settings, renderWindow), AppMenu(menuStack, settings, renderWindow),
game(this->settings->getMenu().startGame(this->settings->getGamemode())) { 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->paused = false;
this->pausePressed = false; this->pausePressed = false;
this->retryPressed = false; this->retryPressed = false;
@@ -77,7 +78,10 @@ void GamePlayingAppMenu::computeFrame() {
else { else {
if (this->retryPressed) { if (this->retryPressed) {
this->game.reset(); 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; this->retryPressed = false;
} }
@@ -116,6 +120,8 @@ void GamePlayingAppMenu::drawFrame() const {
} }
} }
// end coutdown
if (drawActivePiece) { if (drawActivePiece) {
// ghost piece // ghost piece
sf::Color ghostColor = this->getColorOfBlock(this->game.getActivePiece()->getBlockType(), 100); sf::Color ghostColor = this->getColorOfBlock(this->game.getActivePiece()->getBlockType(), 100);
@@ -247,6 +253,7 @@ void GamePlayingAppMenu::drawFrame() const {
// game state // game state
text.setOutlineColor(sf::Color(255, 255, 255)); text.setOutlineColor(sf::Color(255, 255, 255));
text.setOutlineThickness(windowSizeMultiplier / 2.f); text.setOutlineThickness(windowSizeMultiplier / 2.f);
text.setCharacterSize(windowSizeMultiplier * 4);
if (this->game.hasWon()) { if (this->game.hasWon()) {
this->placeTitle(text, {}, "WIN", 25.f, {}); this->placeTitle(text, {}, "WIN", 25.f, {});
@@ -258,8 +265,7 @@ void GamePlayingAppMenu::drawFrame() const {
this->placeTitle(text, {}, "PAUSE", 25.f, {}); this->placeTitle(text, {}, "PAUSE", 25.f, {});
} }
else if (this->startTimer > 0) { else if (this->startTimer > 0) {
text.setCharacterSize(windowSizeMultiplier * 4); this->placeTitle(text, {}, std::to_string(((this->startTimer - 1) / ((this->settings->getStartTimerLength() * FRAMES_PER_SECOND) / 4))), 25.f, {});
this->placeTitle(text, {}, std::to_string(((this->startTimer - 1) / (TIME_BEFORE_STARTING / 4))), 25.f, {});
} }
this->renderWindow->display(); this->renderWindow->display();

View File

@@ -15,7 +15,7 @@
SettingsKeybindsAppMenu::SettingsKeybindsAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow) : SettingsKeybindsAppMenu::SettingsKeybindsAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow) :
AppMenu(menuStack, settings, renderWindow), AppMenu(menuStack, settings, renderWindow),
playerCursor({12, 1}) { playerCursor({1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}) {
this->selectedAnAction = false; this->selectedAnAction = false;

View File

@@ -37,10 +37,10 @@ void SettingsMainAppMenu::computeFrame() {
} }
case 3 : { case 3 : {
if (this->playerCursor.movedLeft()) { if (this->playerCursor.movedLeft()) {
this->settings->lowerMasterVolume(); this->settings->shortenStartTimer();
} }
if (this->playerCursor.movedRight()) { if (this->playerCursor.movedRight()) {
this->settings->raiseMasterVolume(); this->settings->lengthenStartTimer();
} }
break; 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 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, "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, "< 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(); this->renderWindow->display();
} }

View File

@@ -49,9 +49,9 @@ void Settings::loadSettingsFromFile() {
settingsFile.get(byte); settingsFile.get(byte);
this->windowSizeMode = byte; this->windowSizeMode = byte;
// master volume // start timer length
settingsFile.get(byte); settingsFile.get(byte);
this->masterVolume = byte; this->startTimerLength = byte;
// gamemode // gamemode
settingsFile.get(byte); settingsFile.get(byte);
@@ -114,8 +114,8 @@ void Settings::saveSettingsToFile() const {
byte = this->windowSizeMode; byte = this->windowSizeMode;
settingsFile.write(&byte, 1); settingsFile.write(&byte, 1);
// master volume // start timer length
byte = this->masterVolume; byte = this->startTimerLength;
settingsFile.write(&byte, 1); settingsFile.write(&byte, 1);
// gamemode // 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))); window.setPosition(sf::Vector2i((desktopSize.x / 2) - (windowSize.x / 2), (desktopSize.y / 2) - (windowSize.y / 2)));
} }
bool Settings::raiseMasterVolume() { bool Settings::lengthenStartTimer() {
if (this->masterVolume < 100) { if (this->startTimerLength < 4) {
this->masterVolume = std::min(this->masterVolume + 5, 100); this->startTimerLength++;
return true; return true;
} }
return false; return false;
} }
bool Settings::lowerMasterVolume() { bool Settings::shortenStartTimer() {
if (this->masterVolume > 0) { if (this->startTimerLength > 0) {
this->masterVolume = std::max(this->masterVolume - 5, 0); this->startTimerLength--;
return true; return true;
} }
return false; return false;
@@ -260,8 +260,8 @@ int Settings::getWindowSizeMultiplier() const {
return WINDOW_SIZE_MULTIPLIERS[this->windowSizeMode]; return WINDOW_SIZE_MULTIPLIERS[this->windowSizeMode];
} }
int Settings::getMasterVolume() const { int Settings::getStartTimerLength() const {
return this->masterVolume; return this->startTimerLength;
} }
const std::vector<std::pair<PiecesType, int>>& Settings::getSelectedPieces() const { const std::vector<std::pair<PiecesType, int>>& Settings::getSelectedPieces() const {

View File

@@ -24,7 +24,7 @@ class Settings {
std::vector<Keybinds> keybinds; std::vector<Keybinds> keybinds;
int chosenKeybinds; int chosenKeybinds;
int windowSizeMode; int windowSizeMode;
int masterVolume; int startTimerLength;
Gamemode gamemode; Gamemode gamemode;
std::vector<std::pair<PiecesType, int>> selectedPieces; std::vector<std::pair<PiecesType, int>> selectedPieces;
@@ -47,9 +47,9 @@ class Settings {
void changeVideoMode(sf::RenderWindow& window) const; void changeVideoMode(sf::RenderWindow& window) const;
bool raiseMasterVolume(); bool lengthenStartTimer();
bool lowerMasterVolume(); bool shortenStartTimer();
void setGamemode(Gamemode gamemode); void setGamemode(Gamemode gamemode);
@@ -69,7 +69,7 @@ class Settings {
int getWindowSizeMultiplier() const; int getWindowSizeMultiplier() const;
int getMasterVolume() const; int getStartTimerLength() const;
const std::vector<std::pair<PiecesType, int>>& getSelectedPieces() const; const std::vector<std::pair<PiecesType, int>>& getSelectedPieces() const;
}; };

View File

@@ -63,8 +63,8 @@ void resetSettingsFile() {
byte = 2; byte = 2;
settingsFile.write(&byte, 1); settingsFile.write(&byte, 1);
// master volume // start timer length
byte = 50; byte = 2;
settingsFile.write(&byte, 1); settingsFile.write(&byte, 1);
// gamemode // gamemode