-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
62 lines (49 loc) · 1.56 KB
/
main.cpp
File metadata and controls
62 lines (49 loc) · 1.56 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
// =================
// MAIN.CPP
// entry point of the game, sets up the window, scene manager, main loop, event handling, updates, and rendering
// =================
/*
Road Fighter - GDADPRG Final Project
Members:
BARUNDIA, BRAVO, BUAN
Compile:
g++ main.cpp -o race -lsfml-graphics -lsfml-window -lsfml-system -lsfml-audio
Run:
./race
*/
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <SFML/Audio.hpp>
#include <iostream>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include "header/SceneManager.h"
#include "header/MainMenuScene.h"
int main() {
sf::RenderWindow window(sf::VideoMode({ 800, 600 }), "PIXEL1 - BARUNDIA, BRAVO, BUAN");
window.setFramerateLimit(60);
SceneManager sceneManager;
sceneManager.pushScene(std::make_unique<MainMenuScene>(sceneManager), false);
sf::Clock clock;
while (window.isOpen()) {
float dt = clock.restart().asSeconds();
while (const std::optional<sf::Event> ev = window.pollEvent()) {
if (ev->is<sf::Event::Closed>()) {
window.close();
}
if (const auto* kp = ev->getIf<sf::Event::KeyPressed>()) {
if (kp->code == sf::Keyboard::Key::Escape) window.close();
}
}
sceneManager.processSceneChanges();
sceneManager.handleInput(window);
sceneManager.update(dt);
window.clear(sf::Color(20, 20, 20));
sceneManager.render(window);
window.display();
}
return 0;
}