Add stats class, make a functionnal SFML game
This commit is contained in:
parent
1bebaf0f92
commit
164d94eec1
8 changed files with 127 additions and 31 deletions
|
@ -18,7 +18,7 @@ MainWindow::MainWindow(int width, int height, std::string title):
|
|||
//Set windows size
|
||||
m_windowSize=RenderWindow::getSize();
|
||||
|
||||
m_gridPosition=sf::Vector2u(50,200);
|
||||
m_gridPosition=sf::Vector2u(0,200);
|
||||
|
||||
|
||||
|
||||
|
@ -75,6 +75,11 @@ void MainWindow::drawGrid(std::vector<std::vector<int> > grid, bool gameIsOver){
|
|||
m_gridSize.x=(grid.at(0).size()*m_cellSize.x)+(grid.at(0).size()*m_spaceBetweenCell)+m_spaceBetweenCell;
|
||||
m_gridSize.y=(grid.size()*m_cellSize.y)+(grid.size()*m_spaceBetweenCell)+m_spaceBetweenCell;
|
||||
|
||||
//Center:
|
||||
m_gridPosition.x=m_windowSize.x/2-m_gridSize.x/2;
|
||||
m_gridPosition.y=220;
|
||||
|
||||
|
||||
//Draw the grid
|
||||
sf::RectangleShape gridShape(sf::Vector2f(m_gridSize.x,m_gridSize.y));
|
||||
gridShape.setFillColor(m_skin.at(2));
|
||||
|
@ -97,7 +102,6 @@ void MainWindow::drawGrid(std::vector<std::vector<int> > grid, bool gameIsOver){
|
|||
|
||||
if(gameIsOver)
|
||||
this->drawGameOver(gridX,gridY);
|
||||
this->drawATH();
|
||||
}
|
||||
|
||||
|
||||
|
@ -177,7 +181,7 @@ void MainWindow::drawGameOver(int gridX, int gridY){
|
|||
}
|
||||
|
||||
|
||||
void MainWindow::drawATH(){
|
||||
void MainWindow::drawATH(Stats stats){
|
||||
|
||||
int titleX=m_gridPosition.x;
|
||||
int titleY=m_gridPosition.y-190;
|
||||
|
@ -195,21 +199,57 @@ void MainWindow::drawATH(){
|
|||
RenderWindow::draw(text);
|
||||
|
||||
|
||||
//==================== Draw score ====================
|
||||
//==================== Draw best score ====================
|
||||
|
||||
int scoreSizeX=110;
|
||||
int scoreX=m_gridPosition.x+m_gridSize.x-scoreSizeX;
|
||||
int scoreAndBestScoreFontSize(20);
|
||||
|
||||
sf::RectangleShape scoreShape(sf::Vector2f(scoreSizeX,60));
|
||||
int bestScoreSizeX=110;
|
||||
int bestScoreSizeY=60;
|
||||
int bestScoreX=m_gridPosition.x+m_gridSize.x-bestScoreSizeX;
|
||||
int bestScoreY=titleY+25;
|
||||
|
||||
sf::RectangleShape bestScoreShape(sf::Vector2f(bestScoreSizeX,bestScoreSizeY));
|
||||
bestScoreShape.setFillColor(m_skin.at(2));
|
||||
bestScoreShape.setPosition(bestScoreX,bestScoreY);
|
||||
RenderWindow::draw(bestScoreShape);
|
||||
|
||||
text.setString("BEST");
|
||||
text.setPosition(bestScoreX+bestScoreSizeY-scoreAndBestScoreFontSize-5,bestScoreY+12);
|
||||
text.setCharacterSize(scoreAndBestScoreFontSize-5);
|
||||
text.setColor(m_skin.at(7));
|
||||
|
||||
RenderWindow::draw(text);
|
||||
|
||||
//==================== Draw score ====================
|
||||
|
||||
int scoreX=bestScoreX-bestScoreSizeX-5;
|
||||
int scoreY=bestScoreY;
|
||||
int scoreSizeX=bestScoreSizeX;
|
||||
int scoreSizeY=bestScoreSizeY;
|
||||
int scoreLength=std::to_string(stats.getScore()).size();
|
||||
|
||||
sf::RectangleShape scoreShape(sf::Vector2f(scoreSizeX,scoreSizeY));
|
||||
scoreShape.setFillColor(m_skin.at(2));
|
||||
scoreShape.setPosition(scoreX,titleY+25);
|
||||
scoreShape.setPosition(scoreX,scoreY);
|
||||
RenderWindow::draw(scoreShape);
|
||||
|
||||
//==================== Draw best score ====================
|
||||
|
||||
|
||||
sf::RectangleShape bestScoreShape(sf::Vector2f(scoreSizeX,60));
|
||||
bestScoreShape.setFillColor(m_skin.at(2));
|
||||
bestScoreShape.setPosition(scoreX-scoreSizeX-5,titleY+25);
|
||||
RenderWindow::draw(bestScoreShape);
|
||||
text.setString("SCORE");
|
||||
text.setPosition(scoreX+scoreSizeY-scoreAndBestScoreFontSize-10,scoreY+12);
|
||||
text.setCharacterSize(scoreAndBestScoreFontSize-5);
|
||||
text.setColor(m_skin.at(7));
|
||||
|
||||
RenderWindow::draw(text);
|
||||
|
||||
text.setString(std::to_string(stats.getScore()));
|
||||
text.setPosition(scoreX+scoreSizeY-((scoreLength+20)/2)-scoreAndBestScoreFontSize+10,scoreY+scoreSizeY - scoreAndBestScoreFontSize-10);
|
||||
text.setCharacterSize(scoreAndBestScoreFontSize);
|
||||
text.setColor(sf::Color::White);
|
||||
|
||||
RenderWindow::draw(text);
|
||||
}
|
||||
|
||||
void MainWindow::drawGame(std::vector<std::vector<int> > grid, bool gameIsOver, Stats stats){
|
||||
this->drawGrid(grid,gameIsOver);
|
||||
this->drawATH(stats);
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <vector>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include "../Model/Stats.hpp"
|
||||
#include <SFML/Window.hpp>
|
||||
#include <SFML/Graphics.hpp>
|
||||
|
||||
|
@ -36,5 +37,7 @@ class MainWindow : public sf::RenderWindow{
|
|||
|
||||
void drawGameOver(int gridX, int griY);
|
||||
|
||||
void drawATH();
|
||||
void drawATH(Stats stats);
|
||||
|
||||
void drawGame(std::vector<std::vector<int> > grid, bool gameIsOver, Stats stats);
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue