Merge pull request #2 from TriantaTV/Development
Development runs but not yet updated with new features
This commit is contained in:
commit
5842130425
59
src/Snake.cpp
Normal file
59
src/Snake.cpp
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <SFML\Graphics.hpp>
|
||||||
|
#include <SFML\System.hpp>
|
||||||
|
#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)
|
||||||
|
return 0;
|
||||||
|
if (object1Position.y != object2Position.y)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move snake head piece
|
||||||
|
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();
|
||||||
|
*/
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Snake::ExtendSnake()
|
||||||
|
{
|
||||||
|
// Create a new deque RectangleShape without popping old
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Snake::MoveSnake()
|
||||||
|
{
|
||||||
|
// Create a new deque RectangleShape and pop old
|
||||||
|
// Todo: Depreciate ExtendSnake and just add a collision test
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Snake::Snake()
|
||||||
|
{
|
||||||
|
// Possibly unnecessary
|
||||||
|
// The big 3 could be used to create a fresh game state
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// SnakeNode::SnakeNode();
|
||||||
|
// SnakeNode::SnakeNode(sf::Vector2f addBodyPiece);
|
33
src/Snake.h
Normal file
33
src/Snake.h
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
//Snake.h
|
||||||
|
#ifndef SNAKE_H
|
||||||
|
#define SNAKE_H
|
||||||
|
#include <queue>
|
||||||
|
|
||||||
|
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<sf::RectangleShape> snakeBody;
|
||||||
|
Snake();
|
||||||
|
public:
|
||||||
|
// Instead of popping like in MoveSnake()
|
||||||
|
// Simply add to deque
|
||||||
|
void ExtendSnake();
|
||||||
|
void MoveSnake(); // Move only head body piece
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
31
src/main.cpp
31
src/main.cpp
@ -1,9 +1,22 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <SFML\Graphics.hpp>
|
#include <SFML\Graphics.hpp>
|
||||||
#include <SFML\System.hpp>
|
#include <SFML\System.hpp>
|
||||||
|
#include "Snake.h"
|
||||||
using namespace std;
|
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()
|
int main()
|
||||||
{
|
{
|
||||||
@ -30,6 +43,9 @@ int main()
|
|||||||
}
|
}
|
||||||
sf::Vector2f snakeHeadPosition = snakeHead.getPosition();
|
sf::Vector2f snakeHeadPosition = snakeHead.getPosition();
|
||||||
sf::Vector2f snakeFoodPosition = snakeFood.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))
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
|
||||||
snakeHeadPosition.x -= 25;
|
snakeHeadPosition.x -= 25;
|
||||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
|
||||||
@ -52,16 +68,3 @@ int main()
|
|||||||
sf::sleep(delay);
|
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;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user