forked from jasonmaharjan/QuizmaHeros9000
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Games.cpp
65 lines (50 loc) · 1.67 KB
/
Games.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
#include "Games.hpp"
#include "SplashState.hpp"
#include <fstream>
#include "DEFINITIONS.hpp"
namespace Quizma
{
Games::Games(int width, int height, std::string title)
{
_data->window.create(sf::VideoMode(width, height), title, sf::Style::Close | sf::Style::Titlebar | sf::Style::Fullscreen);
_data->machine.AddState(StateRef(new SplashState(this->_data)));
//_data->music.openFromFile("Resources/glasgowkiss.wav");
_data->music1.openFromFile("Resources/song1.wav");
_data->music2.openFromFile("Resources/L Theme.wav");
_data->music3.openFromFile("Resources/song2.wav");
_data->buffer.loadFromFile("Resources/Choose.wav");
_data->font.loadFromFile("Resources/CENTAUR.ttf");
_data->text.setFont(this->_data->font);
for (int i = 0; i < 4; i++) {
_data->texts[i].setFont(this->_data->font);
}
_data->qa_vector.armQuestions();
this->Run();
}
void Games::Run()
{
float newTime, frameTime, interpolation;
float currentTime = this->_clock.getElapsedTime().asSeconds();
float accumulator = 0.0f;
while (this->_data->window.isOpen()) //main game loop
{
this->_data->machine.ProcessStateChanges();
newTime = this->_clock.getElapsedTime().asSeconds();
frameTime = newTime - currentTime;
if (frameTime > 0.05f)
{
frameTime = 0.05f;
}
currentTime = newTime;
accumulator += frameTime;
while (accumulator >= dt)
{
this->_data->machine.GetActiveState()->HandleInput();
this->_data->machine.GetActiveState()->Update(dt);
accumulator -= dt;
}
interpolation = accumulator / dt;
this->_data->machine.GetActiveState()->Draw(interpolation);
}
}
}