snake head will now always start within the boundary
This commit is contained in:
parent
ef0a139e70
commit
2136174547
|
|
@ -72,7 +72,7 @@ private:
|
||||||
sf::Sound moveSound;
|
sf::Sound moveSound;
|
||||||
|
|
||||||
sf::RectangleShape tempRect;
|
sf::RectangleShape tempRect;
|
||||||
sf::RectangleShape gameBoundry;
|
sf::RectangleShape gameBoundary;
|
||||||
|
|
||||||
//sf::Sound failSound;
|
//sf::Sound failSound;
|
||||||
|
|
||||||
|
|
|
||||||
19
src/Game.cpp
19
src/Game.cpp
|
|
@ -34,8 +34,11 @@ Game::Game(bool useImgui_in)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
gameBoundry.setFillColor(sf::Color::Transparent);
|
config.headGridStartPos.x = config.headGridStartPos.x % config.gridCount;
|
||||||
gameBoundry.setOutlineColor(sf::Color::White);
|
config.headGridStartPos.y = config.headGridStartPos.y % config.gridCount;
|
||||||
|
|
||||||
|
gameBoundary.setFillColor(sf::Color::Transparent);
|
||||||
|
gameBoundary.setOutlineColor(sf::Color::White);
|
||||||
setNewBounds();
|
setNewBounds();
|
||||||
|
|
||||||
player.body.reserve(config.gridCount * config.gridCount);
|
player.body.reserve(config.gridCount * config.gridCount);
|
||||||
|
|
@ -413,15 +416,15 @@ void Game::render()
|
||||||
for (auto& node : player.body)
|
for (auto& node : player.body)
|
||||||
{
|
{
|
||||||
tempRect.setFillColor(node.color.sfml());
|
tempRect.setFillColor(node.color.sfml());
|
||||||
tempRect.setPosition(node.windowPos(gameBoundry.getPosition(), config.nodeSize));
|
tempRect.setPosition(node.windowPos(gameBoundary.getPosition(), config.nodeSize));
|
||||||
window.draw(tempRect);
|
window.draw(tempRect);
|
||||||
}
|
}
|
||||||
|
|
||||||
tempRect.setFillColor(fruit.color.sfml());
|
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(tempRect);
|
||||||
|
|
||||||
window.draw(gameBoundry);
|
window.draw(gameBoundary);
|
||||||
|
|
||||||
score.setString("Score: " + std::to_string(player.score));
|
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 boundaryPosX = (newSize.x - boundarySize) / 2.f;
|
||||||
const float boundaryPosY = (newSize.y - boundarySize) / 2.f;
|
const float boundaryPosY = (newSize.y - boundarySize) / 2.f;
|
||||||
|
|
||||||
gameBoundry.setSize({boundarySize, boundarySize});
|
gameBoundary.setSize({boundarySize, boundarySize});
|
||||||
gameBoundry.setPosition({boundaryPosX, boundaryPosY});
|
gameBoundary.setPosition({boundaryPosX, boundaryPosY});
|
||||||
gameBoundry.setOutlineThickness(boundryThickness);
|
gameBoundary.setOutlineThickness(boundryThickness);
|
||||||
|
|
||||||
score.setPosition({10, newSize.y - 40});
|
score.setPosition({10, newSize.y - 40});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue