ingame moins moche (mais pas fini)

This commit is contained in:
2025-03-24 13:28:38 +01:00
parent 38008e00bc
commit c08cfc2255
8 changed files with 146 additions and 36 deletions

View File

@@ -346,12 +346,16 @@ bool Game::isOnB2BChain() const {
return this->B2BChain;
}
bool Game::areBlocksBones() const {
return this->parameters.getBoneBlocks();
float Game::getLockDelayProgression() const {
return (float) this->totalLockDelay / this->parameters.getLockDelay();
}
Position Game::ghostPiecePosition() const {
return this->board.lowestPosition();
float Game::getForcedLockDelayProgression() const {
return (float) this->totalForcedLockDelay / this->parameters.getForcedLockDelay();
}
bool Game::areBlocksBones() const {
return this->parameters.getBoneBlocks();
}
const Board& Game::getBoard() const {
@@ -366,6 +370,10 @@ const Position& Game::getActivePiecePosition() const {
return this->board.getActivePiecePosition();
}
Position Game::getGhostPiecePosition() const {
return this->board.lowestPosition();
}
const std::shared_ptr<Piece>& Game::getHeldPiece() const {
return this->board.getHeldPiece();
}

View File

@@ -116,16 +116,21 @@ class Game {
*/
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
*/
bool areBlocksBones() const;
/**
* @return The position of the ghost piece
*/
Position ghostPiecePosition() const;
/**
* @return The board
*/
@@ -141,6 +146,11 @@ class Game {
*/
const Position& getActivePiecePosition() const;
/**
* @return The position of the ghost piece
*/
Position getGhostPiecePosition() const;
/**
* @return A pointer to the held piece, can be null
*/

View File

@@ -4,16 +4,28 @@
#include <stack>
#include <memory>
#include <algorithm>
#include <cmath>
#include <SFML/Graphics.hpp>
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()))
{
game(this->settings->getMenu().startGame(this->settings->getGamemode())) {
this->game.start();
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() {
@@ -33,12 +45,25 @@ void GamePlayingAppMenu::computeFrame() {
}
if (actions.contains(RETRY)) {
this->retryPressed = true;
}
else {
if (this->retryPressed) {
this->game.reset();
this->game.start();
}
this->retryPressed = false;
}
if (actions.contains(PAUSE)) {
this->pausePressed = true;
}
else {
if (this->pausePressed) {
this->paused = (!this->paused);
}
this->pausePressed = false;
}
if (!paused) {
this->game.nextFrame(actions);
@@ -47,24 +72,58 @@ void GamePlayingAppMenu::computeFrame() {
}
void GamePlayingAppMenu::drawFrame() const {
this->renderWindow->clear(sf::Color::Black);
this->renderWindow->clear(sf::Color(200, 200, 200));
int sizeMultiplier = this->settings->getWindowSizeMultiplier();
sf::Vector2f cellSize((float) sizeMultiplier, (float) sizeMultiplier);
float cellSizeMultiplier = this->settings->getWindowSizeMultiplier() * this->cellSizeZoom;
sf::Vector2f cellSize(cellSizeMultiplier, cellSizeMultiplier);
for (int y = this->game.getBoard().getBaseHeight() + 10; 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});
Block block = this->game.getBoard().getBlock(Position{x, y});
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.setPosition(sf::Vector2f(x * sizeMultiplier, (this->game.getBoard().getBaseHeight() + 10 - y) * sizeMultiplier));
cell.setFillColor(this->getColorOfBlock(block, (block == NOTHING) ? 0 : -50));
cell.setPosition(this->getBlockPosition(x, y));
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) {
for (int y = 10; y >= 0; y--) {
for (int x = 0; x <= 10; x++) {
@@ -98,6 +157,20 @@ void GamePlayingAppMenu::drawFrame() const {
}
}
}
*/
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));
}

View File

@@ -11,11 +11,19 @@ class GamePlayingAppMenu : public AppMenu {
private:
Game game;
bool paused;
bool pausePressed;
bool retryPressed;
float cellSizeZoom;
sf::Rect<float> boardPosition;
public:
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;
};

View File

@@ -15,9 +15,9 @@ class GameSettingsAppMenu : public AppMenu {
public:
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;
};

View File

@@ -15,7 +15,7 @@ class MainAppMenu : public AppMenu {
public:
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;
};

View File

@@ -4,6 +4,19 @@
#include <fstream>
#ifdef __JMINOS_RELEASE__
int main() {
std::srand(std::time(NULL));
GraphApp UI;
UI.run();
return 0;
}
#else
void resetConfigFiles();
void resetSettingsFile();
void resetKeybindFile(int layout);
@@ -12,8 +25,6 @@ void resetKeybindFile(int layout);
int main() {
std::srand(std::time(NULL));
#ifndef __JMINOS_RELEASE__
PiecesFiles pf;
for (int i = 1; i <= MAXIMUM_PIECES_SIZE; i++) {
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();
#endif
GraphApp UI;
UI.run();
@@ -154,3 +163,5 @@ void resetKeybindFile(int layout) {
layoutFile.write(&byte, 1);
}
}
#endif

View File

@@ -251,7 +251,7 @@ void TextApp::printGame(const Game& game) const {
for (int x = 0; x < game.getBoard().getWidth(); x++) {
/* BOARD PRINTING */
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});
if (isActivePieceHere || isGhostPieceHere) {