-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplication.cpp
More file actions
52 lines (44 loc) · 1012 Bytes
/
Application.cpp
File metadata and controls
52 lines (44 loc) · 1012 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "Application.h"
Application::Application() : mWindow(sf::VideoMode(1024, 768), "Pathfinder")
{
gameState = mainState;
mView.setCenter(sf::Vector2f(800 / 2, 600 / 2)); // hard coded
mView.setSize(sf::Vector2f(800, 600)); // hard coded
//mView.setViewport(sf::FloatRect(0.25f, 0.25f, 0.5f, 0.5f));
mWindow.setView(mView);
mWindow.setFramerateLimit(30);
if (gameState == mainState)
mainstate = new MainState(&mWindow); // to do - destructor
}
void Application::run()
{
while (mWindow.isOpen())
{
processEvents();
update();
render();
}
}
void Application::processEvents()
{
sf::Event event;
while (mWindow.pollEvent(event))
{
if (event.type == sf::Event::Closed)
mWindow.close();
if (mainState == gameState)
{
mainstate->handleInput(event, mWindow);
}
}
}
void Application::update()
{
}
void Application::render()
{
mWindow.clear();
if (gameState == mainState)
mainstate->draw(mWindow);
mWindow.display();
}