-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
76 lines (59 loc) · 1.43 KB
/
main.cpp
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//STD
#include <iostream>
#include <vector>
//3RD
#include "SFML/Graphics.hpp"
//SELF
#include "Map.hpp"
#include "Constants.hpp"
#include "Pathfinder.hpp"
void handleEvent(sf::Event& e, sf::RenderWindow& window);
void update(const float dt, sf::RenderWindow& window);
void draw(sf::RenderWindow& window);
Map map;
Pathfinder pathfinder(map);
int main()
{
sf::RenderWindow window(sf::VideoMode(Constant::windowWidth, Constant::windowHeight), "Pathfinding");
sf::Clock frameTime;
sf::Time prevFrameTime = sf::seconds(1.f / 60.f);
sf::Event event;
while (window.isOpen())
{
window.pollEvent(event);
handleEvent(event, window);
update(prevFrameTime.asSeconds(), window);
draw(window);
//std::cout << "FPS: " << 1.f / prevFrameTime.asSeconds() << "\n";
prevFrameTime = frameTime.restart();
}
return 0;
}
void handleEvent(sf::Event& e, sf::RenderWindow& window)
{
map.handleEvent(e, window);
pathfinder.handleEvent(e, window);
switch (e.type)
{
case (sf::Event::Closed):
{
window.close();
break;
}
default:
{
return;
}
}
}
void update(const float dt, sf::RenderWindow& window)
{
map.update(dt, window);
pathfinder.update(dt, window);
}
void draw(sf::RenderWindow& window)
{
window.clear(sf::Color(40, 40, 40));
window.draw(map);
window.display();
}