Fixed movement and color of snake

This commit is contained in:
TriantaTV 2022-07-26 19:24:46 -05:00
parent a8eee1db4d
commit 97085dd314
2 changed files with 7 additions and 6 deletions

View File

@ -63,9 +63,10 @@ void Snake::MoveSnake(int snakeDirection)
sf::Vector2f newHeadPosition;
newHeadPosition = GetSnakeHeadPosition();
newHeadPosition = CalculateNewPosition(snakeDirection, newHeadPosition);
sf::RectangleShape newBodyPart(newHeadPosition);
sf::RectangleShape newBodyPart(sf::Vector2f(25,25));
newBodyPart.setPosition(newHeadPosition);
snakeBody.push_back(newBodyPart);
// snakeBody.pop_front();
snakeBody.pop_front();
return;
}
@ -102,6 +103,7 @@ Snake::Snake()
Snake::Snake(sf::Vector2f head)
{
sf::RectangleShape newBodyPart(head);
newBodyPart.setFillColor(sf::Color::Green);
snakeBody.push_back(newBodyPart);
return;
}

View File

@ -27,7 +27,7 @@ int main()
gameGridVertical = (videoSizeVertical // 25) * 25;
*/
sf::RenderWindow window(sf::VideoMode(videoSizeHorizontal, videoSizeVertical), "SnakePlusPlus");
sf::Time delay = sf::milliseconds(100);
sf::Time delay = sf::milliseconds(5);
int snakeDirection = 0;
Snake Player(sf::Vector2f(25,25));
@ -46,7 +46,7 @@ int main()
if ((event.type == sf::Event::Closed) || (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)))
window.close();
}
sf::Vector2f snakeHeadPosition = Player.GetSnakeHeadPosition();
// sf::Vector2f snakeHeadPosition = Player.GetSnakeHeadPosition();
sf::Vector2f snakeFoodPosition = snakeFood.getPosition();
// TODO: Split Movement into separate function
// Add boundaries
@ -67,9 +67,8 @@ int main()
// snakeFood.setPosition(snakeFoodPosition.x, snakeFoodPosition.y);
window.clear();
window.draw(snakeFood);
Player.DisplaySnake(window);
window.display();
// sf::sleep(delay);
sf::sleep(delay);
}
}