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 <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) :
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();