taille board adaptative
This commit is contained in:
@@ -18,13 +18,14 @@ GamePlayingAppMenu::GamePlayingAppMenu(std::shared_ptr<MenuStack> menuStack, std
|
|||||||
this->pausePressed = false;
|
this->pausePressed = false;
|
||||||
this->retryPressed = false;
|
this->retryPressed = false;
|
||||||
|
|
||||||
int maxWidthMultiplier = 40 / (this->game.getBoard().getWidth());
|
int maxWidthMultiplier = (this->settings->getWindowSizeMultiplier() * 40) / (this->game.getBoard().getWidth());
|
||||||
int maxHeightMultiplier = 50 / (this->game.getBoard().getBaseHeight() + 10);
|
int maxHeightMultiplier = (this->settings->getWindowSizeMultiplier() * 50) / (this->game.getBoard().getBaseHeight() + 10);
|
||||||
this->cellSizeZoom = std::min(maxWidthMultiplier, maxHeightMultiplier);
|
this->cellSizeZoom = std::min(maxWidthMultiplier, maxHeightMultiplier);
|
||||||
|
|
||||||
float boardWidth = this->game.getBoard().getWidth() * this->cellSizeZoom;
|
float boardWidth = this->game.getBoard().getWidth() * this->cellSizeZoom;
|
||||||
float boardHeight = (this->game.getBoard().getBaseHeight() + 10) * 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(),
|
this->boardPosition = sf::Rect<float>(sf::Vector2f((this->settings->getWindowSizeMultiplier() * 40) - (boardWidth / 2),
|
||||||
|
(this->settings->getWindowSizeMultiplier() * 25) - (boardHeight / 2)),
|
||||||
sf::Vector2f(boardWidth, boardHeight));
|
sf::Vector2f(boardWidth, boardHeight));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,26 +75,24 @@ void GamePlayingAppMenu::computeFrame() {
|
|||||||
void GamePlayingAppMenu::drawFrame() const {
|
void GamePlayingAppMenu::drawFrame() const {
|
||||||
this->renderWindow->clear(sf::Color(200, 200, 200));
|
this->renderWindow->clear(sf::Color(200, 200, 200));
|
||||||
|
|
||||||
float cellSizeMultiplier = this->settings->getWindowSizeMultiplier() * this->cellSizeZoom;
|
sf::Vector2f cellSize(this->cellSizeZoom, this->cellSizeZoom);
|
||||||
sf::Vector2f cellSize(cellSizeMultiplier, cellSizeMultiplier);
|
bool drawActivePiece = (this->game.getActivePiece() != nullptr) && (!this->game.hasLost());
|
||||||
|
|
||||||
for (int y = this->game.getBoard().getBaseHeight() + 10; y >= 0; y--) {
|
// board
|
||||||
|
for (int y = this->game.getBoard().getBaseHeight() + 9; y >= 0; y--) {
|
||||||
for (int x = 0; x < this->game.getBoard().getWidth(); x++) {
|
for (int x = 0; x < this->game.getBoard().getWidth(); x++) {
|
||||||
Block block = this->game.getBoard().getBlock(Position{x, y});
|
Block block = this->game.getBoard().getBlock(Position{x, y});
|
||||||
|
|
||||||
sf::RectangleShape cell(cellSize);
|
sf::RectangleShape cell(cellSize);
|
||||||
cell.setFillColor(this->getColorOfBlock(block, (block == NOTHING) ? 0 : -50));
|
cell.setFillColor(this->getColorOfBlock(block, (block == NOTHING) ? 0 : -30));
|
||||||
cell.setPosition(this->getBlockPosition(x, y));
|
cell.setPosition(this->getBlockPosition(x, y));
|
||||||
this->renderWindow->draw(cell);
|
this->renderWindow->draw(cell);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->game.getActivePiece() != nullptr) {
|
if (drawActivePiece) {
|
||||||
|
// ghost piece
|
||||||
sf::Color ghostColor = this->getColorOfBlock(this->game.getActivePiece()->getBlockType(), 100);
|
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()) {
|
for (const Position& position : this->game.getActivePiece()->getPositions()) {
|
||||||
Position cellPosition = (this->game.getGhostPiecePosition() + position);
|
Position cellPosition = (this->game.getGhostPiecePosition() + position);
|
||||||
|
|
||||||
@@ -103,6 +102,9 @@ void GamePlayingAppMenu::drawFrame() const {
|
|||||||
this->renderWindow->draw(cell);
|
this->renderWindow->draw(cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// active piece outline
|
||||||
|
float pieceOutlineSize = std::roundf(this->cellSizeZoom / 4);
|
||||||
|
sf::Color pieceOultlineColor = sf::Color(255, 255 - (255 * this->game.getForcedLockDelayProgression()), 255 - (255 * this->game.getForcedLockDelayProgression()));
|
||||||
for (const Position& position : this->game.getActivePiece()->getPositions()) {
|
for (const Position& position : this->game.getActivePiece()->getPositions()) {
|
||||||
Position cellPosition = (this->game.getActivePiecePosition() + position);
|
Position cellPosition = (this->game.getActivePiecePosition() + position);
|
||||||
|
|
||||||
@@ -112,6 +114,17 @@ void GamePlayingAppMenu::drawFrame() const {
|
|||||||
cell.setPosition(this->getBlockPosition(cellPosition.x, cellPosition.y));
|
cell.setPosition(this->getBlockPosition(cellPosition.x, cellPosition.y));
|
||||||
this->renderWindow->draw(cell);
|
this->renderWindow->draw(cell);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// top out line
|
||||||
|
sf::RectangleShape topOutLine(sf::Vector2f(this->cellSizeZoom * this->game.getBoard().getWidth(), std::roundf(this->cellSizeZoom / 4)));
|
||||||
|
topOutLine.setPosition(this->getBlockPosition(0, this->game.getBoard().getBaseHeight() - 1));
|
||||||
|
topOutLine.setFillColor(sf::Color(255, 0, 0));
|
||||||
|
this->renderWindow->draw(topOutLine);
|
||||||
|
|
||||||
|
if (drawActivePiece) {
|
||||||
|
// active piece
|
||||||
|
sf::Color pieceColor = this->getColorOfBlock(this->game.getActivePiece()->getBlockType(), -200 * (this->game.getLockDelayProgression()));
|
||||||
|
|
||||||
for (const Position& position : this->game.getActivePiece()->getPositions()) {
|
for (const Position& position : this->game.getActivePiece()->getPositions()) {
|
||||||
Position cellPosition = (this->game.getActivePiecePosition() + position);
|
Position cellPosition = (this->game.getActivePiecePosition() + position);
|
||||||
@@ -170,7 +183,6 @@ sf::Color GamePlayingAppMenu::getColorOfBlock(Block block, int luminosityShift)
|
|||||||
}
|
}
|
||||||
|
|
||||||
sf::Vector2f GamePlayingAppMenu::getBlockPosition(int x, int y) const {
|
sf::Vector2f GamePlayingAppMenu::getBlockPosition(int x, int y) const {
|
||||||
float cellSizeMultiplier = this->settings->getWindowSizeMultiplier() * this->cellSizeZoom;
|
return sf::Vector2f(this->boardPosition.position.x + (x * this->cellSizeZoom),
|
||||||
return sf::Vector2f(this->boardPosition.position.x + (x * cellSizeMultiplier),
|
this->boardPosition.position.y + ((this->game.getBoard().getBaseHeight() + 9 - y) * this->cellSizeZoom));
|
||||||
this->boardPosition.position.y + ((this->game.getBoard().getBaseHeight() + 10 - y) * cellSizeMultiplier));
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user