trop de trucs oscours
This commit is contained in:
@@ -7,7 +7,6 @@ We will only talk about pieces and not polyominoes. In this project, pieces are
|
||||
|
||||
Each frame, the UI will translate the user's input into a series of action to apply to the game. The list of action is the following:
|
||||
|
||||
- Quit the game
|
||||
- Pause
|
||||
- Retry
|
||||
- Hold
|
||||
|
||||
@@ -4,10 +4,9 @@
|
||||
|
||||
|
||||
/**
|
||||
* The list of actions that can be taken by the player
|
||||
* The list of in-game actions that can be taken by the player
|
||||
*/
|
||||
enum Action {
|
||||
QUIT,
|
||||
PAUSE,
|
||||
RETRY,
|
||||
HOLD,
|
||||
@@ -22,8 +21,20 @@ enum Action {
|
||||
};
|
||||
|
||||
|
||||
static const std::string ACTION_NAMES[] = { // name for each action
|
||||
"Quit",
|
||||
static const Action ACTION_LIST_IN_ORDER[] = { // the list of possible actions in a sorted order
|
||||
MOVE_LEFT,
|
||||
MOVE_RIGHT,
|
||||
SOFT_DROP,
|
||||
HARD_DROP,
|
||||
ROTATE_CW,
|
||||
ROTATE_CCW,
|
||||
ROTATE_180,
|
||||
ROTATE_0,
|
||||
HOLD,
|
||||
PAUSE,
|
||||
RETRY
|
||||
};
|
||||
static const std::string ACTION_NAMES[] = { // name representation for each actions
|
||||
"Pause",
|
||||
"Retry",
|
||||
"Hold",
|
||||
|
||||
96
src/GraphicalUI/AppMenus/InGameAppMenu.cpp
Normal file
96
src/GraphicalUI/AppMenus/InGameAppMenu.cpp
Normal file
@@ -0,0 +1,96 @@
|
||||
#include "InGameAppMenu.h"
|
||||
|
||||
#include "AppMenu.h"
|
||||
|
||||
#include <stack>
|
||||
#include <memory>
|
||||
#include <SFML/Graphics.hpp>
|
||||
|
||||
|
||||
InGameAppMenu::InGameAppMenu(std::shared_ptr<std::stack<AppMenu>> 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->paused = false;
|
||||
}
|
||||
|
||||
void InGameAppMenu::computeFrame() {
|
||||
std::set<Action> actions;
|
||||
for (Action action : ACTION_LIST_IN_ORDER) {
|
||||
for (sfKey key : this->settings->getKeybinds().getKeybinds(action)) {
|
||||
if (sf::Keyboard::isKeyPressed(key)) {
|
||||
actions.insert(action);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (actions.contains(RETRY)) {
|
||||
this->game.reset();
|
||||
this->game.start();
|
||||
}
|
||||
if (actions.contains(PAUSE)) {
|
||||
this->paused = (!this->paused);
|
||||
}
|
||||
|
||||
if (!paused) {
|
||||
this->game.nextFrame(actions);
|
||||
}
|
||||
|
||||
if (sf::Keyboard::isKeyPressed(sfKey::Escape)) {
|
||||
this->menuStack->pop();
|
||||
}
|
||||
}
|
||||
|
||||
void InGameAppMenu::drawFrame() const {
|
||||
this->renderWindow->clear(sf::Color::Black);
|
||||
|
||||
for (int y = this->game.getBoard().getBaseHeight() + 5; y >= 0; y--) {
|
||||
for (int x = 0; x < this->game.getBoard().getWidth(); x++) {
|
||||
bool isActivePieceHere = (this->game.getActivePiece() != nullptr) && (this->game.getActivePiece()->getPositions().contains(Position{x, y} - this->game.getActivePiecePosition()));
|
||||
bool isGhostPieceHere = (this->game.getActivePiece() != nullptr) && (this->game.getActivePiece()->getPositions().contains(Position{x, y} - this->game.ghostPiecePosition()));
|
||||
Block block = (isActivePieceHere || isGhostPieceHere) ? this->game.getActivePiece()->getBlockType() : this->game.getBoard().getBlock(Position{x, y});
|
||||
|
||||
sf::RectangleShape cell(sf::Vector2f(20.f, 20.f));
|
||||
cell.setFillColor(sf::Color(BLOCKS_COLOR[block].red, BLOCKS_COLOR[block].green, BLOCKS_COLOR[block].blue, (isGhostPieceHere && !isActivePieceHere) ? 150 : 255));
|
||||
cell.setPosition(sf::Vector2f(x*20, (this->game.getBoard().getBaseHeight() + 10 - y)*20));
|
||||
this->renderWindow->draw(cell);
|
||||
}
|
||||
}
|
||||
|
||||
if (this->game.getNextPieces().size() > 0) {
|
||||
for (int y = 10; y >= 0; y--) {
|
||||
for (int x = 0; x <= 10; x++) {
|
||||
Block block = this->game.getNextPieces().at(0).getBlockType();
|
||||
sf::RectangleShape cell(sf::Vector2f(20.f, 20.f));
|
||||
cell.setPosition(sf::Vector2f((x + 2 + this->game.getBoard().getWidth())*20, (this->game.getBoard().getBaseHeight() - y)*20));
|
||||
if (this->game.getNextPieces().at(0).getPositions().contains(Position({x, y}))) {
|
||||
cell.setFillColor(sf::Color(BLOCKS_COLOR[block].red, BLOCKS_COLOR[block].green, BLOCKS_COLOR[block].blue));
|
||||
}
|
||||
else {
|
||||
cell.setFillColor(sf::Color(0, 0, 0));
|
||||
}
|
||||
this->renderWindow->draw(cell);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this->game.getHeldPiece() != nullptr) {
|
||||
for (int y = 10; y >= 0; y--) {
|
||||
for (int x = 0; x <= 10; x++) {
|
||||
Block block = this->game.getHeldPiece()->getBlockType();
|
||||
sf::RectangleShape cell(sf::Vector2f(20.f, 20.f));
|
||||
cell.setPosition(sf::Vector2f((x + 12 + this->game.getBoard().getWidth())*20, (this->game.getBoard().getBaseHeight() - y)*20));
|
||||
if (this->game.getHeldPiece()->getPositions().contains(Position({x, y}))) {
|
||||
cell.setFillColor(sf::Color(BLOCKS_COLOR[block].red, BLOCKS_COLOR[block].green, BLOCKS_COLOR[block].blue));
|
||||
}
|
||||
else {
|
||||
cell.setFillColor(sf::Color(0, 0, 0));
|
||||
}
|
||||
this->renderWindow->draw(cell);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this->renderWindow->display();
|
||||
}
|
||||
21
src/GraphicalUI/AppMenus/InGameAppMenu.h
Normal file
21
src/GraphicalUI/AppMenus/InGameAppMenu.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
#include "AppMenu.h"
|
||||
|
||||
#include <stack>
|
||||
#include <memory>
|
||||
#include <SFML/Graphics.hpp>
|
||||
|
||||
|
||||
class InGameAppMenu : public AppMenu {
|
||||
private:
|
||||
Game game;
|
||||
bool paused;
|
||||
|
||||
public:
|
||||
InGameAppMenu(std::shared_ptr<std::stack<AppMenu>> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow);
|
||||
|
||||
void computeFrame();
|
||||
|
||||
void drawFrame() const;
|
||||
};
|
||||
@@ -13,9 +13,16 @@ MainAppMenu::MainAppMenu(std::shared_ptr<std::stack<AppMenu>> menuStack, std::sh
|
||||
}
|
||||
|
||||
void MainAppMenu::computeFrame() {
|
||||
if (sf::Keyboard::isKeyPressed(sfKey::Enter)) {
|
||||
|
||||
}
|
||||
else if (sf::Keyboard::isKeyPressed(sfKey::Escape)) {
|
||||
this->menuStack->pop();
|
||||
}
|
||||
}
|
||||
|
||||
void MainAppMenu::drawFrame() const {
|
||||
this->renderWindow->clear(sf::Color::Black);
|
||||
|
||||
this->renderWindow->display();
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ GraphApp::GraphApp() {
|
||||
this->window = std::make_shared<sf::RenderWindow>();
|
||||
}
|
||||
|
||||
void GraphApp::startApp() {
|
||||
void GraphApp::run() {
|
||||
changeVideoMode(*this->window, this->settings->getVideoMode());
|
||||
this->menuStack->push(MainAppMenu(this->menuStack, this->settings, this->window));
|
||||
|
||||
|
||||
@@ -17,5 +17,5 @@ class GraphApp {
|
||||
public:
|
||||
GraphApp();
|
||||
|
||||
void startApp();
|
||||
void run();
|
||||
};
|
||||
|
||||
@@ -20,8 +20,6 @@ class Keybinds {
|
||||
|
||||
void saveKeybindsToFile() const;
|
||||
|
||||
void resetCustomLayoutFile() const;
|
||||
|
||||
void addKey(Action action, sfKey key);
|
||||
|
||||
void clearKeys(Action action);
|
||||
|
||||
@@ -21,17 +21,14 @@ Settings::Settings() {
|
||||
}
|
||||
|
||||
void Settings::loadSettingsFromFile() {
|
||||
//TODO
|
||||
this->menu.getPiecesList().unselectAll();
|
||||
this->menu.getPiecesList().selectAllPieces(4);
|
||||
this->windowSizeMode = 2;
|
||||
}
|
||||
|
||||
void Settings::saveSettingsToFile() const {
|
||||
|
||||
}
|
||||
|
||||
void Settings::resetSettingsFile() const {
|
||||
|
||||
//TODO
|
||||
}
|
||||
|
||||
bool Settings::selectNextKeybinds() {
|
||||
@@ -122,7 +119,7 @@ int Settings::getWindowSizeMultiplier() const {
|
||||
return WINDOW_SIZE_MULTIPLIERS[this->windowSizeMode];
|
||||
}
|
||||
|
||||
const sf::VideoMode& Settings::getVideoMode() const {
|
||||
const sf::VideoMode Settings::getVideoMode() const {
|
||||
return sf::VideoMode(BASE_WINDOW_SIZE * (unsigned int) WINDOW_SIZE_MULTIPLIERS[this->windowSizeMode]);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,8 +24,6 @@ class Settings {
|
||||
|
||||
void saveSettingsToFile() const;
|
||||
|
||||
void resetSettingsFile() const;
|
||||
|
||||
bool selectNextKeybinds();
|
||||
|
||||
bool selectPreviousKeybinds();
|
||||
@@ -52,7 +50,7 @@ class Settings {
|
||||
|
||||
int getWindowSizeMultiplier() const;
|
||||
|
||||
const sf::VideoMode& getVideoMode() const;
|
||||
const sf::VideoMode getVideoMode() const;
|
||||
|
||||
const std::vector<std::pair<PiecesType, int>>& getSelectedPieces() const;
|
||||
};
|
||||
|
||||
@@ -1,138 +1,116 @@
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include "../Core/Menu.h"
|
||||
#include "GraphApp.h"
|
||||
#include "../Pieces/PiecesFiles.h"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
void setToDefaultConfig();
|
||||
|
||||
int main() {
|
||||
std::srand(std::time(NULL));
|
||||
|
||||
sf::RenderWindow window(sf::VideoMode({800, 640}), "My window", sf::Style::Titlebar | sf::Style::Close);
|
||||
window.setPosition(sf::Vector2i(sf::VideoMode::getDesktopMode().size.x / 2 - 400, sf::VideoMode::getDesktopMode().size.y / 2 - 320));
|
||||
|
||||
// dev version
|
||||
PiecesFiles pf;
|
||||
for (int i = 1; i <= 10; i++) {
|
||||
for (int i = 1; i <= MAXIMUM_PIECES_SIZE; i++) {
|
||||
if (!std::filesystem::exists("data/pieces/" + std::to_string(i) + "minos.bin")) {
|
||||
std::cout << "pieces files for size " << i << " not found, generating..." << std::endl;
|
||||
pf.savePieces(i);
|
||||
}
|
||||
|
||||
Menu m;
|
||||
m.getPiecesList().loadPieces(10);
|
||||
m.getPiecesList().selectAllPieces(4);
|
||||
m.setBoardWidth(10);
|
||||
m.getPlayerControls().setDAS(6);
|
||||
m.getPlayerControls().setARR(0);
|
||||
m.getPlayerControls().setSDR(0);
|
||||
Game game = m.startGame(SPRINT);
|
||||
game.start();
|
||||
|
||||
sf::Clock clock;
|
||||
|
||||
sf::Font font;
|
||||
if (!font.openFromFile("data/fonts/arial.ttf")) {
|
||||
std::cout << "aaaaaaaaaaaaaa";
|
||||
}
|
||||
sf::Text text(font);
|
||||
text.setCharacterSize(20);
|
||||
text.setFillColor(sf::Color::White);
|
||||
|
||||
while (window.isOpen()) {
|
||||
while (const std::optional event = window.pollEvent()) {
|
||||
if (event->is<sf::Event::Closed>())
|
||||
window.close();
|
||||
if (!std::filesystem::exists("data/config/settings.bin")) {
|
||||
resetSettingsFile();
|
||||
}
|
||||
|
||||
if (clock.getElapsedTime().asMilliseconds() > 16) {
|
||||
clock.restart();
|
||||
|
||||
window.clear(sf::Color::Black);
|
||||
|
||||
std::set<Action> actions;
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Left)) {
|
||||
actions.insert(MOVE_LEFT);
|
||||
}
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Right)) {
|
||||
actions.insert(MOVE_RIGHT);
|
||||
}
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Up)) {
|
||||
actions.insert(HARD_DROP);
|
||||
}
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Down)) {
|
||||
actions.insert(SOFT_DROP);
|
||||
}
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::A)) {
|
||||
actions.insert(ROTATE_CCW);
|
||||
}
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::E)) {
|
||||
actions.insert(ROTATE_CW);
|
||||
}
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Z)) {
|
||||
actions.insert(HOLD);
|
||||
}
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Tab)) {
|
||||
actions.insert(ROTATE_0);
|
||||
}
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::Num2)) {
|
||||
actions.insert(ROTATE_180);
|
||||
}
|
||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Key::R)) {
|
||||
game.reset();
|
||||
game.start();
|
||||
}
|
||||
game.nextFrame(actions);
|
||||
|
||||
for (int y = game.getBoard().getBaseHeight() + 5; y >= 0; y--) {
|
||||
for (int x = 0; x < game.getBoard().getWidth(); x++) {
|
||||
bool isActivePieceHere = (game.getActivePiece() != nullptr) && (game.getActivePiece()->getPositions().contains(Position{x, y} - game.getActivePiecePosition()));
|
||||
bool isGhostPieceHere = (game.getActivePiece() != nullptr) && (game.getActivePiece()->getPositions().contains(Position{x, y} - game.ghostPiecePosition()));
|
||||
Block block = (isActivePieceHere || isGhostPieceHere) ? game.getActivePiece()->getBlockType() : game.getBoard().getBlock(Position{x, y});
|
||||
|
||||
sf::RectangleShape cell(sf::Vector2f(20.f, 20.f));
|
||||
cell.setFillColor(sf::Color(BLOCKS_COLOR[block].red, BLOCKS_COLOR[block].green, BLOCKS_COLOR[block].blue, (isGhostPieceHere && !isActivePieceHere) ? 150 : 255));
|
||||
cell.setPosition(sf::Vector2f(x*20, (game.getBoard().getBaseHeight() + 10 - y)*20));
|
||||
window.draw(cell);
|
||||
for (int i = 0; i < 5; i++) {
|
||||
if (!std::filesystem::exists("data/config/keybinds/layout" + std::to_string(i) + ".bin")) {
|
||||
resetKeybindFile(i);
|
||||
}
|
||||
}
|
||||
|
||||
if (game.getNextPieces().size() > 0) {
|
||||
for (int y = 10; y >= 0; y--) {
|
||||
for (int x = 0; x <= 10; x++) {
|
||||
Block block = game.getNextPieces().at(0).getBlockType();
|
||||
sf::RectangleShape cell(sf::Vector2f(20.f, 20.f));
|
||||
cell.setPosition(sf::Vector2f((x + 2 + game.getBoard().getWidth())*20, (game.getBoard().getBaseHeight() - y)*20));
|
||||
if (game.getNextPieces().at(0).getPositions().contains(Position({x, y}))) {
|
||||
cell.setFillColor(sf::Color(BLOCKS_COLOR[block].red, BLOCKS_COLOR[block].green, BLOCKS_COLOR[block].blue));
|
||||
}
|
||||
else {
|
||||
cell.setFillColor(sf::Color(0, 0, 0));
|
||||
}
|
||||
window.draw(cell);
|
||||
}
|
||||
}
|
||||
}
|
||||
// release version
|
||||
//resetConfigFiles();
|
||||
|
||||
if (game.getHeldPiece() != nullptr) {
|
||||
for (int y = 10; y >= 0; y--) {
|
||||
for (int x = 0; x <= 10; x++) {
|
||||
Block block = game.getHeldPiece()->getBlockType();
|
||||
sf::RectangleShape cell(sf::Vector2f(20.f, 20.f));
|
||||
cell.setPosition(sf::Vector2f((x + 12 + game.getBoard().getWidth())*20, (game.getBoard().getBaseHeight() - y)*20));
|
||||
if (game.getHeldPiece()->getPositions().contains(Position({x, y}))) {
|
||||
cell.setFillColor(sf::Color(BLOCKS_COLOR[block].red, BLOCKS_COLOR[block].green, BLOCKS_COLOR[block].blue));
|
||||
}
|
||||
else {
|
||||
cell.setFillColor(sf::Color(0, 0, 0));
|
||||
}
|
||||
window.draw(cell);
|
||||
}
|
||||
}
|
||||
}
|
||||
GraphApp UI;
|
||||
UI.run();
|
||||
|
||||
text.setPosition(sf::Vector2f(12*20, (game.getBoard().getBaseHeight() - 5)*20));
|
||||
text.setString(sf::String(std::to_string(game.getClearedLines())));
|
||||
window.draw(text);
|
||||
return 0;
|
||||
}
|
||||
|
||||
window.display();
|
||||
}
|
||||
|
||||
void resetConfigFiles() {
|
||||
resetSettingsFile;
|
||||
for (int i = 0; i < 5; i++) {
|
||||
resetKeybindFile(i);
|
||||
}
|
||||
}
|
||||
|
||||
void resetSettingsFile() {
|
||||
|
||||
}
|
||||
|
||||
void resetKeybindFile(int layout) {
|
||||
if (layout < 0 || layout > 4) return;
|
||||
|
||||
std::ofstream layoutFile("data/config/keybinds/layout" + std::to_string(layout) + ".bin", std::ios::trunc | std::ios::binary);
|
||||
std::map<Action, sfKey> keybinds;
|
||||
|
||||
if (layout != 4) {
|
||||
keybinds.insert({PAUSE, sfKey::P});
|
||||
keybinds.insert({RETRY, sfKey::R});
|
||||
}
|
||||
|
||||
if (layout == 0) {
|
||||
keybinds.insert({MOVE_LEFT, sfKey::Left});
|
||||
keybinds.insert({MOVE_RIGHT, sfKey::Right});
|
||||
keybinds.insert({SOFT_DROP, sfKey::Down});
|
||||
keybinds.insert({HARD_DROP, sfKey::Space});
|
||||
keybinds.insert({ROTATE_CW, sfKey::Up});
|
||||
keybinds.insert({ROTATE_CCW, sfKey::Z});
|
||||
keybinds.insert({ROTATE_180, sfKey::X});
|
||||
keybinds.insert({ROTATE_0, sfKey::LShift});
|
||||
keybinds.insert({HOLD, sfKey::C});
|
||||
}
|
||||
if (layout == 1) {
|
||||
keybinds.insert({MOVE_LEFT, sfKey::Z});
|
||||
keybinds.insert({MOVE_RIGHT, sfKey::C});
|
||||
keybinds.insert({SOFT_DROP, sfKey::X});
|
||||
keybinds.insert({HARD_DROP, sfKey::S});
|
||||
keybinds.insert({ROTATE_CW, sfKey::M});
|
||||
keybinds.insert({ROTATE_CCW, sfKey::Comma});
|
||||
keybinds.insert({ROTATE_180, sfKey::J});
|
||||
keybinds.insert({ROTATE_0, sfKey::K});
|
||||
keybinds.insert({HOLD, sfKey::LShift});
|
||||
}
|
||||
if (layout == 2) {
|
||||
keybinds.insert({MOVE_LEFT, sfKey::A});
|
||||
keybinds.insert({MOVE_RIGHT, sfKey::D});
|
||||
keybinds.insert({SOFT_DROP, sfKey::W});
|
||||
keybinds.insert({HARD_DROP, sfKey::S});
|
||||
keybinds.insert({ROTATE_CW, sfKey::Left});
|
||||
keybinds.insert({ROTATE_CCW, sfKey::Right});
|
||||
keybinds.insert({ROTATE_180, sfKey::Up});
|
||||
keybinds.insert({ROTATE_0, sfKey::Down});
|
||||
keybinds.insert({HOLD, sfKey::RShift});
|
||||
}
|
||||
if (layout == 3) {
|
||||
keybinds.insert({MOVE_LEFT, sfKey::Left});
|
||||
keybinds.insert({MOVE_RIGHT, sfKey::Right});
|
||||
keybinds.insert({SOFT_DROP, sfKey::Down});
|
||||
keybinds.insert({HARD_DROP, sfKey::Up});
|
||||
keybinds.insert({ROTATE_CW, sfKey::E});
|
||||
keybinds.insert({ROTATE_CCW, sfKey::A});
|
||||
keybinds.insert({ROTATE_180, sfKey::Num2});
|
||||
keybinds.insert({ROTATE_0, sfKey::Tab});
|
||||
keybinds.insert({HOLD, sfKey::Z});
|
||||
}
|
||||
|
||||
char contentChar;
|
||||
for (Action action : ACTION_LIST_IN_ORDER) {
|
||||
contentChar = action;
|
||||
layoutFile.write(&contentChar, 1);
|
||||
|
||||
if (keybinds.contains(action)) {
|
||||
contentChar = (int) keybinds.at(action);
|
||||
layoutFile.write(&contentChar, 1);
|
||||
}
|
||||
|
||||
contentChar = 0xFF;
|
||||
layoutFile.write(&contentChar, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,7 +136,6 @@ void TextApp::seeKeybinds() const {
|
||||
|
||||
void TextApp::defaultKeybinds() {
|
||||
this->keybinds.clear();
|
||||
this->keybinds.insert({"quit", QUIT});
|
||||
this->keybinds.insert({"pause", PAUSE});
|
||||
this->keybinds.insert({"retry", RETRY});
|
||||
this->keybinds.insert({"h", HOLD});
|
||||
@@ -171,15 +170,21 @@ void TextApp::startGame() const {
|
||||
|
||||
std::set<Action> playerActions;
|
||||
std::set<Action> lastFrameActions;
|
||||
std::set<Action> metaActions;
|
||||
bool retrying = false;
|
||||
for (std::string action : actions) {
|
||||
try {
|
||||
Action playerAction = this->keybinds.at(action);
|
||||
if (playerAction == PAUSE || playerAction == RETRY || playerAction == quit) {
|
||||
metaActions.insert(playerAction);
|
||||
if (action == "quit") {
|
||||
quit = true;
|
||||
}
|
||||
else {
|
||||
if (playerAction == SOFT_DROP || playerAction == MOVE_LEFT || playerAction == MOVE_RIGHT) {
|
||||
try {
|
||||
Action playerAction = this->keybinds.at(action);
|
||||
if (playerAction == RETRY) {
|
||||
retrying = true;
|
||||
}
|
||||
else if (playerAction == PAUSE) {
|
||||
paused = (!paused);
|
||||
}
|
||||
else if (playerAction == SOFT_DROP || playerAction == MOVE_LEFT || playerAction == MOVE_RIGHT) {
|
||||
playerActions.insert(playerAction);
|
||||
lastFrameActions.insert(playerAction);
|
||||
}
|
||||
@@ -190,19 +195,12 @@ void TextApp::startGame() const {
|
||||
playerActions.insert(playerAction);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (std::exception ignored) {}
|
||||
}
|
||||
|
||||
if (metaActions.contains(PAUSE)) {
|
||||
paused = (!paused);
|
||||
}
|
||||
|
||||
if (!paused) {
|
||||
if (metaActions.contains(QUIT)) {
|
||||
quit = true;
|
||||
}
|
||||
else if (metaActions.contains(RETRY)) {
|
||||
if (!paused && !quit) {
|
||||
if (retrying) {
|
||||
game.reset();
|
||||
game.start();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user