-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.cpp
More file actions
57 lines (43 loc) · 952 Bytes
/
Copy pathGame.cpp
File metadata and controls
57 lines (43 loc) · 952 Bytes
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
#include "Game.hpp"
using namespace console;
Game* Game::instance_ = nullptr;
Game::Game()
{
Game::instance_ = this;
}
Game::~Game()
{
}
void Game::run()
{
// Check controller
controller_->check();
// Check timers
for (auto& timer : timers_)
{
timer.check();
}
// Check sounds
sound_->check();
}
void Game::setDisplay(Display* display)
{
display_ = display;
display_->clear();
}
void Game::setController(Controller* controller)
{
controller_ = controller;
controller_->setCallback(std::bind(&Game::onEvent, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
controller_->init();
}
void Game::setSound(Sound* sound)
{
sound_ = sound;
sound_->init();
}
Timer* Game::createTimer(unsigned long int period, std::function<void()> callback, bool one_shoot)
{
timers_.push_back(Timer(period, callback, one_shoot));
return &timers_.back();
}