diff --git a/.gitignore b/.gitignore index 5609314..e701c63 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ CMakeCache.txt 2P11 clear.sh *.vim +game_backup.xcf diff --git a/CMakeLists.txt b/CMakeLists.txt index a8ac529..01383c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,7 @@ # - CONSOLECONTROLLER # - SFMLCONTROLLER add_definitions(-DSFMLCONTROLLER) +add_definitions(-DLIVESKINNING) diff --git a/bin/skin/devil/game.png b/bin/skin/devil/game.png new file mode 100644 index 0000000..2c9f5c4 Binary files /dev/null and b/bin/skin/devil/game.png differ diff --git a/bin/skin/original/game.png b/bin/skin/original/game.png new file mode 100644 index 0000000..a2db074 Binary files /dev/null and b/bin/skin/original/game.png differ diff --git a/bin/skin/skinMaker/game.xcf b/bin/skin/skinMaker/game.xcf new file mode 100644 index 0000000..b67bae2 Binary files /dev/null and b/bin/skin/skinMaker/game.xcf differ diff --git a/src/Helpers/Skin.hpp b/src/Helpers/Skin.hpp index 6f01f18..4d020c8 100644 --- a/src/Helpers/Skin.hpp +++ b/src/Helpers/Skin.hpp @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -8,6 +9,7 @@ namespace skin{ std::vector loadSkin(std::string skinName); + std::vector loadShader(std::string skinName); std::vector removeComments(std::vector linesVector); diff --git a/src/Helpers/Skin/Skin.cpp b/src/Helpers/Skin/Skin.cpp index b421dae..6b36295 100644 --- a/src/Helpers/Skin/Skin.cpp +++ b/src/Helpers/Skin/Skin.cpp @@ -2,7 +2,7 @@ -std::vector skin::loadSkin(std::string skinName){ +std::vector skin::loadShader(std::string skinName){ std::vector skinLoaded; @@ -116,3 +116,52 @@ std::vector skin::extractRGBA(std::string line){ return rgba; } +std::vector skin::loadSkin(std::string skinName){ + sf::Image game; + game.loadFromFile("bin/skin/"+skinName+"/game.png"); + + std::vector skin; + + + + //Background + skin.push_back(game.getPixel(0,0)); //Background MainWindow + skin.push_back(game.getPixel(76,243)); //Background cells + skin.push_back(game.getPixel(61,227)); //Background grid color + skin.push_back(game.getPixel(326,58)); //Score bg + skin.push_back(game.getPixel(441,58)); //Best score bg + skin.push_back(sf::Color(143,122,102)); //Button bg + skin.push_back(sf::Color(238,228,218,186)); //Game over color bg + + //Font + skin.push_back(game.getPixel(65,105)); //Title font color + skin.push_back(game.getPixel(348,78)); //Score title fontcolor + skin.push_back(game.getPixel(468,77)); //Best score title font color + skin.push_back(game.getPixel(400,96)); //Score font color + skin.push_back(game.getPixel(484,97)); //Best score font color + skin.push_back(game.getPixel(128,660)); //2 and 4 font color + skin.push_back(game.getPixel(359,661)); //other number font Color + skin.push_back(sf::Color(143,122,102)); //game over font + + //Skin 2 et le 4 + skin.push_back(game.getPixel(70,597)); //2 + skin.push_back(game.getPixel(190,597)); //4 + + //Skin 8 à 64 + skin.push_back(game.getPixel(311,597)); //8 + skin.push_back(game.getPixel(431,597)); //16 + skin.push_back(game.getPixel(71,477)); //32 + skin.push_back(game.getPixel(191,477)); //64 + + //Skin 128 à 2048 + skin.push_back(game.getPixel(312,477)); //128 + skin.push_back(game.getPixel(431,477)); //256 + skin.push_back(game.getPixel(71,358)); //512 + skin.push_back(game.getPixel(191,358)); //1024 + skin.push_back(game.getPixel(311,358)); //2048 + + //Skin for other number + skin.push_back(game.getPixel(432,358)); //More than 2048 + + return skin; +} diff --git a/src/Model/Grid.cpp b/src/Model/Grid.cpp index e510bed..a14dd0a 100644 --- a/src/Model/Grid.cpp +++ b/src/Model/Grid.cpp @@ -12,6 +12,22 @@ Grid::Grid(): m_size(4), m_grid(4){ } } //m_grid.at(3).at(0)=2048; + + //m_grid.at(3).at(0)=2; + //m_grid.at(3).at(1)=4; + //m_grid.at(3).at(2)=8; + //m_grid.at(3).at(3)=16; + //m_grid.at(2).at(0)=32; + //m_grid.at(2).at(1)=64; + //m_grid.at(2).at(2)=128; + //m_grid.at(2).at(3)=256; + //m_grid.at(1).at(0)=512; + //m_grid.at(1).at(1)=1024; + //m_grid.at(1).at(2)=2048; + //m_grid.at(1).at(3)=4096; + + + } //Destructor diff --git a/src/View/MainWindow.cpp b/src/View/MainWindow.cpp index 3a61068..6152fa3 100644 --- a/src/View/MainWindow.cpp +++ b/src/View/MainWindow.cpp @@ -142,19 +142,20 @@ void MainWindow::drawCell(int x, int y, int value){ text.setCharacterSize(fontSize); text.setString(valueString); if(value==2 || value==4) - text.setColor(m_skin.at(3)); + text.setColor(m_skin.at(12)); else - text.setColor(m_skin.at(4)); + text.setColor(m_skin.at(13)); text.setPosition(fontX,fontY); if(value != 0) RenderWindow::draw(text); + } sf::Color MainWindow::getCellColor(int value){ //Id of the first cell color skin - int idStart=7; + int idStart=15; if(value==0){ return m_skin.at(1); @@ -192,7 +193,7 @@ void MainWindow::drawATH(Stats stats){ text.setFont(m_font); text.setStyle(sf::Text::Bold); text.setCharacterSize(80); - text.setColor(m_skin.at(3)); + text.setColor(m_skin.at(7)); text.setPosition(titleX,titleY); text.setString("2048"); @@ -209,14 +210,14 @@ void MainWindow::drawATH(Stats stats){ int bestScoreY=titleY+25; sf::RectangleShape bestScoreShape(sf::Vector2f(bestScoreSizeX,bestScoreSizeY)); - bestScoreShape.setFillColor(m_skin.at(2)); + bestScoreShape.setFillColor(m_skin.at(4)); 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)); + text.setColor(m_skin.at(9)); RenderWindow::draw(text); @@ -229,7 +230,7 @@ void MainWindow::drawATH(Stats stats){ int scoreLength=std::to_string(stats.getScore()).size(); sf::RectangleShape scoreShape(sf::Vector2f(scoreSizeX,scoreSizeY)); - scoreShape.setFillColor(m_skin.at(2)); + scoreShape.setFillColor(m_skin.at(3)); scoreShape.setPosition(scoreX,scoreY); RenderWindow::draw(scoreShape); @@ -237,19 +238,22 @@ void MainWindow::drawATH(Stats stats){ text.setString("SCORE"); text.setPosition(scoreX+scoreSizeY-scoreAndBestScoreFontSize-10,scoreY+12); text.setCharacterSize(scoreAndBestScoreFontSize-5); - text.setColor(m_skin.at(7)); + text.setColor(m_skin.at(8)); 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); + text.setColor(m_skin.at(10)); RenderWindow::draw(text); } void MainWindow::drawGame(std::vector > grid, bool gameIsOver, Stats stats){ +#ifdef LIVESKINNING + m_skin=skin::loadSkin(m_skinName); +#endif this->drawGrid(grid,gameIsOver); this->drawATH(stats); }