diff --git a/src/Snake.cpp b/src/Snake.cpp new file mode 100644 index 0000000..b0fba5b --- /dev/null +++ b/src/Snake.cpp @@ -0,0 +1,55 @@ +#include +#include +#include +#include "Snake.h" +using namespace std; + +bool SnakeCollision(sf::RectangleShape object1, sf::RectangleShape object2) +{ + sf::Vector2f object1Position = object1.getPosition(); + sf::Vector2f object2Position = object2.getPosition(); + if (object1Position.x != object2Position.x) + return 0; + if (object1Position.y != object2Position.y) + return 0; + + return 1; + +} + +void SnakeMovement(sf::Keyboard keyboard) +{ + /* + if (keyboard.pressed(Left)) + snakeHead.moveleft(); + + if (keyboard.pressed(Right)) + snakeHead.moveRight(); + if (keyboard.pressed(Down)) + snakeHead.moveDown(); + if (keyboard.pressed(Up)) + snakeHead.moveUp(); + if (!snakeHead.isTouchingFood()) + snakeQueue.pop(); + + */ + return; +} + +void Snake::ExtendSnake(sf::Vector2f newLocation) +{ + /* + snakeBody.push_back(newLocation); + */ + return; +} + +void Snake::MoveSnake() +{ + /* + head.snakeBody() + */ + return; +} +SnakeNode::SnakeNode(); +SnakeNode::SnakeNode(sf::Vector2f addBodyPiece); diff --git a/src/Snake.h b/src/Snake.h new file mode 100644 index 0000000..5c9e4c5 --- /dev/null +++ b/src/Snake.h @@ -0,0 +1,30 @@ +//Snake.h +#ifndef SNAKE_H +#define SNAKE_H +#include + +bool SnakeCollision(sf::RectangleShape object1, sf::RectangleShape object2); +void SnakeMovement(sf::Keyboard keyboard); + +class SnakeNode +{ +private: + // sf::RectangleShape snakeBody(sf::Vector2f(25,25)); + sf::Vector2f snakeBodyLocation; + SnakeNode* next; +public: + SnakeNode(); + SnakeNode(sf::Vector2f addBodyPiece); +}; + +class Snake +{ +private: + std::deque snakeBody; +public: + void ExtendSnake(sf::Vector2f newLocation); + void MoveSnake(); +}; + + +#endif diff --git a/src/main.cpp b/src/main.cpp index f7e00db..12f7310 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,9 +1,22 @@ #include #include #include +#include "Snake.h" using namespace std; -bool SnakeCollision(sf::RectangleShape object1, sf::RectangleShape object2); + +/* + + TODO: Work on snake body + Add ability for body to extend when eating food + + Turn snake body into queue + Each piece of queue has coordinates + If head touches food, just add to queue, don't pop + +*/ + + int main() { @@ -30,6 +43,9 @@ int main() } sf::Vector2f snakeHeadPosition = snakeHead.getPosition(); sf::Vector2f snakeFoodPosition = snakeFood.getPosition(); + // TODO: Split Movement into separate function + // Add boundaries + // Add movement until boundaries if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) snakeHeadPosition.x -= 25; if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) @@ -52,16 +68,3 @@ int main() sf::sleep(delay); } } - -bool SnakeCollision(sf::RectangleShape object1, sf::RectangleShape object2) -{ - sf::Vector2f object1Position = object1.getPosition(); - sf::Vector2f object2Position = object2.getPosition(); - if (object1Position.x != object2Position.x) - return 0; - if (object1Position.y != object2Position.y) - return 0; - - return 1; - -}