-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.cpp
57 lines (48 loc) · 1.2 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
#include "stdafx.h"
#include "Game.h"
#include "Editing.h"
#include "Debugger.h"
#include "Playing.h"
Game::Game() : mainWindow_(sf::VideoMode(SCREEN_WIDTH, SCREEN_HEIGHT, 32), "RPG"), level_(0), debug(false)
{
state_ = Playing::Instance();
}
Game* Game::instance_ = 0;
Game* Game::Instance()
{
if(instance_ == 0)
instance_ = new Game;
return instance_;
}
void Game::ChangeState(GameState* s)
{
state_=s;
}
void Game::HandleEvents()
{
state_->HandleEvents();
}
void Game::Update()
{
state_->Update();
}
void Game::Draw()
{
Game::Instance()->mainWindow_.clear();
state_->Draw();
if(debug) Debugger::Instance()->Draw(mainWindow_);
mainWindow_.display();
}
void Game::Loop()
{
//add lines to the static debugger every time (since they get overridden each loop)... probably a faster way to implement the debugger but this works for now.
while(mainWindow_.isOpen())
{
Debugger::Instance()->AddLine("Draw: " + std::to_string(gameClock.restart().asMicroseconds()));
HandleEvents();
Debugger::Instance()->AddLine("Event: " + std::to_string(gameClock.restart().asMicroseconds()));
Update();
Debugger::Instance()->AddLine("Update: " + std::to_string(gameClock.restart().asMicroseconds()));
Draw();
}
}