-
Notifications
You must be signed in to change notification settings - Fork 1
/
LevelManager.cpp
125 lines (94 loc) · 2.2 KB
/
LevelManager.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include "LevelManager.h"
LevelManager::LevelManager(int numLevels){
this->numLevels = numLevels;
this->currentLevel = 0;
for(int i = 0; i < numLevels; i++){
levels.push_back(new Level(i));
levels[i]->print();
}
splashOn = true;
}
LevelManager::~LevelManager(){
}
Level* LevelManager::getLevel(int i){
return levels[i];
}
Level* LevelManager::current(){
return levels[currentLevel];
}
void LevelManager::renderSplash(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glUseProgram(Level::bgShader->programID());
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-1.0, 1.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
GLint tex = glGetUniformLocation(Level::bgShader->programID(), "texture");
glUniform1i(tex, 0);
glActiveTexture(GL_TEXTURE0);
//splash.Bind();
current()->getSplash()->Bind();
GLint pos = glGetAttribLocation(Level::bgShader->programID(), "positionIn");
glBegin(GL_QUADS);
glVertexAttrib2f(pos, 1.0, -1.0);
glVertexAttrib2f(pos, 1.0, 1.0);
glVertexAttrib2f(pos, -1.0, 1.0);
glVertexAttrib2f(pos, -1.0, -1.0);
glEnd();
}
bool LevelManager::shouldShowSplashScreen(){
return splashOn;
}
void LevelManager::setSplash(bool s){
splashOn = s;
}
bool LevelManager::last(){
return currentLevel == numLevels - 1;
}
void LevelManager::setBodyEmitter(BodyEmitter* b){
emitter = b;
}
void LevelManager::setGameOver(bool over){
this->over = over;
splashOn = true;
}
void LevelManager::setWon(bool won){
this->won = won;
if(won){
currentLevel = numLevels + WIN_OFFSET;
}else{
currentLevel = numLevels + LOSE_OFFSET;
}
}
bool LevelManager::gameOver(){
return over;
}
void LevelManager::nextLevel(){
currentLevel++;
if(currentLevel == numLevels) {
currentLevel--;
}
if(currentLevel == numLevels + WIN_OFFSET){
setGameOver(true);
setWon(true);
}
emitter->setEmitSpeed(current()->speed);
setSplash(true);
}
void LevelManager::handleEvent(sf::Event &event, const sf::Input &input) {
switch (event.Type) {
case sf::Event::KeyPressed:
switch(event.Key.Code){
case sf::Key::L:
nextLevel();
printf("Current level is now %d\n", currentLevel);
break;
default:
break;
}
break;
default:
break;
}
}