From 21361745474a9f198f850504242e5706af585e3a Mon Sep 17 00:00:00 2001 From: Joseph Aquino Date: Fri, 9 Jan 2026 10:57:45 -0500 Subject: [PATCH] snake head will now always start within the boundary --- include/Game.h | 2 +- src/Game.cpp | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/include/Game.h b/include/Game.h index c7f4be3..a3b9040 100644 --- a/include/Game.h +++ b/include/Game.h @@ -72,7 +72,7 @@ private: sf::Sound moveSound; sf::RectangleShape tempRect; - sf::RectangleShape gameBoundry; + sf::RectangleShape gameBoundary; //sf::Sound failSound; diff --git a/src/Game.cpp b/src/Game.cpp index 661b688..6dc6e09 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -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}); }