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:
parent
c7263dfc1f
commit
3d8dcf23ac
@ -4,8 +4,11 @@
|
|||||||
#include "Snake.h"
|
#include "Snake.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
// Test for collision between two objects
|
||||||
bool SnakeCollision(sf::RectangleShape object1, sf::RectangleShape object2)
|
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 object1Position = object1.getPosition();
|
||||||
sf::Vector2f object2Position = object2.getPosition();
|
sf::Vector2f object2Position = object2.getPosition();
|
||||||
if (object1Position.x != object2Position.x)
|
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)
|
void SnakeMovement(sf::Keyboard keyboard)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@ -36,7 +40,7 @@ void SnakeMovement(sf::Keyboard keyboard)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Snake::ExtendSnake(sf::Vector2f newLocation)
|
void Snake::ExtendSnake()
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
snakeBody.push_back(newLocation);
|
snakeBody.push_back(newLocation);
|
||||||
|
@ -20,10 +20,12 @@ void SnakeMovement(sf::Keyboard keyboard);
|
|||||||
class Snake
|
class Snake
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::deque<sf::Vector2f> snakeBody;
|
std::deque<sf::RectangleShape> snakeBody;
|
||||||
public:
|
public:
|
||||||
void ExtendSnake(sf::Vector2f newLocation);
|
// Instead of popping like in MoveSnake()
|
||||||
void MoveSnake();
|
// Simply add to deque
|
||||||
|
void ExtendSnake();
|
||||||
|
void MoveSnake(); // Move only head body piece
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user