ingame moins moche (mais pas fini)
This commit is contained in:
@@ -346,12 +346,16 @@ bool Game::isOnB2BChain() const {
|
|||||||
return this->B2BChain;
|
return this->B2BChain;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Game::areBlocksBones() const {
|
float Game::getLockDelayProgression() const {
|
||||||
return this->parameters.getBoneBlocks();
|
return (float) this->totalLockDelay / this->parameters.getLockDelay();
|
||||||
}
|
}
|
||||||
|
|
||||||
Position Game::ghostPiecePosition() const {
|
float Game::getForcedLockDelayProgression() const {
|
||||||
return this->board.lowestPosition();
|
return (float) this->totalForcedLockDelay / this->parameters.getForcedLockDelay();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Game::areBlocksBones() const {
|
||||||
|
return this->parameters.getBoneBlocks();
|
||||||
}
|
}
|
||||||
|
|
||||||
const Board& Game::getBoard() const {
|
const Board& Game::getBoard() const {
|
||||||
@@ -366,6 +370,10 @@ const Position& Game::getActivePiecePosition() const {
|
|||||||
return this->board.getActivePiecePosition();
|
return this->board.getActivePiecePosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Position Game::getGhostPiecePosition() const {
|
||||||
|
return this->board.lowestPosition();
|
||||||
|
}
|
||||||
|
|
||||||
const std::shared_ptr<Piece>& Game::getHeldPiece() const {
|
const std::shared_ptr<Piece>& Game::getHeldPiece() const {
|
||||||
return this->board.getHeldPiece();
|
return this->board.getHeldPiece();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,16 +116,21 @@ class Game {
|
|||||||
*/
|
*/
|
||||||
bool isOnB2BChain() const;
|
bool isOnB2BChain() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return How close the active piece's lock delay is to the maximum allowed, betwwen 0 and 1
|
||||||
|
*/
|
||||||
|
float getLockDelayProgression() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return How close the active piece's forced lock delay is to the maximum allowed, betwwen 0 and 1
|
||||||
|
*/
|
||||||
|
float getForcedLockDelayProgression() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return If all blocks are currently bone blocks
|
* @return If all blocks are currently bone blocks
|
||||||
*/
|
*/
|
||||||
bool areBlocksBones() const;
|
bool areBlocksBones() const;
|
||||||
|
|
||||||
/**
|
|
||||||
* @return The position of the ghost piece
|
|
||||||
*/
|
|
||||||
Position ghostPiecePosition() const;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The board
|
* @return The board
|
||||||
*/
|
*/
|
||||||
@@ -141,6 +146,11 @@ class Game {
|
|||||||
*/
|
*/
|
||||||
const Position& getActivePiecePosition() const;
|
const Position& getActivePiecePosition() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The position of the ghost piece
|
||||||
|
*/
|
||||||
|
Position getGhostPiecePosition() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return A pointer to the held piece, can be null
|
* @return A pointer to the held piece, can be null
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -4,16 +4,28 @@
|
|||||||
|
|
||||||
#include <stack>
|
#include <stack>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cmath>
|
||||||
#include <SFML/Graphics.hpp>
|
#include <SFML/Graphics.hpp>
|
||||||
|
|
||||||
|
|
||||||
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->game.start();
|
this->game.start();
|
||||||
this->paused = false;
|
this->paused = false;
|
||||||
|
this->pausePressed = false;
|
||||||
|
this->retryPressed = false;
|
||||||
|
|
||||||
|
int maxWidthMultiplier = 40 / (this->game.getBoard().getWidth());
|
||||||
|
int maxHeightMultiplier = 50 / (this->game.getBoard().getBaseHeight() + 10);
|
||||||
|
this->cellSizeZoom = std::min(maxWidthMultiplier, maxHeightMultiplier);
|
||||||
|
|
||||||
|
float boardWidth = this->game.getBoard().getWidth() * this->cellSizeZoom;
|
||||||
|
float boardHeight = (this->game.getBoard().getBaseHeight() + 10) * this->cellSizeZoom;
|
||||||
|
this->boardPosition = sf::Rect<float>(sf::Vector2f(40.f - (boardWidth / 2), 25.f - (boardHeight / 2)) * (float) this->settings->getWindowSizeMultiplier(),
|
||||||
|
sf::Vector2f(boardWidth, boardHeight));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GamePlayingAppMenu::computeFrame() {
|
void GamePlayingAppMenu::computeFrame() {
|
||||||
@@ -33,12 +45,25 @@ void GamePlayingAppMenu::computeFrame() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (actions.contains(RETRY)) {
|
if (actions.contains(RETRY)) {
|
||||||
|
this->retryPressed = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (this->retryPressed) {
|
||||||
this->game.reset();
|
this->game.reset();
|
||||||
this->game.start();
|
this->game.start();
|
||||||
}
|
}
|
||||||
|
this->retryPressed = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (actions.contains(PAUSE)) {
|
if (actions.contains(PAUSE)) {
|
||||||
|
this->pausePressed = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (this->pausePressed) {
|
||||||
this->paused = (!this->paused);
|
this->paused = (!this->paused);
|
||||||
}
|
}
|
||||||
|
this->pausePressed = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (!paused) {
|
if (!paused) {
|
||||||
this->game.nextFrame(actions);
|
this->game.nextFrame(actions);
|
||||||
@@ -47,24 +72,58 @@ void GamePlayingAppMenu::computeFrame() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GamePlayingAppMenu::drawFrame() const {
|
void GamePlayingAppMenu::drawFrame() const {
|
||||||
this->renderWindow->clear(sf::Color::Black);
|
this->renderWindow->clear(sf::Color(200, 200, 200));
|
||||||
|
|
||||||
int sizeMultiplier = this->settings->getWindowSizeMultiplier();
|
float cellSizeMultiplier = this->settings->getWindowSizeMultiplier() * this->cellSizeZoom;
|
||||||
sf::Vector2f cellSize((float) sizeMultiplier, (float) sizeMultiplier);
|
sf::Vector2f cellSize(cellSizeMultiplier, cellSizeMultiplier);
|
||||||
|
|
||||||
for (int y = this->game.getBoard().getBaseHeight() + 10; y >= 0; y--) {
|
for (int y = this->game.getBoard().getBaseHeight() + 10; y >= 0; y--) {
|
||||||
for (int x = 0; x < this->game.getBoard().getWidth(); x++) {
|
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()));
|
Block block = this->game.getBoard().getBlock(Position{x, y});
|
||||||
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(cellSize);
|
sf::RectangleShape cell(cellSize);
|
||||||
cell.setFillColor(sf::Color(BLOCKS_COLOR[block].red, BLOCKS_COLOR[block].green, BLOCKS_COLOR[block].blue, (isGhostPieceHere && !isActivePieceHere) ? 150 : 255));
|
cell.setFillColor(this->getColorOfBlock(block, (block == NOTHING) ? 0 : -50));
|
||||||
cell.setPosition(sf::Vector2f(x * sizeMultiplier, (this->game.getBoard().getBaseHeight() + 10 - y) * sizeMultiplier));
|
cell.setPosition(this->getBlockPosition(x, y));
|
||||||
this->renderWindow->draw(cell);
|
this->renderWindow->draw(cell);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this->game.getActivePiece() != nullptr) {
|
||||||
|
sf::Color ghostColor = this->getColorOfBlock(this->game.getActivePiece()->getBlockType(), 100);
|
||||||
|
float pieceOutlineSize = std::roundf(cellSizeMultiplier / 4);
|
||||||
|
sf::Color pieceOultlineColor = sf::Color(255, 255 - (255 * this->game.getForcedLockDelayProgression()), 255 - (255 * this->game.getForcedLockDelayProgression()));
|
||||||
|
sf::Color pieceColor = this->getColorOfBlock(this->game.getActivePiece()->getBlockType(), -200 * (this->game.getLockDelayProgression()));
|
||||||
|
|
||||||
|
for (const Position& position : this->game.getActivePiece()->getPositions()) {
|
||||||
|
Position cellPosition = (this->game.getGhostPiecePosition() + position);
|
||||||
|
|
||||||
|
sf::RectangleShape cell(cellSize);
|
||||||
|
cell.setFillColor(ghostColor);
|
||||||
|
cell.setPosition(this->getBlockPosition(cellPosition.x, cellPosition.y));
|
||||||
|
this->renderWindow->draw(cell);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const Position& position : this->game.getActivePiece()->getPositions()) {
|
||||||
|
Position cellPosition = (this->game.getActivePiecePosition() + position);
|
||||||
|
|
||||||
|
sf::RectangleShape cell(cellSize);
|
||||||
|
cell.setOutlineThickness(pieceOutlineSize);
|
||||||
|
cell.setOutlineColor(pieceOultlineColor);
|
||||||
|
cell.setPosition(this->getBlockPosition(cellPosition.x, cellPosition.y));
|
||||||
|
this->renderWindow->draw(cell);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const Position& position : this->game.getActivePiece()->getPositions()) {
|
||||||
|
Position cellPosition = (this->game.getActivePiecePosition() + position);
|
||||||
|
|
||||||
|
sf::RectangleShape cell(cellSize);
|
||||||
|
cell.setFillColor(pieceColor);
|
||||||
|
cell.setPosition(this->getBlockPosition(cellPosition.x, cellPosition.y));
|
||||||
|
this->renderWindow->draw(cell);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
if (this->game.getNextPieces().size() > 0) {
|
if (this->game.getNextPieces().size() > 0) {
|
||||||
for (int y = 10; y >= 0; y--) {
|
for (int y = 10; y >= 0; y--) {
|
||||||
for (int x = 0; x <= 10; x++) {
|
for (int x = 0; x <= 10; x++) {
|
||||||
@@ -98,6 +157,20 @@ void GamePlayingAppMenu::drawFrame() const {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
this->renderWindow->display();
|
this->renderWindow->display();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sf::Color GamePlayingAppMenu::getColorOfBlock(Block block, int luminosityShift) const {
|
||||||
|
Color rgbColor = BLOCKS_COLOR[block];
|
||||||
|
return sf::Color(std::clamp(rgbColor.red + luminosityShift, 0, 255),
|
||||||
|
std::clamp(rgbColor.green + luminosityShift, 0, 255),
|
||||||
|
std::clamp(rgbColor.blue + luminosityShift, 0, 255));
|
||||||
|
}
|
||||||
|
|
||||||
|
sf::Vector2f GamePlayingAppMenu::getBlockPosition(int x, int y) const {
|
||||||
|
float cellSizeMultiplier = this->settings->getWindowSizeMultiplier() * this->cellSizeZoom;
|
||||||
|
return sf::Vector2f(this->boardPosition.position.x + (x * cellSizeMultiplier),
|
||||||
|
this->boardPosition.position.y + ((this->game.getBoard().getBaseHeight() + 10 - y) * cellSizeMultiplier));
|
||||||
|
}
|
||||||
|
|||||||
@@ -11,11 +11,19 @@ class GamePlayingAppMenu : public AppMenu {
|
|||||||
private:
|
private:
|
||||||
Game game;
|
Game game;
|
||||||
bool paused;
|
bool paused;
|
||||||
|
bool pausePressed;
|
||||||
|
bool retryPressed;
|
||||||
|
float cellSizeZoom;
|
||||||
|
sf::Rect<float> boardPosition;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GamePlayingAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow);
|
GamePlayingAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow);
|
||||||
|
|
||||||
void computeFrame();
|
void computeFrame() override;
|
||||||
|
|
||||||
void drawFrame() const;
|
void drawFrame() const override;
|
||||||
|
|
||||||
|
sf::Color getColorOfBlock(Block block, int luminosityShift) const;
|
||||||
|
|
||||||
|
sf::Vector2f getBlockPosition(int x, int y) const;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -15,9 +15,9 @@ class GameSettingsAppMenu : public AppMenu {
|
|||||||
public:
|
public:
|
||||||
GameSettingsAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow);
|
GameSettingsAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow);
|
||||||
|
|
||||||
void computeFrame();
|
void computeFrame() override;
|
||||||
|
|
||||||
void drawFrame() const;
|
void drawFrame() const override;
|
||||||
|
|
||||||
void placeText(sf::Text& text, const sf::String& string, float xPos, float yPos, unsigned int xCursorOutline, unsigned int yCursorOutline) const ;
|
void placeText(sf::Text& text, const sf::String& string, float xPos, float yPos, unsigned int xCursorOutline, unsigned int yCursorOutline) const;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ class MainAppMenu : public AppMenu {
|
|||||||
public:
|
public:
|
||||||
MainAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow);
|
MainAppMenu(std::shared_ptr<MenuStack> menuStack, std::shared_ptr<Settings> settings, std::shared_ptr<sf::RenderWindow> renderWindow);
|
||||||
|
|
||||||
void computeFrame();
|
void computeFrame() override;
|
||||||
|
|
||||||
void drawFrame() const;
|
void drawFrame() const override;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,6 +4,19 @@
|
|||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __JMINOS_RELEASE__
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::srand(std::time(NULL));
|
||||||
|
|
||||||
|
GraphApp UI;
|
||||||
|
UI.run();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
void resetConfigFiles();
|
void resetConfigFiles();
|
||||||
void resetSettingsFile();
|
void resetSettingsFile();
|
||||||
void resetKeybindFile(int layout);
|
void resetKeybindFile(int layout);
|
||||||
@@ -12,8 +25,6 @@ void resetKeybindFile(int layout);
|
|||||||
int main() {
|
int main() {
|
||||||
std::srand(std::time(NULL));
|
std::srand(std::time(NULL));
|
||||||
|
|
||||||
#ifndef __JMINOS_RELEASE__
|
|
||||||
|
|
||||||
PiecesFiles pf;
|
PiecesFiles pf;
|
||||||
for (int i = 1; i <= MAXIMUM_PIECES_SIZE; i++) {
|
for (int i = 1; i <= MAXIMUM_PIECES_SIZE; i++) {
|
||||||
if (!std::filesystem::exists("data/pieces/" + std::to_string(i) + "minos.bin")) {
|
if (!std::filesystem::exists("data/pieces/" + std::to_string(i) + "minos.bin")) {
|
||||||
@@ -30,11 +41,9 @@ int main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// uncomment before compiling release version
|
// do this before compiling release version
|
||||||
//resetConfigFiles();
|
//resetConfigFiles();
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
GraphApp UI;
|
GraphApp UI;
|
||||||
UI.run();
|
UI.run();
|
||||||
|
|
||||||
@@ -154,3 +163,5 @@ void resetKeybindFile(int layout) {
|
|||||||
layoutFile.write(&byte, 1);
|
layoutFile.write(&byte, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -251,7 +251,7 @@ void TextApp::printGame(const Game& game) const {
|
|||||||
for (int x = 0; x < game.getBoard().getWidth(); x++) {
|
for (int x = 0; x < game.getBoard().getWidth(); x++) {
|
||||||
/* BOARD PRINTING */
|
/* BOARD PRINTING */
|
||||||
bool isActivePieceHere = (game.getActivePiece() != nullptr) && (game.getActivePiece()->getPositions().contains(Position{x, y} - game.getActivePiecePosition()));
|
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()));
|
bool isGhostPieceHere = (game.getActivePiece() != nullptr) && (game.getActivePiece()->getPositions().contains(Position{x, y} - game.getGhostPiecePosition()));
|
||||||
Block block = (isActivePieceHere || isGhostPieceHere) ? game.getActivePiece()->getBlockType() : game.getBoard().getBlock(Position{x, y});
|
Block block = (isActivePieceHere || isGhostPieceHere) ? game.getActivePiece()->getBlockType() : game.getBoard().getBlock(Position{x, y});
|
||||||
|
|
||||||
if (isActivePieceHere || isGhostPieceHere) {
|
if (isActivePieceHere || isGhostPieceHere) {
|
||||||
|
|||||||
Reference in New Issue
Block a user