Merge pull request #9 from TriantaTV/Development
Fixed stacking at boundaries
This commit is contained in:
commit
f526a7500f
1
.gitignore
vendored
1
.gitignore
vendored
@ -31,3 +31,4 @@
|
|||||||
*.out
|
*.out
|
||||||
*.app
|
*.app
|
||||||
*.json
|
*.json
|
||||||
|
*.ps1
|
||||||
|
@ -19,7 +19,7 @@ bool SnakeCollision(sf::RectangleShape object1, sf::RectangleShape object2)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Move snake head piece
|
// Check keyboard for new direction of snake
|
||||||
void Snake::CheckDirection()
|
void Snake::CheckDirection()
|
||||||
{
|
{
|
||||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
|
||||||
@ -70,13 +70,13 @@ void Snake::MoveSnake(sf::RectangleShape& snakeFood)
|
|||||||
CheckDirection();
|
CheckDirection();
|
||||||
sf::Vector2f newHeadPosition;
|
sf::Vector2f newHeadPosition;
|
||||||
newHeadPosition = GetSnakeHeadPosition();
|
newHeadPosition = GetSnakeHeadPosition();
|
||||||
if (!CheckBoundaries())
|
if (CheckBoundaries())
|
||||||
newHeadPosition = CalculateNewPosition(snakeDirection, newHeadPosition);
|
return;
|
||||||
|
newHeadPosition = CalculateNewPosition(snakeDirection, newHeadPosition);
|
||||||
sf::RectangleShape newBodyPart(sf::Vector2f(25,25));
|
sf::RectangleShape newBodyPart(sf::Vector2f(25,25));
|
||||||
newBodyPart.setPosition(newHeadPosition);
|
newBodyPart.setPosition(newHeadPosition);
|
||||||
if (IsSelfCollision(newBodyPart))
|
if (IsSelfCollision(newBodyPart)) // Do nothing if self collision
|
||||||
{
|
{
|
||||||
// Do nothing if self collision
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
newBodyPart.setFillColor(sf::Color::Green);
|
newBodyPart.setFillColor(sf::Color::Green);
|
||||||
|
Loading…
Reference in New Issue
Block a user