-
Notifications
You must be signed in to change notification settings - Fork 0
/
gameover.cpp
executable file
·104 lines (91 loc) · 2.81 KB
/
gameover.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
/*
* Copyright (C) 2011-2012 Michal Hozza ([email protected])
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "gameover.h"
#include "GL/glut.h"
#include "menuroom.h"
#include <iostream>
//#include <cstring>
GameOver::GameOver(Room* parent, int score)
:parent(parent), score(score), info(false),
gameOverStringW(0), scoreStringW(0), infoStringW(0)
{
z = -10;
speedZ = 0.2;
gameOverString = "Game Over";
infoString = "Press ESC to show menu";
scoreStream << "Score: " << score;
//zrataj sirky stringov
for (unsigned i=0;i<gameOverString.size();i++)
gameOverStringW+=glutStrokeWidth(GLUT_STROKE_ROMAN,gameOverString[i]);
for (unsigned i=0;i<scoreStream.str().size();i++)
scoreStringW+=glutStrokeWidth(GLUT_STROKE_ROMAN,scoreStream.str()[i]);
for (unsigned i=0;i<infoString.size();i++)
infoStringW+=glutStrokeWidth(GLUT_STROKE_ROMAN,infoString[i]);
Keyboard::getInstance()->registerAction(this,0,27,false);
}
void GameOver::draw()
{
//glDisable(GL_LIGHTING);
glDisable(GL_TEXTURE_2D);
glLineWidth(2.0);
glPointSize(1);
glPushMatrix();
glColor4i(1,1,1,1);
glPushMatrix();
glScalef(0.004,0.004,1);
glTranslatef(-gameOverStringW/2.0,0,-4);
//glRotatef(30,1,0,0);
for (unsigned i=0;i<gameOverString.size();i++)
glutStrokeCharacter(GLUT_STROKE_ROMAN,gameOverString[i]);
glPopMatrix();
if(info)
{
glPushMatrix();
glScalef(0.002,0.002,1);
glTranslatef(-scoreStringW/2.0,-300,-4);
for (unsigned i=0;i<scoreStream.str().size();i++)
glutStrokeCharacter(GLUT_STROKE_ROMAN,scoreStream.str()[i]);
glPopMatrix();
glPushMatrix();
glScalef(0.002,0.002,1);
glTranslatef(-infoStringW/2.0,-600,-4);
for (unsigned i=0;i<infoString.size();i++)
glutStrokeCharacter(GLUT_STROKE_ROMAN,infoString[i]);
glPopMatrix();
}
glPopMatrix();
//glEnable(GL_LIGHTING);
glEnable(GL_TEXTURE_2D);
//glEnable(GL_FOG);
}
void GameOver::step()
{
GameObject::step();
if(z>=0)
{
speedZ = 0;
info = true;
}
}
void GameOver::action(int actionID)
{
if (actionID==0)
{
Keyboard::getInstance()->clearActions();
Renderer::getInstance()->setRoom(new MenuRoom(parent->getParent(),WINDOW_W,WINDOW_H));
}
}