From 71dfa043a99549a1c1679668799ff0fbca74c98e Mon Sep 17 00:00:00 2001 From: Trimutex Date: Fri, 18 Aug 2023 22:36:47 -0500 Subject: [PATCH] Fixed snake not showing on start --- src/gamestate.cpp | 2 ++ src/playerinterface.cpp | 11 ++++------- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/gamestate.cpp b/src/gamestate.cpp index 8394f78..67941f4 100755 --- a/src/gamestate.cpp +++ b/src/gamestate.cpp @@ -1,6 +1,7 @@ // GameState.cpp #include #include +#include #include "common.hpp" #include "playerinterface.hpp" #include "gamestate.hpp" @@ -58,6 +59,7 @@ namespace snakeplusplus void GameEngine::PlaceNewSnakePart(sf::Vector2f location) { + if (!player.speed.x && !player.speed.y) { return; } try { char* locationState; diff --git a/src/playerinterface.cpp b/src/playerinterface.cpp index 2978179..d63706c 100755 --- a/src/playerinterface.cpp +++ b/src/playerinterface.cpp @@ -74,25 +74,22 @@ namespace snakeplusplus void PlayerOutput::DisplayGameState(std::vector< std::vector >& gameBoard) { CheckWindowEvents(); - sf::Vector2f location; char* letterOnBoard; for (float y = 0; y < gameBoundaries.y; y++) { for (float x = 0; x < gameBoundaries.x; x++) { - location.x = x; - location.y = y; - letterOnBoard = &gameBoard.at(location.y).at(location.x); + letterOnBoard = &gameBoard.at(y).at(x); switch (*letterOnBoard) { case 'O': - DrawSnake(location); + DrawSnake(sf::Vector2f(x, y)); break; case 'X': - DrawFood(location); + DrawFood(sf::Vector2f(x,y)); break; default: - DrawEmpty(location); + DrawEmpty(sf::Vector2f(x,y)); break; } }