summaryrefslogtreecommitdiff
authorandyq <andyq>2002-12-07 18:07:27 (UTC)
committer andyq <andyq>2002-12-07 18:07:27 (UTC)
commit25debd07f03e4a1b21047ee5d49a3dd811d8352a (patch) (unidiff)
treec25eaa7d0423e733772412bf097e1ab577362fc0
parent2e00687f66fadd9cc4c0f564b5f8ba108084d619 (diff)
downloadopie-25debd07f03e4a1b21047ee5d49a3dd811d8352a.zip
opie-25debd07f03e4a1b21047ee5d49a3dd811d8352a.tar.gz
opie-25debd07f03e4a1b21047ee5d49a3dd811d8352a.tar.bz2
Added dificculty levels to Fly and Gates, bug fixes (height checking), added help menu option and other features
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/sfcave/sfcave.cpp477
-rw-r--r--noncore/games/sfcave/sfcave.h26
2 files changed, 372 insertions, 131 deletions
diff --git a/noncore/games/sfcave/sfcave.cpp b/noncore/games/sfcave/sfcave.cpp
index 8b9c844..788606f 100644
--- a/noncore/games/sfcave/sfcave.cpp
+++ b/noncore/games/sfcave/sfcave.cpp
@@ -1,318 +1,488 @@
1#include <stdio.h> 1#include <stdio.h>
2#include <stdlib.h> 2#include <stdlib.h>
3#include <math.h> 3#include <math.h>
4 4
5#ifdef QWS 5#ifdef QWS
6#include <qpe/qpeapplication.h> 6#include <qpe/qpeapplication.h>
7#include <qpe/config.h> 7#include <qpe/config.h>
8#else 8#else
9#include <qapplication.h> 9#include <qapplication.h>
10#endif 10#endif
11 11
12#include "helpwindow.h"
12#include "sfcave.h" 13#include "sfcave.h"
13 14
14#define CAPTION "SFCave 1.7 by AndyQ" 15#define CAPTION "SFCave 1.8 by AndyQ"
16
17#define UP_THRUST 0.6
18#define NO_THRUST 0.8
19#define MAX_DOWN_THRUST 4.0
20#define MAX_UP_THRUST -3.5
15 21
16// States 22// States
17#define STATE_BOSS 0 23#define STATE_BOSS 0
18#define STATE_RUNNING 1 24#define STATE_RUNNING 1
19#define STATE_CRASHED 2 25#define STATE_CRASHING 2
20#define STATE_NEWGAME 3 26#define STATE_CRASHED 3
21#define STATE_MENU 4 27#define STATE_NEWGAME 4
28#define STATE_MENU 5
22 29
23// Menus 30// Menus
24#define MENU_MAIN_MENU 0 31#define MENU_MAIN_MENU 0
25#define MENU_OPTIONS_MENU 1 32#define MENU_OPTIONS_MENU 1
26 33
27// Main Menu Options 34// Main Menu Options
28#define MENU_START_GAME 0 35#define MENU_START_GAME 0
29#define MENU_OPTIONS 1 36#define MENU_OPTIONS 1
30#define MENU_QUIT 2 37#define MENU_HELP 2
38#define MENU_QUIT 3
31 39
32// Option Menu Options 40// Option Menu Options
33#define MENU_GAME_TYPE 0 41#define MENU_GAME_TYPE 0
34#define MENU_GAME_DIFFICULTY 1 42#define MENU_GAME_DIFFICULTY 1
35#define MENU_BACK 2 43#define MENU_CLEAR_HIGHSCORES 2
36 44#define MENU_BACK 3
37QString SFCave::menuOptions[2][5] = { { "Start Game", "Options", "Quit", "", "" },
38 { "Game Type - %s", "Game Difficulty - %s", "Back", "", "" } };
39 45
40 46
41#define NR_GAME_DIFFICULTIES 3 47#define NR_GAME_DIFFICULTIES 3
42#define NR_GAME_TYPES 3 48#define NR_GAME_TYPES 3
43 49
50#define DIFICULTY_EASY 0
51#define DIFICULTY_NORMAL 1
52#define DIFICULTY_HARD 2
44#define EASY "Easy" 53#define EASY "Easy"
45#define NORMAL "Normal" 54#define NORMAL "Normal"
46#define HARD "Hard" 55#define HARD "Hard"
47 56
48#define SFCAVE_GAME_TYPE 0 57#define SFCAVE_GAME_TYPE 0
49#define GATES_GAME_TYPE 1 58#define GATES_GAME_TYPE 1
50#define FLY_GAME_TYPE 2 59#define FLY_GAME_TYPE 2
51#define SFCAVE_GAME "SFCave" 60#define SFCAVE_GAME "SFCave"
52#define GATES_GAME "Gates" 61#define GATES_GAME "Gates"
53#define FLY_GAME "Fly" 62#define FLY_GAME "Fly"
63#define CURRENT_GAME_TYPE gameTypes[currentGameType]
64#define CURRENT_GAME_DIFFICULTY difficultyOption[currentGameDifficulty];
65
54QString SFCave::dificultyOption[] = { EASY, NORMAL, HARD }; 66QString SFCave::dificultyOption[] = { EASY, NORMAL, HARD };
55QString SFCave::gameTypes[] = { SFCAVE_GAME, GATES_GAME, FLY_GAME }; 67QString SFCave::gameTypes[] = { SFCAVE_GAME, GATES_GAME, FLY_GAME };
56 68
57#define CURRENT_GAME_TYPE gameTypes[currentGameType] 69QString SFCave::menuOptions[2][5] = { { "Start Game", "Options", "Help", "Quit", "" },
58#define CURRENT_GAME_DIFFICULTY difficultyOption[currentGameDifficulty]; 70 { "Game Type - %s", "Game Difficulty - %s", "Clear High Scores for this game", "Back", "" } };
71
72#define UP_THRUST 0.6
73#define NO_THRUST 0.8
74#define MAX_DOWN_THRUST 4.0
75#define MAX_UP_THRUST -3.5
76double SFCave::UpThrustVals[3][3] = {{ 0.6, 0.6, 0.6 }, // SFCave
77 { 0.6, 0.6, 0.8 }, // Gates
78 { 0.4, 0.7, 1.0 } }; // Fly
79
80double SFCave::DownThrustVals[3][3] = {{ 0.8, 0.8, 0.8 }, // SFCave
81 { 0.8, 0.8, 1.0 }, // Gates
82 { 0.4, 0.7, 1.0 } }; // Fly
83
84double SFCave::MaxUpThrustVals[3][3] = {{ -3.5, -3.5, -3.5 }, // SFCave
85 { -3.5, -4.0, -5.0 }, // Gates
86 { -3.5, -4.0, -5.0 } }; // Fly
87
88double SFCave::MaxDownThrustVals[3][3] = {{ 4.0, 4.0, 4.0 }, // SFCave
89 { 4.0, 5.0, 5.5 }, // Gates
90 { 3.5, 4.0, 5.0 } }; // Fly
91
92int SFCave::initialGateGaps[] = { 75, 50, 25 };
93
94int SFCave::nrMenuOptions[2] = { 4, 4 };
95int SFCave ::currentMenuOption[2] = { 0, 0 };
59 96
60bool movel; 97bool movel;
61 98
62 99
63int main( int argc, char *argv[] ) 100int main( int argc, char *argv[] )
64{ 101{
65 movel = true; 102 movel = true;
66
67#ifdef QWS 103#ifdef QWS
68 QPEApplication a( argc, argv ); 104 QPEApplication a( argc, argv );
69#else 105#else
70 QApplication a( argc, argv ); 106 QApplication a( argc, argv );
71#endif 107#endif
72 108
73 int speed = 3; 109 int speed = 3;
74 for ( int i = 0 ; i < argc ; ++i ) 110 for ( int i = 0 ; i < argc ; ++i )
75 { 111 {
76 if ( strcmp( argv[i], "-s" ) == 0 ) 112 if ( strcmp( argv[i], "-s" ) == 0 )
77 { 113 {
78 if ( i+1 < argc ) 114 if ( i+1 < argc )
79 speed = atoi( argv[i+1] ); 115 speed = atoi( argv[i+1] );
80 } 116 }
81 } 117 }
82 118
83 SFCave app( speed ); 119 SFCave app( speed );
84 a.setMainWidget( &app ); 120 a.setMainWidget( &app );
85 app.show(); 121 app.show();
86 app.start(); 122 app.start();
87 a.exec(); 123 a.exec();
88} 124}
89 125
90SFCave :: SFCave( int spd, QWidget *w, char *name ) 126SFCave :: SFCave( int spd, QWidget *w, char *name )
91 : QMainWindow( w, name ) 127 : QMainWindow( w, name )
92 128
93{ 129{
94#ifdef QWS 130#ifdef QWS
95 showMaximized(); 131 showMaximized();
96#else 132#else
97 resize( 240, 284 ); 133 resize( 240, 284 );
98#endif 134#endif
99 135
100 sWidth = width(); 136 sWidth = width();
101 sHeight = height(); 137 sHeight = height();
102 segSize = sWidth/(MAPSIZE-1)+1; 138 segSize = sWidth/(MAPSIZE-1)+1;
103 139
104 currentMenuNr = 0; 140 currentMenuNr = 0;
105 nrMenuOptions[0] = 3;
106 nrMenuOptions[1] = 3;
107 currentMenuOption[0] = 0;
108 currentMenuOption[1] = 0;
109 currentGameType = 0; 141 currentGameType = 0;
110 currentGameDifficulty = 0; 142 currentGameDifficulty = 0;
111 143
112 setCaption( CAPTION ); 144 setCaption( CAPTION );
145 showScoreZones = false;
113 146
114#ifdef QWS 147#ifdef QWS
115 Config cfg( "sfcave" ); 148 Config cfg( "sfcave" );
116 cfg.setGroup( "settings" ); 149 cfg.setGroup( "settings" );
117 QString key = "highScore_"; 150 QString key = "highScore_";
118 highestScore[SFCAVE_GAME_TYPE] = cfg.readNumEntry( key + SFCAVE_GAME, 0 ); 151
119 highestScore[GATES_GAME_TYPE] = cfg.readNumEntry( key + GATES_GAME, 0 ); 152 for ( int i = 0 ; i < 3 ; ++i )
120 highestScore[FLY_GAME_TYPE] = cfg.readNumEntry( key + FLY_GAME, 0 ); 153 {
154 for ( int j = 0 ; j < 3 ; ++j )
155 highestScore[i][j] = cfg.readNumEntry( key + gameTypes[i] + "_" + dificultyOption[j], 0 );
156 }
157
121 currentGameType = cfg.readNumEntry( "gameType", 0 ); 158 currentGameType = cfg.readNumEntry( "gameType", 0 );
122 currentGameDifficulty = cfg.readNumEntry( "difficulty", 0 ); 159 currentGameDifficulty = cfg.readNumEntry( "difficulty", 0 );
123#endif 160#endif
124 speed = spd; // Change to 2 for PC 161 speed = spd; // Change to 2 for PC
125 press = false; 162 press = false;
126 163
127 offscreen = new QPixmap( sWidth, sHeight ); 164 offscreen = new QPixmap( sWidth, sHeight );
128 offscreen->fill( Qt::black ); 165 offscreen->fill( Qt::black );
129 166
130 setUp(); 167 setUp();
131 crashLineLength = -1; 168 crashLineLength = -1;
132 169
133 gameTimer = new QTimer( this, "game timer" ); 170 gameTimer = new QTimer( this, "game timer" );
134 connect( gameTimer, SIGNAL( timeout() ), 171 connect( gameTimer, SIGNAL( timeout() ),
135 this, SLOT( run() ) ); 172 this, SLOT( run() ) );
136} 173}
137 174
138SFCave :: ~SFCave() 175SFCave :: ~SFCave()
139{ 176{
140} 177}
141 178
142void SFCave :: start() 179void SFCave :: start()
143{ 180{
144 gameTimer->start( 10 ); 181 gameTimer->start( 10 );
145 182
146} 183}
147 184
148int SFCave :: nextInt( int range ) 185int SFCave :: nextInt( int range )
149{ 186{
150 return rand() % range; 187 return rand() % range;
151} 188}
152 189
153void SFCave :: setUp() 190void SFCave :: setUp()
154{ 191{
155 state = STATE_MENU; 192 state = STATE_MENU;
156 prevState = STATE_MENU; 193 prevState = STATE_MENU;
157 194
158 score = 0; 195 score = 0;
159 offset = 0; 196 offset = 0;
160 maxHeight = 50;
161 nrFrames = 0; 197 nrFrames = 0;
162 dir = 1; 198 dir = 1;
163 thrust = 0; 199 thrust = 0;
200
201 if ( CURRENT_GAME_TYPE == SFCAVE_GAME )
202 {
203 thrustUp = UpThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];;
204 noThrust = DownThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];;
205 maxUpThrust = MaxUpThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];;
206 maxDownThrust = MaxDownThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];;
207 }
208 else if ( CURRENT_GAME_TYPE == GATES_GAME )
209 {
210 thrustUp = UpThrustVals[GATES_GAME_TYPE][currentGameDifficulty];;
211 noThrust = DownThrustVals[GATES_GAME_TYPE][currentGameDifficulty];;
212 maxUpThrust = MaxUpThrustVals[GATES_GAME_TYPE][currentGameDifficulty];;
213 maxDownThrust = MaxDownThrustVals[GATES_GAME_TYPE][currentGameDifficulty];;
214 }
215 else
216 {
217 thrustUp = UpThrustVals[FLY_GAME_TYPE][currentGameDifficulty];
218 noThrust = DownThrustVals[FLY_GAME_TYPE][currentGameDifficulty];
219 maxUpThrust = MaxUpThrustVals[FLY_GAME_TYPE][currentGameDifficulty];
220 maxDownThrust = MaxDownThrustVals[FLY_GAME_TYPE][currentGameDifficulty];
221 }
222
164 crashLineLength = 0; 223 crashLineLength = 0;
165 224
166 user.setRect( 50, sWidth/2, 4, 4 ); 225 user.setRect( 50, sWidth/2, 4, 4 );
167 226
168 blockWidth = 20; 227 blockWidth = 20;
169 blockHeight = 70; 228 blockHeight = 70;
170 gapHeight = 125; 229 gapHeight = initialGateGaps[currentGameDifficulty];
171 gateDistance = 75; 230 gateDistance = 75;
172 nextGate = nextInt( 50 ) + gateDistance; 231 nextGate = nextInt( 50 ) + gateDistance;
173 232
174 for ( int i = 0 ; i < TRAILSIZE ; ++i ) 233 for ( int i = 0 ; i < TRAILSIZE ; ++i )
175 { 234 {
176 trail[i].setX( -1 ); 235 trail[i].setX( -1 );
177 trail[i].setY( 0 ); 236 trail[i].setY( 0 );
178 } 237 }
179 238
180 mapTop[0] = (int)(nextInt(50)) + 5; 239 if ( CURRENT_GAME_TYPE != FLY_GAME )
181 for ( int i = 1 ; i < MAPSIZE ; ++i ) 240 {
182 setPoint( i ); 241 maxHeight = 50;
242
243 mapTop[0] = (int)(nextInt(50)) + 5;
244 mapBottom[0] = (int)(nextInt(50)) + 5;
245 for ( int i = 1 ; i < MAPSIZE ; ++i )
246 setPoint( i );
247 }
248 else
249 {
250 maxHeight = 100;
183 251
252 for ( int i = 0 ; i < MAPSIZE ; ++i )
253 mapBottom[i] = sHeight - 10;
254 }
184 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 255 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
185 blocks[i].setY( -1 ); 256 blocks[i].setY( -1 );
186} 257}
187 258
188void SFCave :: run() 259void SFCave :: run()
189{ 260{
190 //running = true; 261 switch ( state )
191 //setUp(); 262 {
192 switch ( state ) 263 case STATE_MENU:
264 displayMenu();
265 break;
266 case STATE_NEWGAME:
267 setUp();
268 draw();
269 state = STATE_RUNNING;
270 break;
271 case STATE_BOSS:
272 drawBoss();
273 break;
274
275 case STATE_CRASHING:
276 case STATE_CRASHED:
277 draw();
278 break;
279
280 case STATE_RUNNING:
193 { 281 {
194 case STATE_MENU: 282 if ( nrFrames % 2 == 0 )
195 displayMenu(); 283 handleKeys();
196 break; 284
197 case STATE_NEWGAME: 285 // Apply Game rules
198 setUp(); 286 nrFrames ++;
199 draw(); 287 if ( CURRENT_GAME_TYPE == SFCAVE_GAME )
200 state = STATE_RUNNING; 288 handleGameSFCave();
201 break; 289 else if ( CURRENT_GAME_TYPE == GATES_GAME )
202 case STATE_BOSS: 290 handleGameGates();
203 drawBoss(); 291 else if ( CURRENT_GAME_TYPE == FLY_GAME )
204 break; 292 handleGameFly();
293
294 draw();
295 break;
296 }
297 }
298}
205 299
206 case STATE_CRASHED: 300void SFCave :: handleGameSFCave()
207 draw(); 301{
208 break; 302 // Update score
303 if ( nrFrames % 5 == 0 )
304 score ++;
209 305
210 case STATE_RUNNING: 306 if ( nrFrames % 500 == 0 )
211 { 307 {
212 if ( nrFrames % 5 == 0 ) 308 if ( maxHeight < sHeight - 100 )
213 score ++; 309 {
214 if ( nrFrames % 2 == 0 ) 310 maxHeight += 10;
215 handleKeys();
216
217 // Apply Game rules
218 nrFrames ++;
219 if ( CURRENT_GAME_TYPE == SFCAVE_GAME )
220 {
221 if ( nrFrames % 500 == 0 )
222 {
223 if ( maxHeight < sHeight - 100 )
224 {
225 maxHeight += 10;
226
227 // Reduce block height
228 if ( maxHeight > sHeight - 150 )
229 blockHeight -= 5;
230 }
231 }
232 311
233 if ( nrFrames % 100 == 0 ) 312 // Reduce block height
234 addBlock(); 313 if ( maxHeight > sHeight - 150 )
235 } 314 blockHeight -= 5;
236 else if ( CURRENT_GAME_TYPE == GATES_GAME ) 315 }
237 { 316 }
238 // Slightly random gap distance
239 if ( nrFrames >= nextGate )
240 {
241 nextGate = nrFrames + nextInt( 50 ) + gateDistance;
242 addGate();
243 }
244 317
245 if ( nrFrames % 500 == 0 ) 318 if ( nrFrames % 100 == 0 )
246 { 319 addBlock();
247 if ( gapHeight > 75 )
248 gapHeight -= 5;
249 }
250 }
251 else if ( CURRENT_GAME_TYPE == FLY_GAME )
252 {
253 }
254
255
256 if ( checkCollision() )
257 {
258 if ( score > highestScore[currentGameType] )
259 highestScore[currentGameType] = score;
260 320
261#ifdef QWS 321 if ( checkCollision() )
262 Config cfg( "sfcave" ); 322 {
263 cfg.setGroup( "settings" ); 323 if ( score > highestScore[currentGameType][currentGameDifficulty] )
264 QString key = "highScore_"; 324 {
265 key += CURRENT_GAME_TYPE; 325 highestScore[currentGameType][currentGameDifficulty] = score;
266 cfg.writeEntry( key, highestScore[currentGameType] ); 326 saveScore();
267#endif 327 }
328 state = STATE_CRASHING;
329 }
330 else
331 {
332 moveLandscape();
333 }
268 334
269 state = STATE_CRASHED; 335}
270 }
271 else
272 {
273 if ( movel )
274 moveLandscape();
275 //movel = false;
276 }
277 336
278 draw(); 337
279 break; 338void SFCave :: handleGameGates()
280 } 339{
340 // Update score
341 if ( nrFrames % 5 == 0 )
342 score ++;
343
344 // Slightly random gap distance
345 if ( nrFrames >= nextGate )
346 {
347 nextGate = nrFrames + nextInt( 50 ) + gateDistance;
348 addGate();
349 }
350
351 if ( nrFrames % 500 == 0 )
352 {
353 if ( gapHeight > 75 )
354 gapHeight -= 5;
355 }
356
357 if ( checkCollision() )
358 {
359 if ( score > highestScore[currentGameType][currentGameDifficulty] )
360 {
361 highestScore[currentGameType][currentGameDifficulty] = score;
362 saveScore();
363 }
364 state = STATE_CRASHING;
365 }
366 else
367 {
368 moveLandscape();
369 }
370
371}
372
373void SFCave :: handleGameFly()
374{
375 if ( nrFrames % 4 == 0 )
376 {
377 // Update score
378 // get distance between landscape and ship
379 int diff = mapBottom[10] - user.y();
380
381 // the closer the difference is to 0 means more points
382 if ( diff < 10 )
383 score += 5;
384 else if ( diff < 20 )
385 score += 3;
386 else if ( diff < 30 )
387 score += 2;
388 else if ( diff < 40 )
389 score += 1;
390 }
391
392 if ( checkFlyGameCollision() )
393 {
394 if ( score > highestScore[currentGameType][currentGameDifficulty] )
395 {
396 highestScore[currentGameType][currentGameDifficulty] = score;
397 saveScore();
281 } 398 }
399 state = STATE_CRASHING;
400 }
401 else
402 {
403 moveFlyGameLandscape();
404 }
405}
406
407bool SFCave :: checkFlyGameCollision()
408{
409 if ( (user.y() + user.width()) >= mapBottom[11] )
410 return true;
411
412 return false;
413}
414
415void SFCave :: moveFlyGameLandscape()
416{
417 offset++;
418
419 if ( offset >= segSize )
420 {
421 offset = 0;
422 for ( int i = 0 ; i < MAPSIZE-speed ; ++i )
423 mapBottom[i] = mapBottom[i+speed];
424
425 for ( int i = speed ; i > 0 ; --i )
426 setFlyPoint( MAPSIZE-i );
427 }
428}
429
430void SFCave :: setFlyPoint( int point )
431{
432 static int fly_difficulty_levels[] = { 5, 10, 15 };
433 if ( nextInt(100) >= 75 )
434 dir *= -1;
435
436 int prevPoint = mapBottom[point-1];
437
438 int nextPoint = prevPoint + (dir * nextInt( fly_difficulty_levels[currentGameDifficulty] ) );
439
440 if ( nextPoint > sHeight )
441 {
442 nextPoint = sHeight;
443 dir *= -1;
444 }
445 else if ( nextPoint < maxHeight )
446 {
447 nextPoint = maxHeight;
448 dir *= 1;
449 }
450
451 mapBottom[point] = nextPoint;
282} 452}
283 453
284bool SFCave :: checkCollision() 454bool SFCave :: checkCollision()
285{ 455{
286 if ( (user.y() + user.width()) >= mapBottom[10] || user.y() <= mapTop[10] ) 456 if ( (user.y() + user.width()) >= mapBottom[11] || user.y() <= mapTop[11] )
287 return true; 457 return true;
288 458
289 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 459 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
290 { 460 {
291 if ( blocks[i].y() != -1 ) 461 if ( blocks[i].y() != -1 )
292 { 462 {
293 if ( blocks[i].intersects( user ) ) 463 if ( blocks[i].intersects( user ) )
294 return true; 464 return true;
295 } 465 }
296 } 466 }
297 return false; 467 return false;
298} 468}
299 469
300void SFCave :: moveLandscape() 470void SFCave :: moveLandscape()
301{ 471{
302 offset++; 472 offset++;
303 473
304 if ( offset >= segSize ) 474 if ( offset >= segSize )
305 { 475 {
306 offset = 0; 476 offset = 0;
307 for ( int i = 0 ; i < MAPSIZE-speed ; ++i ) 477 for ( int i = 0 ; i < MAPSIZE-speed ; ++i )
308 { 478 {
309 mapTop[i] = mapTop[i+speed]; 479 mapTop[i] = mapTop[i+speed];
310 mapBottom[i] = mapBottom[i+speed]; 480 mapBottom[i] = mapBottom[i+speed];
311 } 481 }
312 482
313 for ( int i = speed ; i > 0 ; --i ) 483 for ( int i = speed ; i > 0 ; --i )
314 setPoint( MAPSIZE-i ); 484 setPoint( MAPSIZE-i );
315 } 485 }
316 486
317 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 487 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
318 { 488 {
@@ -321,214 +491,234 @@ void SFCave :: moveLandscape()
321 blocks[i].moveBy( -speed, 0 ); 491 blocks[i].moveBy( -speed, 0 );
322 if ( blocks[i].x() + blocks[i].width() < 0 ) 492 if ( blocks[i].x() + blocks[i].width() < 0 )
323 blocks[i].setY( -1 ); 493 blocks[i].setY( -1 );
324 } 494 }
325 } 495 }
326} 496}
327 497
328void SFCave :: addBlock() 498void SFCave :: addBlock()
329{ 499{
330 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 500 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
331 { 501 {
332 if ( blocks[i].y() == -1 ) 502 if ( blocks[i].y() == -1 )
333 { 503 {
334 int x = sWidth; 504 int x = sWidth;
335 505
336 int y = mapTop[50] + (int)(nextInt(mapBottom[50] - mapTop[50] - blockHeight)); 506 int y = mapTop[50] + (int)(nextInt(mapBottom[50] - mapTop[50] - blockHeight));
337 507
338 blocks[i].setRect( x, y, blockWidth, blockHeight ); 508 blocks[i].setRect( x, y, blockWidth, blockHeight );
339 509
340 break; 510 break;
341 } 511 }
342 } 512 }
343} 513}
344 514
345void SFCave :: addGate() 515void SFCave :: addGate()
346{ 516{
347 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 517 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
348 { 518 {
349 if ( blocks[i].y() == -1 ) 519 if ( blocks[i].y() == -1 )
350 { 520 {
351 int x1 = sWidth; 521 int x1 = sWidth;
352 int y1 = mapTop[50]; 522 int y1 = mapTop[50];
353 int b1Height = nextInt(mapBottom[50] - mapTop[50] - gateDistance); 523 int b1Height = nextInt(mapBottom[50] - mapTop[50] - gapHeight);
354 524
355 // See if height between last gate and this one is too big 525 // See if height between last gate and this one is too big
356 if ( b1Height - 200 > lastGateBottomY ) 526 if ( b1Height - 200 > lastGateBottomY )
357 b1Height -= 25; 527 b1Height -= 25;
358 else if ( b1Height + 200 < lastGateBottomY ) 528 else if ( b1Height + 200 < lastGateBottomY )
359 b1Height += 25; 529 b1Height += 25;
360 lastGateBottomY = b1Height; 530 lastGateBottomY = b1Height;
361 531
362 int x2 = sWidth; 532 int x2 = sWidth;
363 int y2 = y1 + b1Height + gateDistance; 533 int y2 = y1 + b1Height + gapHeight;
364 int b2Height = mapBottom[50] - y2; 534 int b2Height = mapBottom[50] - y2;
365 535
366 536
367 blocks[i].setRect( x1, y1, blockWidth, b1Height ); 537 blocks[i].setRect( x1, y1, blockWidth, b1Height );
368 blocks[i+1].setRect( x2, y2, blockWidth, b2Height ); 538 blocks[i+1].setRect( x2, y2, blockWidth, b2Height );
369 539
370 break; 540 break;
371 } 541 }
372 } 542 }
373} 543}
374 544
375void SFCave :: setPoint( int point ) 545void SFCave :: setPoint( int point )
376{ 546{
377 if ( nextInt(100) >= 80 ) 547 if ( nextInt(100) >= 80 )
378 dir *= -1; 548 dir *= -1;
379 549
380 mapTop[point] = mapTop[point-1] + (dir * nextInt( 5 ) ); 550 mapTop[point] = mapTop[point-1] + (dir * nextInt( 5 ) );
381 if ( mapTop[point] < 0 ) 551 if ( mapTop[point] < 0 )
382 { 552 {
383 mapTop[point] = 0; 553 mapTop[point] = 0;
384 dir *= -1; 554 dir *= -1;
385 } 555 }
386 else if ( mapTop[point] >= maxHeight ) 556 else if ( mapTop[point] >= maxHeight )
387 { 557 {
388 mapTop[point] = maxHeight; 558 mapTop[point] = maxHeight;
389 dir *= -1; 559 dir *= -1;
390 } 560 }
391 561
392 mapBottom[point] = sHeight - (maxHeight - mapBottom[point]); 562// mapBottom[point] = sHeight - (maxHeight - mapBottom[point]);
393 mapBottom[point] = sHeight - (maxHeight - mapTop[point]); 563 mapBottom[point] = sHeight - (maxHeight - mapTop[point]);
394} 564}
395 565
396void SFCave :: drawBoss() 566void SFCave :: drawBoss()
397{ 567{
398 offscreen->fill( Qt::black ); 568 offscreen->fill( Qt::black );
399 569
400 bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true ); 570 bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true );
401} 571}
402 572
403void SFCave :: draw() 573void SFCave :: draw()
404{ 574{
405 //printf( "Paint\n" ); 575 //printf( "Paint\n" );
406 offscreen->fill( Qt::black ); 576 offscreen->fill( Qt::black );
407 577
408 QPainter p( offscreen ); 578 QPainter p( offscreen );
409 QFontMetrics fm = p.fontMetrics(); 579 QFontMetrics fm = p.fontMetrics();
410 p.setPen( Qt::white ); 580 p.setPen( Qt::white );
411 581
412 for ( int i = 0 ; i < MAPSIZE -3; ++i ) 582 for ( int i = 0 ; i < MAPSIZE -3; ++i )
413 { 583 {
414 p.drawLine( (i*segSize) - (offset*speed), mapTop[i], ((i+1)*segSize)-(offset*speed), mapTop[i+1] ); 584 // Only display top landscape if not running FLY_GAME
585 if ( CURRENT_GAME_TYPE != FLY_GAME )
586 p.drawLine( (i*segSize) - (offset*speed), mapTop[i], ((i+1)*segSize)-(offset*speed), mapTop[i+1] );
587
415 p.drawLine( (i*segSize) - (offset*speed), mapBottom[i], ((i+1)*segSize)-(offset*speed), mapBottom[i+1] ); 588 p.drawLine( (i*segSize) - (offset*speed), mapBottom[i], ((i+1)*segSize)-(offset*speed), mapBottom[i+1] );
589
590 if ( CURRENT_GAME_TYPE == FLY_GAME && showScoreZones )
591 {
592 p.setPen( Qt::red );
593 p.drawLine( (i*segSize) - (offset*speed), mapBottom[i]-10, ((i+1)*segSize)-(offset*speed), mapBottom[i+1]-10 );
594 p.drawLine( (i*segSize) - (offset*speed), mapBottom[i]-20, ((i+1)*segSize)-(offset*speed), mapBottom[i+1]-20 );
595 p.drawLine( (i*segSize) - (offset*speed), mapBottom[i]-30, ((i+1)*segSize)-(offset*speed), mapBottom[i+1]-30 );
596 p.drawLine( (i*segSize) - (offset*speed), mapBottom[i]-40, ((i+1)*segSize)-(offset*speed), mapBottom[i+1]-40 );
597 p.setPen( Qt::white );
598 }
416 } 599 }
417 600
601 // Uncomment this to show user segment (usful for checking collision boundary with landscape
602// p.setPen( Qt::red );
603// p.drawLine( (11*segSize) - (offset*speed), 0, ((11)*segSize)-(offset*speed), sHeight );
604// p.setPen( Qt::white );
605
418 // Draw user 606 // Draw user
419 p.drawRect( user ); 607 p.drawRect( user );
420 608
421 // Draw trails 609 // Draw trails
422 for ( int i = 0 ; i < TRAILSIZE ; ++i ) 610 for ( int i = 0 ; i < TRAILSIZE ; ++i )
423 if ( trail[i].x() >= 0 ) 611 if ( trail[i].x() >= 0 )
424 p.drawRect( trail[i].x(), trail[i].y(), 2, 2 ); 612 p.drawRect( trail[i].x(), trail[i].y(), 2, 2 );
425 613
426 // Draw blocks 614 // Draw blocks
427 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 615 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
428 if ( blocks[i].y() != -1 ) 616 if ( blocks[i].y() != -1 )
429 { 617 {
430 p.fillRect( blocks[i], Qt::black ); 618 p.fillRect( blocks[i], Qt::black );
431 p.drawRect( blocks[i] ); 619 p.drawRect( blocks[i] );
432 } 620 }
433 621
434 // draw score 622 // draw score
435 QString s; 623 QString s;
436 s.sprintf( "score %06d high score %06d", score, highestScore[currentGameType] ); 624 s.sprintf( "score %06d high score %06d", score, highestScore[currentGameType][currentGameDifficulty] );
437 p.drawText( 5, 10, s ); 625 p.drawText( 5, 10, s );
438 626
439 627
440 if ( state == STATE_CRASHED ) 628 if ( state == STATE_CRASHING || state == STATE_CRASHED )
441 { 629 {
442 // add next crash line 630 // add next crash line
443 631
444 if ( crashLineLength != -1 ) 632 if ( crashLineLength != -1 )
445 { 633 {
446 for ( int i = 0 ; i < 36 ; ++i ) 634 for ( int i = 0 ; i < 36 ; ++i )
447 { 635 {
448 int x = (int)(user.x() + (crashLineLength+nextInt(10)) * cos( (M_PI/180) * (10.0 * i) ) ); 636 int x = (int)(user.x() + (crashLineLength+nextInt(10)) * cos( (M_PI/180) * (10.0 * i) ) );
449 int y = (int)(user.y() + (crashLineLength+nextInt(10)) * sin( (M_PI/180) * (10.0 * i) ) ); p.drawLine( user.x(), user.y(), x, y ); 637 int y = (int)(user.y() + (crashLineLength+nextInt(10)) * sin( (M_PI/180) * (10.0 * i) ) ); p.drawLine( user.x(), user.y(), x, y );
450 } 638 }
451 } 639 }
452 640
453 if ( crashLineLength >= 15 || crashLineLength == -1 ) 641 if ( state == STATE_CRASHING && crashLineLength >= 15 ) //|| crashLineLength == -1) )
642 state = STATE_CRASHED;
643
644 if ( state == STATE_CRASHED )
454 { 645 {
455 QString text = "Press up or down to start"; 646 QString text = "Press up or down to start";
456 p.drawText( (sWidth/2) - (fm.width( text )/2), 140, text ); 647 p.drawText( (sWidth/2) - (fm.width( text )/2), 140, text );
457 648
458 text = "or press OK for menu"; 649 text = "or press OK for menu";
459 p.drawText( (sWidth/2) - (fm.width( text )/2), 155, text ); 650 p.drawText( (sWidth/2) - (fm.width( text )/2), 155, text );
460// p.drawText( 70, 140, QString( "Press down to start" ) );
461 } 651 }
462 else 652 else
463 crashLineLength ++; 653 crashLineLength ++;
464 } 654 }
465 655
466 p.end(); 656 p.end();
467 bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true ); 657 bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true );
468 //printf( "endpaint\n" ); 658 //printf( "endpaint\n" );
469} 659}
470 660
471void SFCave :: handleKeys() 661void SFCave :: handleKeys()
472{ 662{
473 // Find enpty trail and move others 663 // Find enpty trail and move others
474 bool done = false; 664 bool done = false;
475 for ( int i = 0 ; i < TRAILSIZE ; ++i ) 665 for ( int i = 0 ; i < TRAILSIZE ; ++i )
476 { 666 {
477 if ( trail[i].x() < 0 ) 667 if ( trail[i].x() < 0 )
478 { 668 {
479 if ( !done ) 669 if ( !done )
480 { 670 {
481 trail[i].setX( user.x() - 5 ); 671 trail[i].setX( user.x() - 5 );
482 trail[i].setY( user.y() ); 672 trail[i].setY( user.y() );
483 done = true; 673 done = true;
484 } 674 }
485 } 675 }
486 else 676 else
487 { 677 {
488 trail[i].setX( trail[i].x() - (2) ); 678 trail[i].setX( trail[i].x() - (2) );
489 } 679 }
490 } 680 }
491 681
492 if ( speed <= 3 ) 682 if ( speed <= 3 )
493 { 683 {
494 if ( press ) 684 if ( press )
495 thrust -= 0.6; 685 thrust -= thrustUp;
496 else 686 else
497 thrust += 0.8; 687 thrust += noThrust;
498 688
499 if ( thrust > 4.0 ) 689 if ( thrust > maxDownThrust )
500 thrust = 4.0; 690 thrust = maxDownThrust;
501 else if ( thrust < -3.5 ) 691 else if ( thrust < maxUpThrust )
502 thrust = -3.5; 692 thrust = maxUpThrust;
503 } 693 }
504 else 694 else
505 { 695 {
506 if ( press ) 696 if ( press )
507 thrust -= 0.5; 697 thrust -= 0.5;
508 else 698 else
509 thrust += 0.8; 699 thrust += 0.8;
510 700
511 if ( thrust > 5.0 ) 701 if ( thrust > 5.0 )
512 thrust = 5.0; 702 thrust = 5.0;
513 else if ( thrust < -3.5 ) 703 else if ( thrust < -3.5 )
514 thrust = -3.5; 704 thrust = -3.5;
515 } 705 }
516 user.moveBy( 0, (int)thrust ); 706 user.moveBy( 0, (int)thrust );
517} 707}
518 708
519void SFCave :: keyPressEvent( QKeyEvent *e ) 709void SFCave :: keyPressEvent( QKeyEvent *e )
520{ 710{
521 if ( state == STATE_MENU ) 711 if ( state == STATE_MENU )
522 { 712 {
523 switch( e->key() ) 713 switch( e->key() )
524 { 714 {
525 case Qt::Key_Down: 715 case Qt::Key_Down:
526 currentMenuOption[currentMenuNr] ++; 716 currentMenuOption[currentMenuNr] ++;
527 if ( menuOptions[currentMenuNr][currentMenuOption[currentMenuNr]] == "" ) 717 if ( menuOptions[currentMenuNr][currentMenuOption[currentMenuNr]] == "" )
528 currentMenuOption[currentMenuNr] = 0; 718 currentMenuOption[currentMenuNr] = 0;
529 break; 719 break;
530 case Qt::Key_Up: 720 case Qt::Key_Up:
531 currentMenuOption[currentMenuNr] --; 721 currentMenuOption[currentMenuNr] --;
532 if ( currentMenuOption[currentMenuNr] < 0 ) 722 if ( currentMenuOption[currentMenuNr] < 0 )
533 currentMenuOption[currentMenuNr] = nrMenuOptions[currentMenuNr]-1; 723 currentMenuOption[currentMenuNr] = nrMenuOptions[currentMenuNr]-1;
534 break; 724 break;
@@ -559,93 +749,99 @@ void SFCave :: keyPressEvent( QKeyEvent *e )
559 currentGameType ++; 749 currentGameType ++;
560 if ( currentGameType == NR_GAME_TYPES ) 750 if ( currentGameType == NR_GAME_TYPES )
561 currentGameType = 0; 751 currentGameType = 0;
562 } 752 }
563 else if ( currentMenuOption[currentMenuNr] == MENU_GAME_DIFFICULTY ) 753 else if ( currentMenuOption[currentMenuNr] == MENU_GAME_DIFFICULTY )
564 { 754 {
565 currentGameDifficulty ++; 755 currentGameDifficulty ++;
566 if ( currentGameDifficulty == NR_GAME_DIFFICULTIES ) 756 if ( currentGameDifficulty == NR_GAME_DIFFICULTIES )
567 currentGameDifficulty = 0; 757 currentGameDifficulty = 0;
568 } 758 }
569 } 759 }
570 break; 760 break;
571 761
572 case Qt::Key_Space: 762 case Qt::Key_Space:
573 case Qt::Key_Return: 763 case Qt::Key_Return:
574 case Qt::Key_Enter: 764 case Qt::Key_Enter:
575 dealWithMenuSelection(); 765 dealWithMenuSelection();
576 break; 766 break;
577 } 767 }
578 } 768 }
579 else 769 else
580 { 770 {
581 switch( e->key() ) 771 switch( e->key() )
582 { 772 {
583 case Qt::Key_Up: 773 case Qt::Key_Up:
584 case Qt::Key_F9: 774 case Qt::Key_F9:
585 case Qt::Key_Space: 775 case Qt::Key_Space:
586 press = true; 776 press = true;
587 break; 777 break;
588 case Qt::Key_M: 778 case Qt::Key_M:
589 case Qt::Key_Return: 779 case Qt::Key_Return:
590 case Qt::Key_Enter: 780 case Qt::Key_Enter:
591 if ( state == STATE_CRASHED && crashLineLength >= 15 || crashLineLength == -1 ) 781 if ( state == STATE_CRASHED )
592 state = STATE_MENU; 782 state = STATE_MENU;
783 break;
784
785 case Qt::Key_Z:
786 showScoreZones = !showScoreZones;
787 break;
788
593 default: 789 default:
594 e->ignore(); 790 e->ignore();
595 break; 791 break;
596 } 792 }
597 } 793 }
598} 794}
599 795
600void SFCave :: keyReleaseEvent( QKeyEvent *e ) 796void SFCave :: keyReleaseEvent( QKeyEvent *e )
601{ 797{
602 if ( state == STATE_MENU ) 798 if ( state == STATE_MENU )
603 { 799 {
604 } 800 }
605 else 801 else
606 { 802 {
607 switch( e->key() ) 803 switch( e->key() )
608 { 804 {
609 case Qt::Key_F9: 805 case Qt::Key_F9:
610 case Qt::Key_Space: 806 case Qt::Key_Space:
611 press = false; 807 press = false;
612 break; 808 break;
613 809
614 case Qt::Key_Up: 810 case Qt::Key_Up:
615 press = false; 811 press = false;
616 812
617 case Qt::Key_R: 813 case Qt::Key_R:
618 case Qt::Key_Down: 814 case Qt::Key_Down:
619 if ( state == STATE_CRASHED && crashLineLength >= 15 || crashLineLength == -1 ) 815 if ( state == STATE_CRASHED )
620 { 816 {
621 state = STATE_NEWGAME; 817 state = STATE_NEWGAME;
622 } 818 }
623 else 819 else
624 movel = true; 820 movel = true;
625 break; 821 break;
626 822
627 default: 823 default:
628 e->ignore(); 824 e->ignore();
629 break; 825 break;
630 } 826 }
631 } 827 }
632 828
633} 829}
634 830
635void SFCave :: displayMenu() 831void SFCave :: displayMenu()
636{ 832{
637 offscreen->fill( Qt::black ); 833 offscreen->fill( Qt::black );
638 834
639 QPainter p( offscreen ); 835 QPainter p( offscreen );
640 p.setPen( Qt::white ); 836 p.setPen( Qt::white );
641 837
642 QFont f( "Helvetica", 16 ); 838 QFont f( "Helvetica", 16 );
643 p.setFont( f ); 839 p.setFont( f );
644 840
645 QFontMetrics fm = p.fontMetrics(); 841 QFontMetrics fm = p.fontMetrics();
646 842
647 QString text = "SFCave"; 843 QString text = "SFCave";
648 p.drawText( (sWidth/2) - (fm.width( text )/2), 60, text ); 844 p.drawText( (sWidth/2) - (fm.width( text )/2), 60, text );
649 845
650 text = "Written by Andy Qua"; 846 text = "Written by Andy Qua";
651 p.drawText( (sWidth/2) - (fm.width( text )/2), 85, text ); 847 p.drawText( (sWidth/2) - (fm.width( text )/2), 85, text );
@@ -668,66 +864,93 @@ void SFCave :: displayMenu()
668 else 864 else
669 val = dificultyOption[currentGameDifficulty]; 865 val = dificultyOption[currentGameDifficulty];
670 866
671 text.sprintf( (const char *)menuOptions[currentMenuNr][i], (const char *)val ); 867 text.sprintf( (const char *)menuOptions[currentMenuNr][i], (const char *)val );
672 } 868 }
673 else 869 else
674 text = menuOptions[currentMenuNr][i]; 870 text = menuOptions[currentMenuNr][i];
675 871
676 p.drawText( (sWidth/2) - (fm.width( text )/2), pos, text ); 872 p.drawText( (sWidth/2) - (fm.width( text )/2), pos, text );
677 } 873 }
678 874
679 p.end(); 875 p.end();
680 bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true ); 876 bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true );
681} 877}
682 878
683void SFCave :: dealWithMenuSelection() 879void SFCave :: dealWithMenuSelection()
684{ 880{
685 switch( currentMenuNr ) 881 switch( currentMenuNr )
686 { 882 {
687 case MENU_MAIN_MENU: 883 case MENU_MAIN_MENU:
688 { 884 {
689 switch( currentMenuOption[currentMenuNr] ) 885 switch( currentMenuOption[currentMenuNr] )
690 { 886 {
691 case MENU_START_GAME: 887 case MENU_START_GAME:
692 state = STATE_NEWGAME; 888 state = STATE_NEWGAME;
693 break; 889 break;
694 890
695 case MENU_OPTIONS: 891 case MENU_OPTIONS:
696 currentMenuNr = MENU_OPTIONS_MENU; 892 currentMenuNr = MENU_OPTIONS_MENU;
697 currentMenuOption[currentMenuNr] = 0; 893 currentMenuOption[currentMenuNr] = 0;
698 break; 894 break;
699 895
896 case MENU_HELP:
897 {
898 // Display Help Menu
899 HelpWindow *dlg = new HelpWindow( this );
900 dlg->exec();
901 delete dlg;
902 break;
903 }
904
700 case MENU_QUIT: 905 case MENU_QUIT:
701 QApplication::exit(); 906 QApplication::exit();
702 break; 907 break;
703 } 908 }
704 909
705 break; 910 break;
706 } 911 }
707 912
708 case MENU_OPTIONS_MENU: 913 case MENU_OPTIONS_MENU:
709 { 914 {
710 switch( currentMenuOption[currentMenuNr] ) 915 switch( currentMenuOption[currentMenuNr] )
711 { 916 {
712 case MENU_GAME_TYPE: 917 case MENU_GAME_TYPE:
713 break; 918 break;
714 919
715 case MENU_GAME_DIFFICULTY: 920 case MENU_GAME_DIFFICULTY:
716 break; 921 break;
922
923 case MENU_CLEAR_HIGHSCORES:
924 for ( int i = 0 ; i < 3 ; ++i )
925 highestScore[currentGameType][i] = 0;
926 break;
717 927
718 case MENU_BACK: 928 case MENU_BACK:
719 currentMenuNr = MENU_MAIN_MENU; 929 currentMenuNr = MENU_MAIN_MENU;
720 930
721#ifdef QWS 931#ifdef QWS
722 Config cfg( "sfcave" ); 932 Config cfg( "sfcave" );
723 cfg.setGroup( "settings" ); 933 cfg.setGroup( "settings" );
724 cfg.writeEntry( "difficulty", currentGameDifficulty ); 934 cfg.writeEntry( "difficulty", currentGameDifficulty );
725 cfg.writeEntry( "gameType", currentGameType ); 935 cfg.writeEntry( "gameType", currentGameType );
726#endif 936#endif
727 break; 937 break;
728 } 938 }
729 939
730 break; 940 break;
731 } 941 }
732 } 942 }
733} \ No newline at end of file 943}
944
945void SFCave :: saveScore()
946{
947#ifdef QWS
948 Config cfg( "sfcave" );
949 cfg.setGroup( "settings" );
950 QString key = "highScore_";
951
952 cfg.writeEntry( key + gameTypes[currentGameType] + "_" + dificultyOption[currentGameDifficulty], highestScore[currentGameType][currentGameDifficulty] );
953 key += CURRENT_GAME_TYPE;
954 cfg.writeEntry( key, highestScore[currentGameType] );
955#endif
956}
diff --git a/noncore/games/sfcave/sfcave.h b/noncore/games/sfcave/sfcave.h
index b19d147..69a0e13 100644
--- a/noncore/games/sfcave/sfcave.h
+++ b/noncore/games/sfcave/sfcave.h
@@ -1,90 +1,108 @@
1#include <qmainwindow.h> 1#include <qmainwindow.h>
2#include <qpainter.h> 2#include <qpainter.h>
3#include <qpixmap.h> 3#include <qpixmap.h>
4#include <qpoint.h> 4#include <qpoint.h>
5#include <qrect.h> 5#include <qrect.h>
6#include <qtimer.h> 6#include <qtimer.h>
7 7
8 8
9 9
10#define MAPSIZE 52 10#define MAPSIZE 52
11#define BLOCKSIZE 6 11#define BLOCKSIZE 6
12#define TRAILSIZE 30 12#define TRAILSIZE 30
13 13
14class SFCave : public QMainWindow 14class SFCave : public QMainWindow
15{ 15{
16Q_OBJECT 16Q_OBJECT
17 17
18public: 18public:
19 int sWidth; 19 int sWidth;
20 int sHeight; 20 int sHeight;
21 int segSize; 21 int segSize;
22 22
23 int blockWidth; 23 int blockWidth;
24 int blockHeight; 24 int blockHeight;
25 int gapHeight; 25 int gapHeight;
26 int state; 26 int state;
27 int prevState; 27 int prevState;
28 int speed; 28 int speed;
29 int crashLineLength; 29 int crashLineLength;
30 30
31 static double UpThrustVals[3][3];
32 static double DownThrustVals[3][3];
33 static double MaxUpThrustVals[3][3];
34 static double MaxDownThrustVals[3][3];
35 static int initialGateGaps[];
36
37 double thrustUp;
38 double noThrust;
39 double maxUpThrust;
40 double maxDownThrust;
41
31 int gateDistance; 42 int gateDistance;
32 int nextGate; 43 int nextGate;
33 int lastGateBottomY; 44 int lastGateBottomY;
34 45
35 static QString menuOptions[2][5]; 46 static QString menuOptions[2][5];
36 int currentMenuNr; 47 int currentMenuNr;
37 int nrMenuOptions[2]; 48 static int nrMenuOptions[2];
38 int currentMenuOption[2]; 49 static int currentMenuOption[2];
39 50
40 static QString dificultyOption[3]; 51 static QString dificultyOption[3];
41 static QString gameTypes[3]; 52 static QString gameTypes[3];
42 int currentGameType; 53 int currentGameType;
43 int currentGameDifficulty; 54 int currentGameDifficulty;
44 55
45 QPixmap *offscreen; 56 QPixmap *offscreen;
46 QTimer *gameTimer; 57 QTimer *gameTimer;
47 58
48 int score; 59 int score;
49 int highestScore[3]; 60 int highestScore[3][3];
50 61
51 int mapTop[MAPSIZE]; 62 int mapTop[MAPSIZE];
52 int mapBottom[MAPSIZE]; 63 int mapBottom[MAPSIZE];
53 QRect blocks[BLOCKSIZE]; 64 QRect blocks[BLOCKSIZE];
54 QRect user; 65 QRect user;
55 QPoint trail[TRAILSIZE]; 66 QPoint trail[TRAILSIZE];
56 67
57 int offset; 68 int offset;
58 int maxHeight; 69 int maxHeight;
59 int nrFrames; 70 int nrFrames;
60 int dir; 71 int dir;
61 72
62 bool bossMode; 73 bool showScoreZones;
63 74
64 bool press; 75 bool press;
65 double thrust; 76 double thrust;
66 bool running; 77 bool running;
67 78
68 SFCave( int speed = 3, QWidget *p = 0, char *name = 0 ); 79 SFCave( int speed = 3, QWidget *p = 0, char *name = 0 );
69 ~SFCave(); 80 ~SFCave();
70 void start(); 81 void start();
71 int nextInt( int range ); 82 int nextInt( int range );
72 void setUp(); 83 void setUp();
84 void handleGameSFCave();
85 void handleGameGates();
86 void handleGameFly();
87 bool checkFlyGameCollision();
88 void moveFlyGameLandscape();
89 void setFlyPoint( int point );
73 bool checkCollision(); 90 bool checkCollision();
74 void moveLandscape(); 91 void moveLandscape();
75 void addBlock(); 92 void addBlock();
76 void addGate(); 93 void addGate();
77 void setPoint( int point ); 94 void setPoint( int point );
78 void drawBoss(); 95 void drawBoss();
79 void draw(); 96 void draw();
80 void handleKeys(); 97 void handleKeys();
81 98
82 void displayMenu(); 99 void displayMenu();
83 void dealWithMenuSelection(); 100 void dealWithMenuSelection();
84 101
85 void keyPressEvent( QKeyEvent *e ); 102 void keyPressEvent( QKeyEvent *e );
86 void keyReleaseEvent( QKeyEvent *e ); 103 void keyReleaseEvent( QKeyEvent *e );
104 void saveScore();
87 105
88private slots: 106private slots:
89 void run(); 107 void run();
90}; 108};