-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathhighscores.cpp
112 lines (95 loc) · 3.07 KB
/
highscores.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
/* ************************************************************************* *
SDL-Ball - DX-Ball/Breakout remake with openGL and SDL for Linux
Copyright (C) 2008 Jimmy Christensen ( dusted at dusted dot dk )
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/>.
* ************************************************************************* */
class highScoreClass {
private:
string name;
textureManager texMgr;
textureClass tex;
public:
highScoreClass()
{
name="";
texMgr.load(useTheme("/gfx/highscore/entername.png",setting.gfxTheme), tex);
}
void draw()
{
glLoadIdentity();
glTranslatef(0,0,-3.0);
glColor4f(1,1,1,1);
glBindTexture(GL_TEXTURE_2D, tex.prop.texture);
glBegin( GL_QUADS );
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 0.5f, 0.0f );
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 0.5f, 0.0f );
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,-0.5f, 0.0f );
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,-0.5f, 0.0f );
glEnd( );
glColor4f(1,1,1,1);
glText->write(name, FONT_MENUHIGHSCORE, 1, 2.0, 0.0, 0.0);
}
void type(SDL_Event e, menuClass &menu)
{
if(var.showHighScores == 1)
{
if(e.key.keysym.sym == SDLK_ESCAPE)
{
var.showHighScores = 0;
initNewGame();
menu.refreshHighScoreList();
var.menu = 7;
return;
}
if(e.key.keysym.sym != SDLK_RETURN)
{
if(e.key.keysym.sym == SDLK_BACKSPACE)
{
if(name.length() > 0)
name.erase(name.length()-1);
} else {
name += e.key.keysym.sym;
}
} else {
var.showHighScores = 0;
ofstream hsList;
hsList.open(privFile.highScoreFile.data(), ios::out | ios::app);
hsList << "[" << player.level+1 << "]" << player.score << "|" << name << endl;
hsList.close();
initNewGame();
menu.refreshHighScoreList();
resumeGame();
var.titleScreenShow=1;
}
}
}
bool isHighScore()
{
int n;
int high=0;
struct score * slist = sortScores(&n);
for(int i = 0; i < n; i++)
{
if(player.score < slist[i].score)
{
high++;
}
}
if(n>0)
delete[] slist;
if(high < 20)
{
return(1);
}
return(0);
}
};