snake head will now always start within the boundary

This commit is contained in:
Joseph Aquino 2026-01-09 10:57:45 -05:00
parent ef0a139e70
commit 2136174547
2 changed files with 12 additions and 9 deletions

View File

@ -72,7 +72,7 @@ private:
sf::Sound moveSound;
sf::RectangleShape tempRect;
sf::RectangleShape gameBoundry;
sf::RectangleShape gameBoundary;
//sf::Sound failSound;

View File

@ -34,8 +34,11 @@ Game::Game(bool useImgui_in)
return;
}
gameBoundry.setFillColor(sf::Color::Transparent);
gameBoundry.setOutlineColor(sf::Color::White);
config.headGridStartPos.x = config.headGridStartPos.x % config.gridCount;
config.headGridStartPos.y = config.headGridStartPos.y % config.gridCount;
gameBoundary.setFillColor(sf::Color::Transparent);
gameBoundary.setOutlineColor(sf::Color::White);
setNewBounds();
player.body.reserve(config.gridCount * config.gridCount);
@ -413,15 +416,15 @@ void Game::render()
for (auto& node : player.body)
{
tempRect.setFillColor(node.color.sfml());
tempRect.setPosition(node.windowPos(gameBoundry.getPosition(), config.nodeSize));
tempRect.setPosition(node.windowPos(gameBoundary.getPosition(), config.nodeSize));
window.draw(tempRect);
}
tempRect.setFillColor(fruit.color.sfml());
tempRect.setPosition(fruit.windowPos(gameBoundry.getPosition(), config.nodeSize));
tempRect.setPosition(fruit.windowPos(gameBoundary.getPosition(), config.nodeSize));
window.draw(tempRect);
window.draw(gameBoundry);
window.draw(gameBoundary);
score.setString("Score: " + std::to_string(player.score));
@ -501,9 +504,9 @@ void Game::setNewBounds()
const float boundaryPosX = (newSize.x - boundarySize) / 2.f;
const float boundaryPosY = (newSize.y - boundarySize) / 2.f;
gameBoundry.setSize({boundarySize, boundarySize});
gameBoundry.setPosition({boundaryPosX, boundaryPosY});
gameBoundry.setOutlineThickness(boundryThickness);
gameBoundary.setSize({boundarySize, boundarySize});
gameBoundary.setPosition({boundaryPosX, boundaryPosY});
gameBoundary.setOutlineThickness(boundryThickness);
score.setPosition({10, newSize.y - 40});
}