-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
71 lines (54 loc) · 1.75 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
/* Main file of the rogue project
We will handle the main loop of the game here
Author : Guillaume Mouton (Kiroxas)
*/
/* User defined includes */
#include "Rendering Engine/Rendering.h"
#include "Input/Input.h"
#include "Misc/ImagePool.h"
#include "Misc/GameInfo.h"
#include "Level.h"
/* SFML includes */
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
/* STL includes */
#include <memory>
#include <random>
#include <thread>
#include <chrono>
#include <SFML/Audio.hpp>
#include <iostream>
int main()
{
/* Creation of the window */
sf::RenderWindow window(sf::VideoMode(800, 600), "Rogue BOI Style",sf::Style::Resize);
window.setFramerateLimit(60);
GameInfo stats;
ImagePool pool;
std::vector<std::function<void()>> callbacks;
/*sf::Music music;
if(!music.openFromFile("./data/Music/01.flac"))
return 1;
music.play();*/
/* Creation of the maze */
Input::GameInput g_i(sf::Keyboard::Up,sf::Keyboard::Down,sf::Keyboard::Left,sf::Keyboard::Right);
bool running = true;
sf::Event event;
sf::Clock clock;
Level l(pool,g_i,stats);
auto quit_reg = g_i.Quit::Suscribe([&running](){std::cout << "Quit" << std::endl; running = false;});
auto quit_reg2 = l.HeroAreDead::Suscribe([&running](){std::cout << "Dead" << std::endl; running = false;});
auto quit_reg3 = l.ClearedLevel::Suscribe([&running](){std::cout << "Cleared" << std::endl; running = false;});
callbacks.emplace_back(std::bind(&Input::GameInput::update,std::ref(g_i),std::ref(event)));
callbacks.emplace_back(std::bind(&Level::update, std::ref(l)));
while(running)
{
window.pollEvent(event);
for(auto& e : callbacks)
e();
rendering::render_level(l,window,stats,pool);
window.display();
stats.setFps(1.0f / clock.restart().asSeconds());
}
stats.dump();
}