Added GameState and cleaned up unused code

This commit is contained in:
TriantaTV 2022-07-28 15:18:24 -05:00
parent e812588200
commit 1a90a4601a
5 changed files with 41 additions and 17 deletions

24
src/GameState.cpp Normal file
View File

@ -0,0 +1,24 @@
#include <iostream>
#include <SFML\Graphics.hpp>
#include <SFML\System.hpp>
#include "GameState.h"
GameState::GameState()
{
videoSizeHorizontal = 1024;
videoSizeVertical = 725;
sf::Vector2u newVideoSize(videoSizeHorizontal, videoSizeVertical);
window.setSize(newVideoSize);
window.setTitle("SnakePlusPlus");
return;
}
GameState::GameState(int newHorizontal, int newVertical)
{
videoSizeHorizontal = newHorizontal;
videoSizeVertical = newVertical;
sf::Vector2u newVideoSize(videoSizeHorizontal, videoSizeVertical);
window.setSize(newVideoSize);
window.setTitle("SnakePlusPlus");
return;
}

16
src/GameState.h Normal file
View File

@ -0,0 +1,16 @@
// GameState.h
#ifndef GAMESTATE_H
#define GAMESTATE_H
class GameState
{
private:
int videoSizeHorizontal;
int videoSizeVertical;
sf::RenderWindow window;
public:
GameState();
GameState(int newHorizontal, int newVertical);
};
#endif

View File

@ -67,8 +67,6 @@ sf::Vector2f CalculateNewPosition(int direction, sf::Vector2f position)
// Move snake based on direction and test for eating food // Move snake based on direction and test for eating food
void Snake::MoveSnake(sf::RectangleShape& snakeFood) void Snake::MoveSnake(sf::RectangleShape& snakeFood)
{ {
// Create a new deque RectangleShape and pop old
// Todo: Depreciate ExtendSnake and just add a collision test
CheckDirection(); CheckDirection();
sf::Vector2f newHeadPosition; sf::Vector2f newHeadPosition;
newHeadPosition = GetSnakeHeadPosition(); newHeadPosition = GetSnakeHeadPosition();
@ -151,5 +149,3 @@ Snake::Snake(sf::Vector2f head)
snakeBody.push_back(newBodyPart); snakeBody.push_back(newBodyPart);
return; return;
} }
// SnakeNode::SnakeNode();
// SnakeNode::SnakeNode(sf::Vector2f addBodyPiece);

View File

@ -1,4 +1,4 @@
//Snake.h // Snake.h
#ifndef SNAKE_H #ifndef SNAKE_H
#define SNAKE_H #define SNAKE_H
#include <queue> #include <queue>

View File

@ -3,18 +3,6 @@
#include <SFML\System.hpp> #include <SFML\System.hpp>
#include "Snake.h" #include "Snake.h"
/*
TODO:
Add ability for body to extend when eating food
Each piece of queue has coordinates
If head touches food, just add to queue, don't pop
*/
int main() int main()
{ {
int videoSizeHorizontal, videoSizeVertical; int videoSizeHorizontal, videoSizeVertical;