-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
67 lines (48 loc) · 1.84 KB
/
Copy pathmain.cpp
File metadata and controls
67 lines (48 loc) · 1.84 KB
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
#include <SFML/Graphics.hpp>
#include "map_gen.hpp"
#include "tilemap.hpp"
#include "player.hpp"
#include "globals.hpp"
#include "game_state.hpp"
#include <random>
int main()
{
sf::RenderWindow window(sf::VideoMode({ 800, 800 }), "DungeonCrawler");
window.setKeyRepeatEnabled(false);
TileMap::load_tile_textures();
sf::Clock clock;
sf::Time dt;
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> dist(3, 5);
// create 2 game over screens, pop once for a loss, pop twice for a win.
// i could use change state but this is simpler to implement.
GameStateManager::get().push_state(std::make_unique<GameOver>(800, 800, "win.png"));
GameStateManager::get().push_state(std::make_unique<GameOver>(800, 800, "game_over.png"));
GameStateManager::get().push_state(std::make_unique<MainGame>(dist(gen) , dist(gen)));
GameStateManager::get().apply_queued_actions();
while (window.isOpen())
{
dt = clock.restart();
GameState* current_state = GameStateManager::get().current_state();
window.setView(current_state->game_view);
// Event handling
while (const std::optional event = window.pollEvent())
{
if (event->is<sf::Event::Closed>())
window.close();
else if (const auto* key_pressed = event->getIf<sf::Event::KeyPressed>())
{
current_state->event_handler.handle_single_k_events(key_pressed);
}
}
current_state->event_handler.handle_repeat_k_events();
current_state->event_handler.run_scheduled_events(dt);
// updating and rendering
current_state->update(dt, window);
window.clear();
current_state->render(window);
window.display();
GameStateManager::get().apply_queued_actions();
}
}