-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.cpp
More file actions
73 lines (62 loc) · 1.39 KB
/
Game.cpp
File metadata and controls
73 lines (62 loc) · 1.39 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
68
69
70
71
72
73
/*
** EPITECH PROJECT, 2022
** particule sfml
** File description:
** Game
*/
#include "Game.hpp"
Game::Game()
{
_window.create(sf::VideoMode(1920, 1080), "uwu ruru", sf::Style::Fullscreen);
_window.setFramerateLimit(144);
_particules = new Particules();
_font.loadFromFile("font.ttf");
_text_fps.setFont(_font);
_text_fps.setCharacterSize(24);
_text_fps.setFillColor(sf::Color::White);
}
Game::~Game()
{
delete _particules;
}
void Game::run()
{
while (_window.isOpen()) {
events();
update();
render();
}
}
static void update_fps(sf::Text &text, sf::Clock &clock)
{
static int frame = 0;
static float time = 0;
frame++;
time += clock.restart().asSeconds();
if (time >= 1) {
text.setString(std::to_string(frame));
frame = 0;
time = 0;
}
}
void Game::update()
{
_particules->update();
update_fps(_text_fps, _clock_fps);
}
void Game::render()
{
_window.clear();
_particules->draw(_window);
_window.draw(_text_fps);
_window.display();
}
void Game::events()
{
while (_window.pollEvent(_event)) {
if (_event.type == sf::Event::Closed)
_window.close();
if (_event.type == sf::Event::KeyPressed && _event.key.code == sf::Keyboard::Escape)
_window.close();
}
}