diff --git a/config/game-config.txt b/config/game-config.txt index 3c72ccc..c59b899 100644 --- a/config/game-config.txt +++ b/config/game-config.txt @@ -12,6 +12,4 @@ boundaryColor 1 1 1 fruitColor 1 0 0 -headGridStartPos 3 5 - gridCount 8 \ No newline at end of file diff --git a/include/GameConfig.h b/include/GameConfig.h index 4da2069..2ea8493 100644 --- a/include/GameConfig.h +++ b/include/GameConfig.h @@ -13,10 +13,9 @@ struct GameConfig Color playerBodyColor; Color boundaryColor; Color fruitColor; - sf::Vector2u headGridStartPos; - sf::Vector2u headGridStartPosBuffer; + sf::Vector2u headGridStartPos; sf::Vector2u resolution; - unsigned int gridCount; + size_t gridCount; int gridCountBuffer; float nodeSize; }; diff --git a/scripts/Create-Solution.bat b/scripts/Create-Solution.bat index e1a205e..d584c9d 100644 --- a/scripts/Create-Solution.bat +++ b/scripts/Create-Solution.bat @@ -1,4 +1,4 @@ @ECHO OFF -ECHO Project files will be written to ./build +ECHO Project files will be written to snake/build ..\third-party\premake5\premake5.exe vs2022 PAUSE \ No newline at end of file diff --git a/src/Game.cpp b/src/Game.cpp index 6a13c0e..5c33673 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -34,8 +34,8 @@ Game::Game(bool useImgui_in) return; } - config.headGridStartPos.x = config.headGridStartPos.x % config.gridCount; - config.headGridStartPos.y = config.headGridStartPos.y % config.gridCount; + config.headGridStartPos.x = Random::get(0u, config.gridCount - 1ull); + config.headGridStartPos.y = Random::get(std::min(config.gridCount - 1ull, 3ull), config.gridCount - 1ull); gameBoundary.setFillColor(sf::Color::Transparent); gameBoundary.setOutlineColor(config.boundaryColor.sfml()); @@ -148,12 +148,6 @@ bool Game::parseConfigFile() configFile >> config.playerBodyColor.r >> config.playerBodyColor.g >> config.playerBodyColor.b; continue; } - - if (inputBuff == "headGridStartPos") - { - configFile >> config.headGridStartPos.x >> config.headGridStartPos.y; - continue; - } if (inputBuff == "gridCount") { @@ -498,15 +492,15 @@ void Game::resetGame() setNewBounds(); + config.headGridStartPos.x = Random::get(0ull, config.gridCount - 1ull); + config.headGridStartPos.y = Random::get(std::min(config.gridCount - 1ull, 3ull), config.gridCount - 1ull); + player.body.clear(); player.body.emplace_back(config.headGridStartPos, config.playerHeadColor); player.facing = Direction::up; player.inputBuffer = {}; player.score = 0; - config.headGridStartPos.x = config.headGridStartPos.x % config.gridCount; - config.headGridStartPos.y = config.headGridStartPos.y % config.gridCount; - fruit.respawn(player.body, config.gridCount); frameCount = 0; diff --git a/third-party b/third-party index 562888b..341153e 160000 --- a/third-party +++ b/third-party @@ -1 +1 @@ -Subproject commit 562888b62d709383f5ef6750c98b204104ea6003 +Subproject commit 341153ea7dea2b3f57a8ce542f0dffb9c2500de2