-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.cpp
More file actions
54 lines (43 loc) · 1.21 KB
/
Copy pathGame.cpp
File metadata and controls
54 lines (43 loc) · 1.21 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
#include "Game.h"
#include "StatePlay.h"
#include <SFML/Window/Event.hpp>
Game::Game() {
srand(int(time(NULL)));
Global::textureManager.addPath("player-default", "./Assets/player-default.png");
Global::textureManager.addPath("player-hugging", "./Assets/player-hugging.png");
Global::textureManager.addPath("wall", "./Assets/wall.png");
Global::textureManager.addPath("rock", "./Assets/rock.png");
Global::fontManager.addPath("komikap", "./Assets/KOMIKAP.ttf");
Global::fontManager.addPath("main", "./Assets/Vegur-Regular.otf");
Global::stateManager.registerState<StatePlay>(StateType::Play);
}
void Game::play()
{
Global::window.create({ 640, 900, 32 }, "Climber", sf::Style::Close);
Global::stateManager.addState(StateType::Play);
while (Global::window.isOpen()) {
handleInput();
update();
draw();
}
}
void Game::handleInput()
{
sf::Event event;
while (Global::window.pollEvent(event)) {
if (event.type == sf::Event::Closed) {
Global::window.close();
}
}
}
void Game::update()
{
sf::Time elapsed = m_clock.restart();
Global::stateManager.update(elapsed.asSeconds());
}
void Game::draw()
{
Global::window.clear(sf::Color::White);
Global::stateManager.render();
Global::window.display();
}