Cleaned up unused code and added more comments for clarification
This commit is contained in:
parent
12a9b118a2
commit
69423bf9d0
@ -64,12 +64,7 @@ sf::Vector2f CalculateNewPosition(int direction, sf::Vector2f position)
|
|||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Snake::ExtendSnake()
|
// Move snake based on direction and test for eating food
|
||||||
{
|
|
||||||
// Create a new deque RectangleShape without popping old
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Snake::MoveSnake(sf::RectangleShape& snakeFood)
|
void Snake::MoveSnake(sf::RectangleShape& snakeFood)
|
||||||
{
|
{
|
||||||
// Create a new deque RectangleShape and pop old
|
// Create a new deque RectangleShape and pop old
|
||||||
@ -94,7 +89,7 @@ void Snake::MoveSnake(sf::RectangleShape& snakeFood)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get x and y position of snake head
|
// Return the Vector2f head of snake
|
||||||
sf::Vector2f Snake::GetSnakeHeadPosition()
|
sf::Vector2f Snake::GetSnakeHeadPosition()
|
||||||
{
|
{
|
||||||
sf::Vector2f position;
|
sf::Vector2f position;
|
||||||
@ -102,6 +97,7 @@ sf::Vector2f Snake::GetSnakeHeadPosition()
|
|||||||
return position;
|
return position;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return the RectangleShape head of snake
|
||||||
sf::RectangleShape Snake::GetSnakeHead()
|
sf::RectangleShape Snake::GetSnakeHead()
|
||||||
{
|
{
|
||||||
sf::RectangleShape head;
|
sf::RectangleShape head;
|
||||||
@ -109,6 +105,7 @@ sf::RectangleShape Snake::GetSnakeHead()
|
|||||||
return head;
|
return head;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Iterate through snake deque and draw to window
|
||||||
void Snake::DisplaySnake(sf::RenderWindow& window)
|
void Snake::DisplaySnake(sf::RenderWindow& window)
|
||||||
{
|
{
|
||||||
for (auto it = snakeBody.cbegin(); it != snakeBody.cend(); ++it)
|
for (auto it = snakeBody.cbegin(); it != snakeBody.cend(); ++it)
|
||||||
@ -118,12 +115,16 @@ void Snake::DisplaySnake(sf::RenderWindow& window)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// General constructor for snake class
|
||||||
Snake::Snake()
|
Snake::Snake()
|
||||||
{
|
{
|
||||||
// Possibly unnecessary
|
sf::RectangleShape newBodyPart(sf::Vector2f(25,25));
|
||||||
// The big 3 could be used to create a fresh game state
|
newBodyPart.setFillColor(sf::Color::Green);
|
||||||
|
snakeBody.push_back(newBodyPart);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Constructor for snake with position
|
||||||
Snake::Snake(sf::Vector2f head)
|
Snake::Snake(sf::Vector2f head)
|
||||||
{
|
{
|
||||||
sf::RectangleShape newBodyPart(head);
|
sf::RectangleShape newBodyPart(head);
|
||||||
|
12
src/Snake.h
12
src/Snake.h
@ -7,17 +7,6 @@ bool SnakeCollision(sf::RectangleShape object1, sf::RectangleShape object2);
|
|||||||
int SnakeMovement();
|
int SnakeMovement();
|
||||||
sf::Vector2f CalculateNewPosition(int direction, sf::Vector2f position);
|
sf::Vector2f CalculateNewPosition(int direction, sf::Vector2f position);
|
||||||
|
|
||||||
// class SnakeNode
|
|
||||||
// {
|
|
||||||
// private:
|
|
||||||
// // sf::RectangleShape snakeBody(sf::Vector2f(25,25));
|
|
||||||
// sf::Vector2f snakeBodyLocation;
|
|
||||||
// SnakeNode* next;
|
|
||||||
// public:
|
|
||||||
// SnakeNode();
|
|
||||||
// SnakeNode(sf::Vector2f addBodyPiece);
|
|
||||||
// };
|
|
||||||
|
|
||||||
class Snake
|
class Snake
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
@ -29,7 +18,6 @@ public:
|
|||||||
sf::Vector2f GetSnakeHeadPosition();
|
sf::Vector2f GetSnakeHeadPosition();
|
||||||
sf::RectangleShape GetSnakeHead();
|
sf::RectangleShape GetSnakeHead();
|
||||||
void DisplaySnake(sf::RenderWindow& window);
|
void DisplaySnake(sf::RenderWindow& window);
|
||||||
void ExtendSnake();
|
|
||||||
void MoveSnake(sf::RectangleShape& snakeFood);
|
void MoveSnake(sf::RectangleShape& snakeFood);
|
||||||
void CheckDirection();
|
void CheckDirection();
|
||||||
bool CheckBoundaries();
|
bool CheckBoundaries();
|
||||||
|
@ -43,7 +43,6 @@ int main()
|
|||||||
if ((event.type == sf::Event::Closed) || (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)))
|
if ((event.type == sf::Event::Closed) || (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)))
|
||||||
window.close();
|
window.close();
|
||||||
}
|
}
|
||||||
// sf::Vector2f snakeFoodPosition = snakeFood.getPosition();
|
|
||||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
|
||||||
snakeDirection = 1;
|
snakeDirection = 1;
|
||||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
|
||||||
|
Loading…
Reference in New Issue
Block a user