Deque swapped to hold sf::RectangleShape

Deque swapped to hold sf::RectangleShape and will allow for holding a deque for each snake body piece. Snake class can create functions to get necessary tests through deque.
This commit is contained in:
TriantaTV 2022-07-25 16:06:06 -05:00
parent c7263dfc1f
commit 3d8dcf23ac
2 changed files with 10 additions and 4 deletions

View File

@ -4,8 +4,11 @@
#include "Snake.h"
using namespace std;
// Test for collision between two objects
bool SnakeCollision(sf::RectangleShape object1, sf::RectangleShape object2)
{
// Hack for getting a temporary collision
// Collision only tested for origin corrordinate
sf::Vector2f object1Position = object1.getPosition();
sf::Vector2f object2Position = object2.getPosition();
if (object1Position.x != object2Position.x)
@ -17,6 +20,7 @@ bool SnakeCollision(sf::RectangleShape object1, sf::RectangleShape object2)
}
// Move snake head piece
void SnakeMovement(sf::Keyboard keyboard)
{
/*
@ -36,7 +40,7 @@ void SnakeMovement(sf::Keyboard keyboard)
return;
}
void Snake::ExtendSnake(sf::Vector2f newLocation)
void Snake::ExtendSnake()
{
/*
snakeBody.push_back(newLocation);

View File

@ -20,10 +20,12 @@ void SnakeMovement(sf::Keyboard keyboard);
class Snake
{
private:
std::deque<sf::Vector2f> snakeBody;
std::deque<sf::RectangleShape> snakeBody;
public:
void ExtendSnake(sf::Vector2f newLocation);
void MoveSnake();
// Instead of popping like in MoveSnake()
// Simply add to deque
void ExtendSnake();
void MoveSnake(); // Move only head body piece
};