2 Commits

Author SHA1 Message Date
3538403f40 finalized gamemode select menu 2025-03-29 12:31:54 +01:00
ec40495328 change volume to start timer 2025-03-29 11:49:19 +01:00
14 changed files with 95 additions and 46 deletions

View File

@@ -25,7 +25,6 @@ If you want to know more details about the generation and classification of poly
- ULTRA : scores as much as possible in only 2 minutes! - ULTRA : scores as much as possible in only 2 minutes!
- MASTER : clear 200 lines at levels higher than maximum gravity! - MASTER : clear 200 lines at levels higher than maximum gravity!
- ZEN : practice indefinitely in this mode with no gravity! - ZEN : practice indefinitely in this mode with no gravity!
- ??? : still to do
## Manual build ## Manual build

View File

@@ -5,7 +5,6 @@
#include <stack> #include <stack>
#include <memory> #include <memory>
#include <vector>
#include <SFML/Graphics.hpp> #include <SFML/Graphics.hpp>

View File

@@ -0,0 +1,28 @@
#include "GamePiecesAppMenu.h"
#include "AppMenu.h"
#include "../PlayerCursor.h"
#include <stack>
#include <memory>
#include <SFML/Graphics.hpp>
GamePiecesAppMenu::GamePiecesAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow) :
AppMenu(menuStack, settings, renderWindow),
playerCursor({1}) {
}
void GamePiecesAppMenu::computeFrame() {
this->updateMetaBinds();
this->playerCursor.updatePosition();
if (this->escReleased) {
this->menuStack->pop();
}
}
void GamePiecesAppMenu::drawFrame() const {
}

View File

@@ -0,0 +1,21 @@
#pragma once
#include "AppMenu.h"
#include "../PlayerCursor.h"
#include <stack>
#include <memory>
#include <SFML/Graphics.hpp>
class GamePiecesAppMenu : public AppMenu {
private:
PlayerCursor playerCursor;
public:
GamePiecesAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow);
void computeFrame() override;
void drawFrame() const override;
};

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

@@ -1,19 +1,19 @@
#include "GameSettingsAppMenu.h" #include "GameSettingsAppMenu.h"
#include "AppMenu.h" #include "AppMenu.h"
#include "GamePiecesAppMenu.h"
#include "GameBoardAppMenu.h" #include "GameBoardAppMenu.h"
#include "GamePlayingAppMenu.h" #include "GamePlayingAppMenu.h"
#include "../PlayerCursor.h" #include "../PlayerCursor.h"
#include <stack> #include <stack>
#include <memory> #include <memory>
#include <vector>
#include <SFML/Graphics.hpp> #include <SFML/Graphics.hpp>
GameSettingsAppMenu::GameSettingsAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow) : GameSettingsAppMenu::GameSettingsAppMenu(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({2, 3, 3}) { playerCursor({2, 3, 2}) {
} }
@@ -34,7 +34,6 @@ void GameSettingsAppMenu::computeFrame() {
switch (this->playerCursor.getPosition().x) { switch (this->playerCursor.getPosition().x) {
case 0 : {this->settings->setGamemode(MASTER); break;} case 0 : {this->settings->setGamemode(MASTER); break;}
case 1 : {this->settings->setGamemode(ZEN); break;} case 1 : {this->settings->setGamemode(ZEN); break;}
case 2 : break; //TODO
} }
break; break;
} }
@@ -43,7 +42,7 @@ void GameSettingsAppMenu::computeFrame() {
if (this->enterReleased) { if (this->enterReleased) {
if (this->playerCursor.getPosition().y == 0) { if (this->playerCursor.getPosition().y == 0) {
if (this->playerCursor.getPosition().x == 0) { if (this->playerCursor.getPosition().x == 0) {
//TODO this->menuStack->push(std::make_shared<GamePiecesAppMenu>(this->menuStack, this->settings, this->renderWindow));
} }
if (this->playerCursor.getPosition().x == 1) { if (this->playerCursor.getPosition().x == 1) {
this->menuStack->push(std::make_shared<GameBoardAppMenu>(this->menuStack, this->settings, this->renderWindow)); this->menuStack->push(std::make_shared<GameBoardAppMenu>(this->menuStack, this->settings, this->renderWindow));
@@ -67,15 +66,17 @@ void GameSettingsAppMenu::drawFrame() const {
this->placeTitle(text, {}, "GAME SETTINGS", 5.f, {}); this->placeTitle(text, {}, "GAME SETTINGS", 5.f, {});
this->placeText(text, this->playerCursor, "PIECES SELECT (TODO)", 5.f, 15.f, sf::Vector2u{0, 0}); this->placeText(text, this->playerCursor, "PIECES SELECT", 5.f, 15.f, sf::Vector2u{0, 0});
this->placeText(text, this->playerCursor, "BOARD SELECT", 40.f, 15.f, sf::Vector2u{1, 0}); this->placeText(text, this->playerCursor, "BOARD SELECT", 40.f, 15.f, sf::Vector2u{1, 0});
this->placeText(text, this->playerCursor, "SPRINT", 5.f, 25.f, sf::Vector2u{0, 1}); text.setOutlineThickness(0);
this->placeText(text, this->playerCursor, "MARATHON", 25.f, 25.f, sf::Vector2u{1, 1}); this->placeTitle(text, {}, "GAMEMODE SELECT", 25.f, {});
this->placeText(text, this->playerCursor, "ULTRA", 50.f, 25.f, sf::Vector2u{2, 1});
this->placeText(text, this->playerCursor, "MASTER", 5.f, 35.f, sf::Vector2u{0, 2}); this->placeText(text, this->playerCursor, "SPRINT", 5.f, 35.f, sf::Vector2u{0, 1});
this->placeText(text, this->playerCursor, "ZEN", 25.f, 35.f, sf::Vector2u{1, 2}); this->placeText(text, this->playerCursor, "MARATHON", 25.f, 35.f, sf::Vector2u{1, 1});
this->placeText(text, this->playerCursor, "??? (TODO)", 50.f, 35.f, sf::Vector2u{2, 2}); this->placeText(text, this->playerCursor, "ULTRA", 50.f, 35.f, sf::Vector2u{2, 1});
this->placeText(text, this->playerCursor, "MASTER", 5.f, 45.f, sf::Vector2u{0, 2});
this->placeText(text, this->playerCursor, "ZEN", 25.f, 45.f, sf::Vector2u{1, 2});
this->renderWindow->display(); this->renderWindow->display();
} }

View File

@@ -5,7 +5,6 @@
#include <stack> #include <stack>
#include <memory> #include <memory>
#include <vector>
#include <SFML/Graphics.hpp> #include <SFML/Graphics.hpp>

View File

@@ -8,7 +8,6 @@
#include <stack> #include <stack>
#include <memory> #include <memory>
#include <vector>
#include <SFML/Graphics.hpp> #include <SFML/Graphics.hpp>

View File

@@ -5,7 +5,6 @@
#include <stack> #include <stack>
#include <memory> #include <memory>
#include <vector>
#include <SFML/Graphics.hpp> #include <SFML/Graphics.hpp>

View File

@@ -5,7 +5,6 @@
#include <stack> #include <stack>
#include <memory> #include <memory>
#include <vector>
#include <string> #include <string>
#include <regex> #include <regex>
#include <filesystem> #include <filesystem>
@@ -15,7 +14,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

@@ -7,7 +7,6 @@
#include <stack> #include <stack>
#include <memory> #include <memory>
#include <vector>
#include <SFML/Graphics.hpp> #include <SFML/Graphics.hpp>
@@ -37,10 +36,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 +72,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