Fixed movement and color of snake
This commit is contained in:
parent
a8eee1db4d
commit
97085dd314
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user