-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGame.cpp
89 lines (68 loc) · 1.38 KB
/
Game.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
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "Game.h"
Game::Game() : _window(sf::VideoMode(1200, 800), "Plateformer 0.1")
{
map.createMap("assets/maps/tilemap.txt");
tMap.init(map, ResourceDispatcher::rDispatcherTexture.get(TextureName::map));
tMap.load();
tMap.loadLayer1();
}
void Game::init()
{
}
void Game::run(int frame_per_seconds)
{
sf::Clock clock;
sf::Time timeSinceLastUpdate = sf::Time::Zero;
sf::Time TimePerFrame = sf::seconds(1.f / frame_per_seconds);
while (_window.isOpen())
{
processEvents();
bool repaint = false;
timeSinceLastUpdate += clock.restart();
while (timeSinceLastUpdate > TimePerFrame)
{
timeSinceLastUpdate -= TimePerFrame;
repaint = true;
update(TimePerFrame);
}
if (repaint)
render();
}
}
void Game::runWithFixedTimeSteps(int frame_per_seconds)
{
}
void Game::runWithVariableTimeSteps()
{
}
void Game::runWithMinimumTimeSteps(int minimum_frame_per_seconds)
{
}
void Game::processEvents()
{
sf::Event event;
while (_window.pollEvent(event)) {
if ((event.type == sf::Event::Closed)) {
_window.close();
}
/*else if (event.type == sf::Event::KeyPressed) {
if (event.key.code == sf::Keyboard::Left) {
_player.moveLeft(1.0f);
}
}*/
}
}
void Game::update()
{
}
void Game::update(sf::Time deltaTime)
{
_player.update(deltaTime);
}
void Game::render()
{
_window.clear();
_window.draw(_player);
_window.draw(tMap);
_window.display();
}