Debian Codegraph @

title.cpp

raw symbols SCIP
1 /* ************************************************************************* *
2 SDL-Ball - DX-Ball/Breakout remake with openGL and SDL for Linux
3 Copyright (C) 2008 Jimmy Christensen ( dusted at dusted dot dk )
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 * ************************************************************************* */
18
19 class powerupDescriptionClass : public moving_object {
20 public:
21 powerupDescriptionClass();
22 textureClass *tex;
23 void draw();
24 string name;
25 string description;
26 };
27
28 powerupDescriptionClass::powerupDescriptionClass()
29 {
30 width=0.055;
31 height=0.055;
32 }
33
34 void powerupDescriptionClass::draw()
35 {
36 tex->play();
37 glBindTexture( GL_TEXTURE_2D, tex->prop.texture);
38 glColor4f(tex->prop.glTexColorInfo[0],tex->prop.glTexColorInfo[1],tex->prop.glTexColorInfo[2],tex->prop.glTexColorInfo[3]);
39 glBegin( GL_QUADS );
40 glTexCoord2f(tex->pos[0],tex->pos[1]);glVertex3f( -width+posx, height+posy, 0.00 ); // øverst venst
41 glTexCoord2f(tex->pos[2],tex->pos[3]);glVertex3f( width+posx, height+posy, 0.00 ); // øverst højre
42 glTexCoord2f(tex->pos[4],tex->pos[5]);glVertex3f( width+posx,-height+posy, 0.00 ); // nederst højre
43 glTexCoord2f(tex->pos[6],tex->pos[7]);glVertex3f( -width+posx,-height+posy, 0.00 ); // nederst venstre
44 glEnd( );
45
46 glColor4f(1.0, 1.0, 1.0, 1.0);
47 //Write her
48 glText->write(name, FONT_INTRODESCRIPTION, 0, 1.0, posx+width, posy+(glText->getHeight(FONT_INTRODESCRIPTION)/2.0));
49 glText->write(description, FONT_INTRODESCRIPTION, 0, 1.0, posx+width, posy-(glText->getHeight(FONT_INTRODESCRIPTION)/2.0));
50 }
51
52 class titleScreenClass {
53 private:
54 effectManager *fxMan;
55 int ticksSinceLastSpawn;
56 textureManager texMgr;
57 textureClass texTitle;
58 textureClass *texPowerups;
59 GLuint glTitleList;
60 float rot;
61 bool rotDir;
62 powerupDescriptionClass powerUp[MAXPOTEXTURES];
63 int numHighScores; //Number of highscores to show in the intro
64 struct pos runnerPos;
65 menuClass *menu; //Here is the highscore text
66 int runnerTime;
67 float runnerVelX,runnerVelY;
68 int hilight;
69 bool hilightDir;
70 int hilightTime;
71 void readDescriptions(powerupDescriptionClass po[]);
72 public:
73 titleScreenClass(effectManager *m, textureClass tp[], menuClass *me);
74 void draw(int * frameAge, int * maxFrameAge);
75 };
76
77 titleScreenClass::titleScreenClass(effectManager *m, textureClass tp[], menuClass *me)
78 {
79 menu = me;
80 numHighScores=7;
81 texPowerups = tp;
82 fxMan = m;
83 ticksSinceLastSpawn=100;
84 texMgr.load(useTheme("/gfx/title/title.png",setting.gfxTheme), texTitle);
85 glTitleList = glGenLists(1);
86 glNewList(glTitleList, GL_COMPILE);
87 glBindTexture(GL_TEXTURE_2D, texTitle.prop.texture);
88 glBegin( GL_QUADS );
89 for(int i=0; i < 32; i++)
90 {
91 glColor4f(1,1,1,0.1);
92 glTexCoord2f(0.0, 0.0); glVertex3f(-1.2,1.15, 0.005*i );
93 glTexCoord2f(1.0, 0.0); glVertex3f( 1.2,1.15, 0.005*i );
94 glColor4f(0,0,1,0.00);
95 glTexCoord2f(1.0, 1.0); glVertex3f( 1.2, 0.75, 0.005*i );
96 glTexCoord2f(0.0, 1.0); glVertex3f(-1.2, 0.75, 0.005*i );
97 }
98 glEnd( );
99 glEndList();
100
101
102 for(int ii = 0; ii < 3; ii++)
103 {
104 for(int i=0; i < 7; i++)
105 {
106 powerUp[i+(7*ii)].tex = &texPowerups[i+(7*ii)];
107 powerUp[i+(7*ii)].posx = -1.5 + (0.8*ii);
108 powerUp[i+(7*ii)].posy = -0.35 - (0.135*i);
109 }
110 }
111 readDescriptions(powerUp);
112
113
114 runnerPos.x=0.0;
115 runnerPos.y=0.66;
116 runnerVelX = rndflt(2,1)+2;
117 runnerVelY = rndflt(2,1)+2;
118 runnerTime=0;
119
120 hilight=0;
121 hilightDir=1;
122 hilightTime=0;
123 }
124
125 int delta(int a, int b)
126 {
127 if(a >= b)
128 {
129 return(a-b);
130 } else {
131 return(b-a);
132 }
133 }
134
135 void titleScreenClass::draw(int * frameAge, int * maxFrameAge)
136 {
137 pos p,s;
138 if(*frameAge >= *maxFrameAge)
139 {
140 soundMan.play();
141
142 if(var.clearScreen)
143 {
144 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
145 }
146 glEnable(GL_TEXTURE_2D);
147
148 ticksSinceLastSpawn +=globalTicksSinceLastDraw;
149 if(ticksSinceLastSpawn > 125)
150 {
151 s.x = 3.25;
152 s.y = 0.525;
153 p.x = 0;
154 p.y = 1;
155
156 ticksSinceLastSpawn=0;
157 fxMan->set(FX_VAR_TYPE, FX_PARTICLEFIELD);
158 fxMan->set(FX_VAR_COLDET, 0);
159 fxMan->set(FX_VAR_LIFE, 1500);
160 fxMan->set(FX_VAR_NUM, 50);
161 fxMan->set(FX_VAR_SIZE, 0.01f);
162 fxMan->set(FX_VAR_SPEED, 0.0f);
163 fxMan->set(FX_VAR_GRAVITY, 0.0f);
164 fxMan->set(FX_VAR_RECTANGLE, s);
165 fxMan->set(FX_VAR_COLOR, 1.0f, 1.0f, 1.0f);
166 fxMan->spawn(p);
167 }
168 fxMan->draw();
169
170 int i;
171 glLoadIdentity();
172 glTranslatef(0.0, 0.0, -3.0);
173
174 for(i=0; i < MAXPOTEXTURES; i++)
175 {
176 powerUp[i].draw();
177 }
178
179 runnerTime+=globalTicksSinceLastDraw;
180 if(runnerTime>10)
181 {
182 fxMan->set(FX_VAR_TYPE, FX_SPARKS);
183 fxMan->set(FX_VAR_COLDET,0);
184 fxMan->set(FX_VAR_LIFE, 250);
185 fxMan->set(FX_VAR_NUM, 2);
186 fxMan->set(FX_VAR_SIZE, 0.09f);
187 fxMan->set(FX_VAR_SPEED, 0.5f);
188 fxMan->set(FX_VAR_GRAVITY, -0.4f);
189
190 fxMan->set(FX_VAR_COLOR, 1.0f, 0.7f, 0.0f);
191 fxMan->spawn(runnerPos);
192 fxMan->set(FX_VAR_COLOR, 1.0f, 0.8f, 0.0f);
193 fxMan->spawn(runnerPos);
194 fxMan->set(FX_VAR_COLOR, 1.0f, 0.9f, 0.0f);
195 fxMan->spawn(runnerPos);
196 fxMan->set(FX_VAR_COLOR, 1.0f, 1.0f, 0.0f);
197 fxMan->spawn(runnerPos);
198
199 runnerPos.x += runnerVelX*(runnerTime/1000.0);
200 runnerPos.y += runnerVelY*(runnerTime/1000.0);
201 if(runnerPos.x > 1.64 && runnerVelX > 0)
202 {
203 runnerVelX *= -1;
204 }
205 if(runnerPos.x < -1.64 && runnerVelX < 0)
206 {
207 runnerVelX *= -1;
208 }
209
210 if(runnerPos.y > 1.24 && runnerVelY > 0)
211 {
212 runnerVelY *= -1;
213 }
214
215 if(runnerPos.y < -1.24 && runnerVelY < 0)
216 {
217 runnerVelY *= -1;
218 }
219 runnerTime=0;
220 }
221
222 hilightTime += globalTicksSinceLastDraw;
223 if(hilightTime > 50)
224 {
225 if(hilightDir)
226 {
227 hilight++;
228 if(hilight == numHighScores*3)//-1)
229 {
230 hilight= numHighScores-1;
231 hilightDir=0;
232 }
233 } else {
234 hilight--;
235 if(hilight == -numHighScores*2)
236 {
237 hilightDir=1;
238 hilight=0;
239 }
240 }
241 hilightTime=0;
242 }
243
244 glTranslatef(0.0, 0.59, 0.0);
245 float a;
246 for(i=0; i < numHighScores; i++)
247 {
248 if((hilightDir && i < hilight+1) || (!hilightDir && i > hilight-1))
249 {
250 a=1.0-((1.0/(float)(numHighScores*2))*(delta(hilight,i)));
251 glColor4f(1,1,1,a);
252 glText->write(menu->highScores[i], FONT_INTROHIGHSCORE, 1, 1.0, 0.0, 0.0);
253 }
254 glTranslatef(0.0,-glText->getHeight(FONT_INTROHIGHSCORE),0.0);
255 }
256
257 //Draw the info string with website and version
258 glColor4f(1,1,0,1);
259 glText->write("Visit http://sdl-ball.sf.net/ for info, help and updates!", FONT_INTROHIGHSCORE, 1, 1.0, 0,0);
260
261 if(!rotDir)
262 {
263 rot += 0.01 * globalTicksSinceLastDraw;
264 if(rot > 40)
265 {
266 rotDir=1;
267 }
268 } else {
269 rot -= 0.01 * globalTicksSinceLastDraw;
270 if(rot < -40)
271 {
272 rotDir=0;
273 }
274 }
275 glLoadIdentity();
276
277 glTranslatef(0.0,0.0,-3.0);
278
279 glRotatef(20, 1,0,0);
280 glRotatef(rot, 0,1,0);
281 glCallList(glTitleList);
282
283 SDL_GL_SwapBuffers( );
284
285 globalTicksSinceLastDraw=0;
286 globalMilliTicksSinceLastDraw=0;
287 *frameAge = 0;
288
289 }
290 }
291
292
293 void titleScreenClass::readDescriptions(powerupDescriptionClass po[])
294 {
295 ifstream f;
296 string line;
297 int p=0;
298 bool flip=0;
299
300 f.open( useTheme("/powerupdescriptions.txt", setting.gfxTheme).data() );
301 if(f.is_open())
302 {
303 while(!f.eof())
304 {
305 getline(f, line);
306 if(!flip)
307 {
308 flip=1;
309 po[p].name=line;
310 } else {
311 flip=0;
312 po[p].description=line;
313 p++;
314 }
315 if(p == MAXPOTEXTURES)
316 break;
317 }
318 f.close();
319 } else {
320 cout << "Could not open powerupdescriptions"<<endl;
321 }
322 }
323