Merge pull request #7 from TriantaTV/Development
GameState now handles RenderWindow
This commit is contained in:
commit
eb0c19e631
@ -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;
|
||||||
}
|
}
|
||||||
|
@ -5,12 +5,16 @@
|
|||||||
class GameState
|
class GameState
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
int videoSizeHorizontal;
|
|
||||||
int videoSizeVertical;
|
|
||||||
sf::RenderWindow window;
|
|
||||||
public:
|
public:
|
||||||
|
sf::VideoMode gameVideoMode;
|
||||||
|
sf::RenderWindow gameWindow;
|
||||||
|
/*
|
||||||
|
gameGridHorizontal = (videoSizeHorizontal // 25) * 25;
|
||||||
|
gameGridVertical = (videoSizeVertical // 25) * 25;
|
||||||
|
*/
|
||||||
GameState();
|
GameState();
|
||||||
GameState(int newHorizontal, int newVertical);
|
GameState(int newHorizontal, int newVertical);
|
||||||
|
// sf::Vector2f GetGameBoundaries();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
31
src/main.cpp
31
src/main.cpp
@ -1,35 +1,30 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <SFML\Graphics.hpp>
|
#include <SFML\Graphics.hpp>
|
||||||
#include <SFML\System.hpp>
|
#include <SFML\System.hpp>
|
||||||
|
#include "GameState.h"
|
||||||
#include "Snake.h"
|
#include "Snake.h"
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
int videoSizeHorizontal, videoSizeVertical;
|
GameState newGame;
|
||||||
videoSizeHorizontal = 1024;
|
newGame.gameWindow.create(newGame.gameVideoMode, "SnakePlusPlus");
|
||||||
videoSizeVertical = 725;
|
sf::RenderWindow *window = &newGame.gameWindow;
|
||||||
/*
|
sf::Time delay = sf::milliseconds(25);
|
||||||
gameGridHorizontal = (videoSizeHorizontal // 25) * 25;
|
|
||||||
gameGridVertical = (videoSizeVertical // 25) * 25;
|
|
||||||
*/
|
|
||||||
sf::RenderWindow window(sf::VideoMode(videoSizeHorizontal, videoSizeVertical), "SnakePlusPlus");
|
|
||||||
sf::Time delay = sf::milliseconds(50);
|
|
||||||
|
|
||||||
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;
|
||||||
@ -40,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