diff --git a/src/GameState.cpp b/src/GameState.cpp index 24f2310..a81ae0b 100644 --- a/src/GameState.cpp +++ b/src/GameState.cpp @@ -5,20 +5,16 @@ GameState::GameState() { - videoSizeHorizontal = 1024; - videoSizeVertical = 725; - sf::Vector2u newVideoSize(videoSizeHorizontal, videoSizeVertical); - window.setSize(newVideoSize); - window.setTitle("SnakePlusPlus"); + sf::VideoMode tempVideoMode(1024, 725); + gameVideoMode = tempVideoMode; + sf::RenderWindow gameWindow(gameVideoMode, "SnakePlusPlus"); return; } GameState::GameState(int newHorizontal, int newVertical) { - videoSizeHorizontal = newHorizontal; - videoSizeVertical = newVertical; - sf::Vector2u newVideoSize(videoSizeHorizontal, videoSizeVertical); - window.setSize(newVideoSize); - window.setTitle("SnakePlusPlus"); + sf::VideoMode tempVideoMode(newHorizontal, newVertical); + gameVideoMode = tempVideoMode; + sf::RenderWindow tempWindow(gameVideoMode, "SnakePlusPlus"); return; } diff --git a/src/GameState.h b/src/GameState.h index 5381228..eec85ae 100644 --- a/src/GameState.h +++ b/src/GameState.h @@ -5,12 +5,16 @@ class GameState { private: - int videoSizeHorizontal; - int videoSizeVertical; - sf::RenderWindow window; public: + sf::VideoMode gameVideoMode; + sf::RenderWindow gameWindow; + /* + gameGridHorizontal = (videoSizeHorizontal // 25) * 25; + gameGridVertical = (videoSizeVertical // 25) * 25; + */ GameState(); GameState(int newHorizontal, int newVertical); + // sf::Vector2f GetGameBoundaries(); }; #endif diff --git a/src/main.cpp b/src/main.cpp index ba99147..e6ed2ae 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,35 +1,30 @@ #include +#include #include #include +#include "GameState.h" #include "Snake.h" int main() { - int videoSizeHorizontal, videoSizeVertical; - videoSizeHorizontal = 1024; - videoSizeVertical = 725; - /* - gameGridHorizontal = (videoSizeHorizontal // 25) * 25; - gameGridVertical = (videoSizeVertical // 25) * 25; - */ - sf::RenderWindow window(sf::VideoMode(videoSizeHorizontal, videoSizeVertical), "SnakePlusPlus"); - sf::Time delay = sf::milliseconds(50); - + GameState newGame; + newGame.gameWindow.create(newGame.gameVideoMode, "SnakePlusPlus"); + sf::RenderWindow *window = &newGame.gameWindow; + sf::Time delay = sf::milliseconds(25); int snakeDirection = 0; Snake Player(sf::Vector2f(25,25)); sf::RectangleShape snakeHead(sf::Vector2f(25,25)); sf::RectangleShape snakeFood(sf::Vector2f(25,25)); snakeFood.setFillColor(sf::Color::Red); - snakeFood.setPosition(25,25); - while (window.isOpen()) + while (window->isOpen()) { sf::Event event; - while (window.pollEvent(event)) + while (window->pollEvent(event)) { if ((event.type == sf::Event::Closed) || (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))) - window.close(); + window->close(); } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) snakeDirection = 1; @@ -40,10 +35,10 @@ int main() if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) snakeDirection = 4; Player.MoveSnake(snakeFood); - window.clear(); - window.draw(snakeFood); - Player.DisplaySnake(window); - window.display(); + window->clear(); + window->draw(snakeFood); + Player.DisplaySnake(*window); + window->display(); sf::sleep(delay); } }