Moved render window into GameState
This commit is contained in:
parent
19b91b78d2
commit
f64577d2cd
@ -5,20 +5,16 @@
|
|||||||
|
|
||||||
GameState::GameState()
|
GameState::GameState()
|
||||||
{
|
{
|
||||||
videoSizeHorizontal = 1024;
|
sf::VideoMode tempVideoMode(1024, 725);
|
||||||
videoSizeVertical = 725;
|
gameVideoMode = tempVideoMode;
|
||||||
// sf::Vector2u newVideoSize(videoSizeHorizontal, videoSizeVertical);
|
sf::RenderWindow gameWindow(gameVideoMode, "SnakePlusPlus");
|
||||||
// window.setSize(newVideoSize);
|
|
||||||
// window.setTitle("SnakePlusPlus");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GameState::GameState(int newHorizontal, int newVertical)
|
GameState::GameState(int newHorizontal, int newVertical)
|
||||||
{
|
{
|
||||||
videoSizeHorizontal = newHorizontal;
|
sf::VideoMode tempVideoMode(newHorizontal, newVertical);
|
||||||
videoSizeVertical = newVertical;
|
gameVideoMode = tempVideoMode;
|
||||||
// sf::Vector2u newVideoSize(videoSizeHorizontal, videoSizeVertical);
|
sf::RenderWindow tempWindow(gameVideoMode, "SnakePlusPlus");
|
||||||
// window.setSize(newVideoSize);
|
|
||||||
// window.setTitle("SnakePlusPlus");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -6,9 +6,12 @@ class GameState
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
public:
|
public:
|
||||||
unsigned int videoSizeHorizontal;
|
sf::VideoMode gameVideoMode;
|
||||||
unsigned int videoSizeVertical;
|
sf::RenderWindow gameWindow;
|
||||||
// sf::RenderWindow window;
|
/*
|
||||||
|
gameGridHorizontal = (videoSizeHorizontal // 25) * 25;
|
||||||
|
gameGridVertical = (videoSizeVertical // 25) * 25;
|
||||||
|
*/
|
||||||
GameState();
|
GameState();
|
||||||
GameState(int newHorizontal, int newVertical);
|
GameState(int newHorizontal, int newVertical);
|
||||||
// sf::Vector2f GetGameBoundaries();
|
// sf::Vector2f GetGameBoundaries();
|
||||||
|
28
src/main.cpp
28
src/main.cpp
@ -7,34 +7,24 @@
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
// int videoSizeHorizontal, videoSizeVertical;
|
|
||||||
// videoSizeHorizontal = 1024;
|
|
||||||
// videoSizeVertical = 725;
|
|
||||||
/*
|
|
||||||
gameGridHorizontal = (videoSizeHorizontal // 25) * 25;
|
|
||||||
gameGridVertical = (videoSizeVertical // 25) * 25;
|
|
||||||
*/
|
|
||||||
// GameState newGame(1200, 1000);
|
|
||||||
GameState newGame;
|
GameState newGame;
|
||||||
sf::RenderWindow window(sf::VideoMode(newGame.videoSizeHorizontal, newGame.videoSizeVertical), "SnakePlusPlus");
|
newGame.gameWindow.create(newGame.gameVideoMode, "SnakePlusPlus");
|
||||||
// window = newGame.window;
|
sf::RenderWindow *window = &newGame.gameWindow;
|
||||||
sf::Time delay = sf::milliseconds(25);
|
sf::Time delay = sf::milliseconds(25);
|
||||||
|
|
||||||
int snakeDirection = 0;
|
int snakeDirection = 0;
|
||||||
Snake Player(sf::Vector2f(25,25));
|
Snake Player(sf::Vector2f(25,25));
|
||||||
sf::RectangleShape snakeHead(sf::Vector2f(25,25));
|
sf::RectangleShape snakeHead(sf::Vector2f(25,25));
|
||||||
sf::RectangleShape snakeFood(sf::Vector2f(25,25));
|
sf::RectangleShape snakeFood(sf::Vector2f(25,25));
|
||||||
snakeFood.setFillColor(sf::Color::Red);
|
snakeFood.setFillColor(sf::Color::Red);
|
||||||
|
|
||||||
snakeFood.setPosition(25,25);
|
snakeFood.setPosition(25,25);
|
||||||
|
|
||||||
while (window.isOpen())
|
while (window->isOpen())
|
||||||
{
|
{
|
||||||
sf::Event event;
|
sf::Event event;
|
||||||
while (window.pollEvent(event))
|
while (window->pollEvent(event))
|
||||||
{
|
{
|
||||||
if ((event.type == sf::Event::Closed) || (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)))
|
if ((event.type == sf::Event::Closed) || (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape)))
|
||||||
window.close();
|
window->close();
|
||||||
}
|
}
|
||||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
|
||||||
snakeDirection = 1;
|
snakeDirection = 1;
|
||||||
@ -45,10 +35,10 @@ int main()
|
|||||||
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
|
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
|
||||||
snakeDirection = 4;
|
snakeDirection = 4;
|
||||||
Player.MoveSnake(snakeFood);
|
Player.MoveSnake(snakeFood);
|
||||||
window.clear();
|
window->clear();
|
||||||
window.draw(snakeFood);
|
window->draw(snakeFood);
|
||||||
Player.DisplaySnake(window);
|
Player.DisplaySnake(*window);
|
||||||
window.display();
|
window->display();
|
||||||
sf::sleep(delay);
|
sf::sleep(delay);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user