Snake now randomly starts as well
This commit is contained in:
parent
d7982b200f
commit
49182ce07d
@ -96,14 +96,20 @@ namespace snakeplusplus
|
|||||||
gameBoard.clear();
|
gameBoard.clear();
|
||||||
sf::Vector2f boardDimensions = GetGameBoundaries();
|
sf::Vector2f boardDimensions = GetGameBoundaries();
|
||||||
gameBoard.resize(boardDimensions.y, std::vector<char> (boardDimensions.x, ' '));
|
gameBoard.resize(boardDimensions.y, std::vector<char> (boardDimensions.x, ' '));
|
||||||
player.headLocation.x = 4;
|
// Snake setup
|
||||||
player.headLocation.y = 5;
|
{
|
||||||
|
player.headLocation.x = GenerateRandomNumber(boardDimensions.x);
|
||||||
|
player.headLocation.y = GenerateRandomNumber(boardDimensions.y);
|
||||||
char* locationState = &gameBoard.at(player.headLocation.y).at(player.headLocation.x);
|
char* locationState = &gameBoard.at(player.headLocation.y).at(player.headLocation.x);
|
||||||
player.body.push(locationState);
|
player.body.push(locationState);
|
||||||
*player.body.front() = 'O';
|
*locationState = 'O';
|
||||||
playerFood.GenerateNewFood(GetGameBoundaries());
|
}
|
||||||
|
// Food setup
|
||||||
|
{
|
||||||
|
playerFood.GenerateNewFood(boardDimensions);
|
||||||
sf::Vector2f newLocation = playerFood.location;
|
sf::Vector2f newLocation = playerFood.location;
|
||||||
gameBoard.at(newLocation.y).at(newLocation.x) = 'X';
|
gameBoard.at(newLocation.y).at(newLocation.x) = 'X';
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
|
|
||||||
namespace snakeplusplus
|
namespace snakeplusplus
|
||||||
{
|
{
|
||||||
|
|
||||||
void Snake::Pop(void)
|
void Snake::Pop(void)
|
||||||
{
|
{
|
||||||
*(body.front()) = ' ';
|
*(body.front()) = ' ';
|
||||||
|
Loading…
Reference in New Issue
Block a user