start pos of snake head is now random and will be away from the top of the grid
This commit is contained in:
parent
de93325371
commit
079ab886eb
|
|
@ -12,6 +12,4 @@ boundaryColor 1 1 1
|
|||
|
||||
fruitColor 1 0 0
|
||||
|
||||
headGridStartPos 3 5
|
||||
|
||||
gridCount 8
|
||||
|
|
@ -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;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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
|
||||
16
src/Game.cpp
16
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());
|
||||
|
|
@ -149,12 +149,6 @@ bool Game::parseConfigFile()
|
|||
continue;
|
||||
}
|
||||
|
||||
if (inputBuff == "headGridStartPos")
|
||||
{
|
||||
configFile >> config.headGridStartPos.x >> config.headGridStartPos.y;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (inputBuff == "gridCount")
|
||||
{
|
||||
configFile >> config.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;
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit 562888b62d709383f5ef6750c98b204104ea6003
|
||||
Subproject commit 341153ea7dea2b3f57a8ce542f0dffb9c2500de2
|
||||
Loading…
Reference in New Issue