-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLD36.cpp
More file actions
66 lines (58 loc) · 1.61 KB
/
LD36.cpp
File metadata and controls
66 lines (58 loc) · 1.61 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
55
56
57
58
59
60
61
62
63
64
65
66
#include "LD36.hpp"
#include "Level.hpp"
#include "EndScene.hpp"
#include <Engine/Factory.hpp>
#include <Engine/util/Random.hpp>
LD36::LD36(): Game(1024, 576), m_currentLevel(0) {
m_windowTitle = "Pyramid Builder - LD36: Ancient Technology";
Level* level;
m_scene = level = engine::Factory::create<Level>("assets/scripts/level.json", this);
level->SetPyramid(0);
auto ufo = level->GetChildByID("ufo");
level->DestroyParticles(ufo);
level->MakePart(ufo);
m_window.setKeyRepeatEnabled(false);
}
LD36::~LD36() {
}
void LD36::Restart(float score) {
RegisterScore(score);
Level* level = engine::Factory::create<Level>("assets/scripts/level.json", this);
if (!level->SetPyramid(m_currentLevel)) {
delete level;
EndScene* end = engine::Factory::create<EndScene>("assets/scripts/end.json", this, m_scores);
m_loadingScene.Switch(m_scene, end);
} else {
auto ufo = level->GetChildByID("ufo");
level->DestroyParticles(ufo);
level->MakePart(ufo);
m_loadingScene.Switch(m_scene, level);
}
m_scene = &m_loadingScene;
}
void LD36::Next(float score) {
RegisterScore(score);
m_currentLevel++;
Restart();
}
std::vector<float>& LD36::GetScores() {
return m_scores;
}
void LD36::RestartGame() {
m_scores.clear();
m_currentLevel = 0;
Restart(-1);
}
void LD36::RegisterScore(float score) {
if (score == -1.0f) return;
if (m_currentLevel >= m_scores.size()) {
m_scores.resize(m_currentLevel + 1);
if (score == -1.0f) {
m_scores[m_currentLevel] = std::numeric_limits<float>::max();
} else {
m_scores[m_currentLevel] = score;
}
} else if (score < m_scores[m_currentLevel]) {
m_scores[m_currentLevel] = score;
}
}