author | andyq <andyq> | 2002-12-07 00:30:30 (UTC) |
---|---|---|
committer | andyq <andyq> | 2002-12-07 00:30:30 (UTC) |
commit | ad2a10877ae6e50b1a765a9b7cff14494c65e588 (patch) (unidiff) | |
tree | 261d3461be9861235dff59e908dc650fe98cb346 | |
parent | 22b6762b871b64825e1f8e974636c2d27fef8486 (diff) | |
download | opie-ad2a10877ae6e50b1a765a9b7cff14494c65e588.zip opie-ad2a10877ae6e50b1a765a9b7cff14494c65e588.tar.gz opie-ad2a10877ae6e50b1a765a9b7cff14494c65e588.tar.bz2 |
Upgraded to v1.7 - new menu system, new game types (gates (implemented and working) and fly (not implemented yet)). Also, high scores are persistent and different across game types - not difficultiy yet. Game Difficulty levels added but not yet implemented
-rw-r--r-- | noncore/games/sfcave/sfcave.cpp | 374 | ||||
-rw-r--r-- | noncore/games/sfcave/sfcave.h | 42 |
2 files changed, 371 insertions, 45 deletions
diff --git a/noncore/games/sfcave/sfcave.cpp b/noncore/games/sfcave/sfcave.cpp index 931f393..8b9c844 100644 --- a/noncore/games/sfcave/sfcave.cpp +++ b/noncore/games/sfcave/sfcave.cpp | |||
@@ -4,15 +4,62 @@ | |||
4 | 4 | ||
5 | #ifdef QWS | 5 | #ifdef QWS |
6 | #include <qpe/qpeapplication.h> | 6 | #include <qpe/qpeapplication.h> |
7 | #include <qpe/config.h> | ||
7 | #else | 8 | #else |
8 | #include <qapplication.h> | 9 | #include <qapplication.h> |
9 | #endif | 10 | #endif |
10 | 11 | ||
11 | #include "sfcave.h" | 12 | #include "sfcave.h" |
12 | 13 | ||
13 | #define CAPTION "SFCave 1.6 by AndyQ" | 14 | #define CAPTION "SFCave 1.7 by AndyQ" |
15 | |||
16 | // States | ||
17 | #define STATE_BOSS 0 | ||
18 | #define STATE_RUNNING 1 | ||
19 | #define STATE_CRASHED 2 | ||
20 | #define STATE_NEWGAME 3 | ||
21 | #define STATE_MENU 4 | ||
22 | |||
23 | // Menus | ||
24 | #define MENU_MAIN_MENU 0 | ||
25 | #define MENU_OPTIONS_MENU 1 | ||
26 | |||
27 | // Main Menu Options | ||
28 | #define MENU_START_GAME 0 | ||
29 | #define MENU_OPTIONS 1 | ||
30 | #define MENU_QUIT 2 | ||
31 | |||
32 | // Option Menu Options | ||
33 | #define MENU_GAME_TYPE 0 | ||
34 | #define MENU_GAME_DIFFICULTY 1 | ||
35 | #define MENU_BACK 2 | ||
36 | |||
37 | QString SFCave::menuOptions[2][5] = { { "Start Game", "Options", "Quit", "", "" }, | ||
38 | { "Game Type - %s", "Game Difficulty - %s", "Back", "", "" } }; | ||
39 | |||
40 | |||
41 | #define NR_GAME_DIFFICULTIES 3 | ||
42 | #define NR_GAME_TYPES 3 | ||
43 | |||
44 | #define EASY "Easy" | ||
45 | #define NORMAL "Normal" | ||
46 | #define HARD "Hard" | ||
47 | |||
48 | #define SFCAVE_GAME_TYPE 0 | ||
49 | #define GATES_GAME_TYPE 1 | ||
50 | #define FLY_GAME_TYPE 2 | ||
51 | #define SFCAVE_GAME "SFCave" | ||
52 | #define GATES_GAME "Gates" | ||
53 | #define FLY_GAME "Fly" | ||
54 | QString SFCave::dificultyOption[] = { EASY, NORMAL, HARD }; | ||
55 | QString SFCave::gameTypes[] = { SFCAVE_GAME, GATES_GAME, FLY_GAME }; | ||
56 | |||
57 | #define CURRENT_GAME_TYPE gameTypes[currentGameType] | ||
58 | #define CURRENT_GAME_DIFFICULTY difficultyOption[currentGameDifficulty]; | ||
59 | |||
14 | bool movel; | 60 | bool movel; |
15 | 61 | ||
62 | |||
16 | int main( int argc, char *argv[] ) | 63 | int main( int argc, char *argv[] ) |
17 | { | 64 | { |
18 | movel = true; | 65 | movel = true; |
@@ -33,15 +80,16 @@ int main( int argc, char *argv[] ) | |||
33 | } | 80 | } |
34 | } | 81 | } |
35 | 82 | ||
36 | Main app( speed ); | 83 | SFCave app( speed ); |
37 | a.setMainWidget( &app ); | 84 | a.setMainWidget( &app ); |
38 | app.show(); | 85 | app.show(); |
39 | app.start(); | 86 | app.start(); |
40 | a.exec(); | 87 | a.exec(); |
41 | } | 88 | } |
42 | 89 | ||
43 | Main :: Main( int spd, QWidget *w, char *name ) | 90 | SFCave :: SFCave( int spd, QWidget *w, char *name ) |
44 | : QMainWindow( w, name ) | 91 | : QMainWindow( w, name ) |
92 | |||
45 | { | 93 | { |
46 | #ifdef QWS | 94 | #ifdef QWS |
47 | showMaximized(); | 95 | showMaximized(); |
@@ -53,12 +101,26 @@ Main :: Main( int spd, QWidget *w, char *name ) | |||
53 | sHeight = height(); | 101 | sHeight = height(); |
54 | segSize = sWidth/(MAPSIZE-1)+1; | 102 | segSize = sWidth/(MAPSIZE-1)+1; |
55 | 103 | ||
56 | //printf( "width %d, height %d\n", sWidth, sHeight ); | 104 | currentMenuNr = 0; |
57 | //printf( "segSize = %d\n", segSize ); | 105 | nrMenuOptions[0] = 3; |
106 | nrMenuOptions[1] = 3; | ||
107 | currentMenuOption[0] = 0; | ||
108 | currentMenuOption[1] = 0; | ||
109 | currentGameType = 0; | ||
110 | currentGameDifficulty = 0; | ||
58 | 111 | ||
59 | setCaption( CAPTION ); | 112 | setCaption( CAPTION ); |
60 | 113 | ||
61 | highestScore = 0; | 114 | #ifdef QWS |
115 | Config cfg( "sfcave" ); | ||
116 | cfg.setGroup( "settings" ); | ||
117 | QString key = "highScore_"; | ||
118 | highestScore[SFCAVE_GAME_TYPE] = cfg.readNumEntry( key + SFCAVE_GAME, 0 ); | ||
119 | highestScore[GATES_GAME_TYPE] = cfg.readNumEntry( key + GATES_GAME, 0 ); | ||
120 | highestScore[FLY_GAME_TYPE] = cfg.readNumEntry( key + FLY_GAME, 0 ); | ||
121 | currentGameType = cfg.readNumEntry( "gameType", 0 ); | ||
122 | currentGameDifficulty = cfg.readNumEntry( "difficulty", 0 ); | ||
123 | #endif | ||
62 | speed = spd; // Change to 2 for PC | 124 | speed = spd; // Change to 2 for PC |
63 | press = false; | 125 | press = false; |
64 | 126 | ||
@@ -73,25 +135,25 @@ Main :: Main( int spd, QWidget *w, char *name ) | |||
73 | this, SLOT( run() ) ); | 135 | this, SLOT( run() ) ); |
74 | } | 136 | } |
75 | 137 | ||
76 | Main :: ~Main() | 138 | SFCave :: ~SFCave() |
77 | { | 139 | { |
78 | } | 140 | } |
79 | 141 | ||
80 | void Main :: start() | 142 | void SFCave :: start() |
81 | { | 143 | { |
82 | gameTimer->start( 10 ); | 144 | gameTimer->start( 10 ); |
83 | 145 | ||
84 | } | 146 | } |
85 | 147 | ||
86 | int Main :: nextInt( int range ) | 148 | int SFCave :: nextInt( int range ) |
87 | { | 149 | { |
88 | return rand() % range; | 150 | return rand() % range; |
89 | } | 151 | } |
90 | 152 | ||
91 | void Main :: setUp() | 153 | void SFCave :: setUp() |
92 | { | 154 | { |
93 | state = STATE_CRASHED; | 155 | state = STATE_MENU; |
94 | prevState = STATE_CRASHED; | 156 | prevState = STATE_MENU; |
95 | 157 | ||
96 | score = 0; | 158 | score = 0; |
97 | offset = 0; | 159 | offset = 0; |
@@ -105,6 +167,9 @@ void Main :: setUp() | |||
105 | 167 | ||
106 | blockWidth = 20; | 168 | blockWidth = 20; |
107 | blockHeight = 70; | 169 | blockHeight = 70; |
170 | gapHeight = 125; | ||
171 | gateDistance = 75; | ||
172 | nextGate = nextInt( 50 ) + gateDistance; | ||
108 | 173 | ||
109 | for ( int i = 0 ; i < TRAILSIZE ; ++i ) | 174 | for ( int i = 0 ; i < TRAILSIZE ; ++i ) |
110 | { | 175 | { |
@@ -120,12 +185,15 @@ void Main :: setUp() | |||
120 | blocks[i].setY( -1 ); | 185 | blocks[i].setY( -1 ); |
121 | } | 186 | } |
122 | 187 | ||
123 | void Main :: run() | 188 | void SFCave :: run() |
124 | { | 189 | { |
125 | //running = true; | 190 | //running = true; |
126 | //setUp(); | 191 | //setUp(); |
127 | switch ( state ) | 192 | switch ( state ) |
128 | { | 193 | { |
194 | case STATE_MENU: | ||
195 | displayMenu(); | ||
196 | break; | ||
129 | case STATE_NEWGAME: | 197 | case STATE_NEWGAME: |
130 | setUp(); | 198 | setUp(); |
131 | draw(); | 199 | draw(); |
@@ -146,7 +214,11 @@ void Main :: run() | |||
146 | if ( nrFrames % 2 == 0 ) | 214 | if ( nrFrames % 2 == 0 ) |
147 | handleKeys(); | 215 | handleKeys(); |
148 | 216 | ||
149 | if ( ++nrFrames % 500 == 0 ) | 217 | // Apply Game rules |
218 | nrFrames ++; | ||
219 | if ( CURRENT_GAME_TYPE == SFCAVE_GAME ) | ||
220 | { | ||
221 | if ( nrFrames % 500 == 0 ) | ||
150 | { | 222 | { |
151 | if ( maxHeight < sHeight - 100 ) | 223 | if ( maxHeight < sHeight - 100 ) |
152 | { | 224 | { |
@@ -160,12 +232,39 @@ void Main :: run() | |||
160 | 232 | ||
161 | if ( nrFrames % 100 == 0 ) | 233 | if ( nrFrames % 100 == 0 ) |
162 | addBlock(); | 234 | addBlock(); |
235 | } | ||
236 | else if ( CURRENT_GAME_TYPE == GATES_GAME ) | ||
237 | { | ||
238 | // Slightly random gap distance | ||
239 | if ( nrFrames >= nextGate ) | ||
240 | { | ||
241 | nextGate = nrFrames + nextInt( 50 ) + gateDistance; | ||
242 | addGate(); | ||
243 | } | ||
244 | |||
245 | if ( nrFrames % 500 == 0 ) | ||
246 | { | ||
247 | if ( gapHeight > 75 ) | ||
248 | gapHeight -= 5; | ||
249 | } | ||
250 | } | ||
251 | else if ( CURRENT_GAME_TYPE == FLY_GAME ) | ||
252 | { | ||
253 | } | ||
254 | |||
163 | 255 | ||
164 | // if ( false ) | ||
165 | if ( checkCollision() ) | 256 | if ( checkCollision() ) |
166 | { | 257 | { |
167 | if ( score > highestScore ) | 258 | if ( score > highestScore[currentGameType] ) |
168 | highestScore = score; | 259 | highestScore[currentGameType] = score; |
260 | |||
261 | #ifdef QWS | ||
262 | Config cfg( "sfcave" ); | ||
263 | cfg.setGroup( "settings" ); | ||
264 | QString key = "highScore_"; | ||
265 | key += CURRENT_GAME_TYPE; | ||
266 | cfg.writeEntry( key, highestScore[currentGameType] ); | ||
267 | #endif | ||
169 | 268 | ||
170 | state = STATE_CRASHED; | 269 | state = STATE_CRASHED; |
171 | } | 270 | } |
@@ -182,7 +281,7 @@ void Main :: run() | |||
182 | } | 281 | } |
183 | } | 282 | } |
184 | 283 | ||
185 | bool Main :: checkCollision() | 284 | bool SFCave :: checkCollision() |
186 | { | 285 | { |
187 | if ( (user.y() + user.width()) >= mapBottom[10] || user.y() <= mapTop[10] ) | 286 | if ( (user.y() + user.width()) >= mapBottom[10] || user.y() <= mapTop[10] ) |
188 | return true; | 287 | return true; |
@@ -198,7 +297,7 @@ bool Main :: checkCollision() | |||
198 | return false; | 297 | return false; |
199 | } | 298 | } |
200 | 299 | ||
201 | void Main :: moveLandscape() | 300 | void SFCave :: moveLandscape() |
202 | { | 301 | { |
203 | offset++; | 302 | offset++; |
204 | 303 | ||
@@ -226,7 +325,7 @@ void Main :: moveLandscape() | |||
226 | } | 325 | } |
227 | } | 326 | } |
228 | 327 | ||
229 | void Main :: addBlock() | 328 | void SFCave :: addBlock() |
230 | { | 329 | { |
231 | for ( int i = 0 ; i < BLOCKSIZE ; ++i ) | 330 | for ( int i = 0 ; i < BLOCKSIZE ; ++i ) |
232 | { | 331 | { |
@@ -237,16 +336,43 @@ void Main :: addBlock() | |||
237 | int y = mapTop[50] + (int)(nextInt(mapBottom[50] - mapTop[50] - blockHeight)); | 336 | int y = mapTop[50] + (int)(nextInt(mapBottom[50] - mapTop[50] - blockHeight)); |
238 | 337 | ||
239 | blocks[i].setRect( x, y, blockWidth, blockHeight ); | 338 | blocks[i].setRect( x, y, blockWidth, blockHeight ); |
240 | // printf( "Added block @ %d %d\n", x, y ); | ||
241 | // printf( "mapTop = %d, mapBottom = %d", mapTop[50], mapBottom[50] ); | ||
242 | 339 | ||
340 | break; | ||
341 | } | ||
342 | } | ||
343 | } | ||
344 | |||
345 | void SFCave :: addGate() | ||
346 | { | ||
347 | for ( int i = 0 ; i < BLOCKSIZE ; ++i ) | ||
348 | { | ||
349 | if ( blocks[i].y() == -1 ) | ||
350 | { | ||
351 | int x1 = sWidth; | ||
352 | int y1 = mapTop[50]; | ||
353 | int b1Height = nextInt(mapBottom[50] - mapTop[50] - gateDistance); | ||
354 | |||
355 | // See if height between last gate and this one is too big | ||
356 | if ( b1Height - 200 > lastGateBottomY ) | ||
357 | b1Height -= 25; | ||
358 | else if ( b1Height + 200 < lastGateBottomY ) | ||
359 | b1Height += 25; | ||
360 | lastGateBottomY = b1Height; | ||
361 | |||
362 | int x2 = sWidth; | ||
363 | int y2 = y1 + b1Height + gateDistance; | ||
364 | int b2Height = mapBottom[50] - y2; | ||
365 | |||
366 | |||
367 | blocks[i].setRect( x1, y1, blockWidth, b1Height ); | ||
368 | blocks[i+1].setRect( x2, y2, blockWidth, b2Height ); | ||
243 | 369 | ||
244 | break; | 370 | break; |
245 | } | 371 | } |
246 | } | 372 | } |
247 | } | 373 | } |
248 | 374 | ||
249 | void Main :: setPoint( int point ) | 375 | void SFCave :: setPoint( int point ) |
250 | { | 376 | { |
251 | if ( nextInt(100) >= 80 ) | 377 | if ( nextInt(100) >= 80 ) |
252 | dir *= -1; | 378 | dir *= -1; |
@@ -267,19 +393,20 @@ void Main :: setPoint( int point ) | |||
267 | mapBottom[point] = sHeight - (maxHeight - mapTop[point]); | 393 | mapBottom[point] = sHeight - (maxHeight - mapTop[point]); |
268 | } | 394 | } |
269 | 395 | ||
270 | void Main :: drawBoss() | 396 | void SFCave :: drawBoss() |
271 | { | 397 | { |
272 | offscreen->fill( Qt::black ); | 398 | offscreen->fill( Qt::black ); |
273 | 399 | ||
274 | bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true ); | 400 | bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true ); |
275 | } | 401 | } |
276 | 402 | ||
277 | void Main :: draw() | 403 | void SFCave :: draw() |
278 | { | 404 | { |
279 | //printf( "Paint\n" ); | 405 | //printf( "Paint\n" ); |
280 | offscreen->fill( Qt::black ); | 406 | offscreen->fill( Qt::black ); |
281 | 407 | ||
282 | QPainter p( offscreen ); | 408 | QPainter p( offscreen ); |
409 | QFontMetrics fm = p.fontMetrics(); | ||
283 | p.setPen( Qt::white ); | 410 | p.setPen( Qt::white ); |
284 | 411 | ||
285 | for ( int i = 0 ; i < MAPSIZE -3; ++i ) | 412 | for ( int i = 0 ; i < MAPSIZE -3; ++i ) |
@@ -306,7 +433,7 @@ void Main :: draw() | |||
306 | 433 | ||
307 | // draw score | 434 | // draw score |
308 | QString s; | 435 | QString s; |
309 | s.sprintf( "score %06d high score %06d", score, highestScore ); | 436 | s.sprintf( "score %06d high score %06d", score, highestScore[currentGameType] ); |
310 | p.drawText( 5, 10, s ); | 437 | p.drawText( 5, 10, s ); |
311 | 438 | ||
312 | 439 | ||
@@ -324,7 +451,14 @@ void Main :: draw() | |||
324 | } | 451 | } |
325 | 452 | ||
326 | if ( crashLineLength >= 15 || crashLineLength == -1 ) | 453 | if ( crashLineLength >= 15 || crashLineLength == -1 ) |
327 | p.drawText( 70, 140, QString( "Press down to start" ) ); | 454 | { |
455 | QString text = "Press up or down to start"; | ||
456 | p.drawText( (sWidth/2) - (fm.width( text )/2), 140, text ); | ||
457 | |||
458 | text = "or press OK for menu"; | ||
459 | p.drawText( (sWidth/2) - (fm.width( text )/2), 155, text ); | ||
460 | // p.drawText( 70, 140, QString( "Press down to start" ) ); | ||
461 | } | ||
328 | else | 462 | else |
329 | crashLineLength ++; | 463 | crashLineLength ++; |
330 | } | 464 | } |
@@ -334,7 +468,7 @@ void Main :: draw() | |||
334 | //printf( "endpaint\n" ); | 468 | //printf( "endpaint\n" ); |
335 | } | 469 | } |
336 | 470 | ||
337 | void Main :: handleKeys() | 471 | void SFCave :: handleKeys() |
338 | { | 472 | { |
339 | // Find enpty trail and move others | 473 | // Find enpty trail and move others |
340 | bool done = false; | 474 | bool done = false; |
@@ -382,7 +516,67 @@ void Main :: handleKeys() | |||
382 | user.moveBy( 0, (int)thrust ); | 516 | user.moveBy( 0, (int)thrust ); |
383 | } | 517 | } |
384 | 518 | ||
385 | void Main :: keyPressEvent( QKeyEvent *e ) | 519 | void SFCave :: keyPressEvent( QKeyEvent *e ) |
520 | { | ||
521 | if ( state == STATE_MENU ) | ||
522 | { | ||
523 | switch( e->key() ) | ||
524 | { | ||
525 | case Qt::Key_Down: | ||
526 | currentMenuOption[currentMenuNr] ++; | ||
527 | if ( menuOptions[currentMenuNr][currentMenuOption[currentMenuNr]] == "" ) | ||
528 | currentMenuOption[currentMenuNr] = 0; | ||
529 | break; | ||
530 | case Qt::Key_Up: | ||
531 | currentMenuOption[currentMenuNr] --; | ||
532 | if ( currentMenuOption[currentMenuNr] < 0 ) | ||
533 | currentMenuOption[currentMenuNr] = nrMenuOptions[currentMenuNr]-1; | ||
534 | break; | ||
535 | |||
536 | case Qt::Key_Left: | ||
537 | if ( currentMenuNr == MENU_OPTIONS_MENU ) | ||
538 | { | ||
539 | if ( currentMenuOption[currentMenuNr] == MENU_GAME_TYPE ) | ||
540 | { | ||
541 | currentGameType --; | ||
542 | if ( currentGameType < 0 ) | ||
543 | currentGameType = NR_GAME_TYPES - 1; | ||
544 | } | ||
545 | else if ( currentMenuOption[currentMenuNr] == MENU_GAME_DIFFICULTY ) | ||
546 | { | ||
547 | currentGameDifficulty --; | ||
548 | if ( currentGameDifficulty < 0 ) | ||
549 | currentGameDifficulty = NR_GAME_DIFFICULTIES - 1; | ||
550 | } | ||
551 | } | ||
552 | break; | ||
553 | |||
554 | case Qt::Key_Right: | ||
555 | if ( currentMenuNr == MENU_OPTIONS_MENU ) | ||
556 | { | ||
557 | if ( currentMenuOption[currentMenuNr] == MENU_GAME_TYPE ) | ||
558 | { | ||
559 | currentGameType ++; | ||
560 | if ( currentGameType == NR_GAME_TYPES ) | ||
561 | currentGameType = 0; | ||
562 | } | ||
563 | else if ( currentMenuOption[currentMenuNr] == MENU_GAME_DIFFICULTY ) | ||
564 | { | ||
565 | currentGameDifficulty ++; | ||
566 | if ( currentGameDifficulty == NR_GAME_DIFFICULTIES ) | ||
567 | currentGameDifficulty = 0; | ||
568 | } | ||
569 | } | ||
570 | break; | ||
571 | |||
572 | case Qt::Key_Space: | ||
573 | case Qt::Key_Return: | ||
574 | case Qt::Key_Enter: | ||
575 | dealWithMenuSelection(); | ||
576 | break; | ||
577 | } | ||
578 | } | ||
579 | else | ||
386 | { | 580 | { |
387 | switch( e->key() ) | 581 | switch( e->key() ) |
388 | { | 582 | { |
@@ -391,21 +585,35 @@ void Main :: keyPressEvent( QKeyEvent *e ) | |||
391 | case Qt::Key_Space: | 585 | case Qt::Key_Space: |
392 | press = true; | 586 | press = true; |
393 | break; | 587 | break; |
588 | case Qt::Key_M: | ||
589 | case Qt::Key_Return: | ||
590 | case Qt::Key_Enter: | ||
591 | if ( state == STATE_CRASHED && crashLineLength >= 15 || crashLineLength == -1 ) | ||
592 | state = STATE_MENU; | ||
394 | default: | 593 | default: |
395 | e->ignore(); | 594 | e->ignore(); |
396 | break; | 595 | break; |
397 | } | 596 | } |
398 | } | 597 | } |
598 | } | ||
399 | 599 | ||
400 | void Main :: keyReleaseEvent( QKeyEvent *e ) | 600 | void SFCave :: keyReleaseEvent( QKeyEvent *e ) |
601 | { | ||
602 | if ( state == STATE_MENU ) | ||
603 | { | ||
604 | } | ||
605 | else | ||
401 | { | 606 | { |
402 | switch( e->key() ) | 607 | switch( e->key() ) |
403 | { | 608 | { |
404 | case Qt::Key_Up: | ||
405 | case Qt::Key_F9: | 609 | case Qt::Key_F9: |
406 | case Qt::Key_Space: | 610 | case Qt::Key_Space: |
407 | press = false; | 611 | press = false; |
408 | break; | 612 | break; |
613 | |||
614 | case Qt::Key_Up: | ||
615 | press = false; | ||
616 | |||
409 | case Qt::Key_R: | 617 | case Qt::Key_R: |
410 | case Qt::Key_Down: | 618 | case Qt::Key_Down: |
411 | if ( state == STATE_CRASHED && crashLineLength >= 15 || crashLineLength == -1 ) | 619 | if ( state == STATE_CRASHED && crashLineLength >= 15 || crashLineLength == -1 ) |
@@ -414,8 +622,112 @@ void Main :: keyReleaseEvent( QKeyEvent *e ) | |||
414 | } | 622 | } |
415 | else | 623 | else |
416 | movel = true; | 624 | movel = true; |
625 | break; | ||
626 | |||
417 | default: | 627 | default: |
418 | e->ignore(); | 628 | e->ignore(); |
419 | break; | 629 | break; |
420 | } | 630 | } |
421 | } | 631 | } |
632 | |||
633 | } | ||
634 | |||
635 | void SFCave :: displayMenu() | ||
636 | { | ||
637 | offscreen->fill( Qt::black ); | ||
638 | |||
639 | QPainter p( offscreen ); | ||
640 | p.setPen( Qt::white ); | ||
641 | |||
642 | QFont f( "Helvetica", 16 ); | ||
643 | p.setFont( f ); | ||
644 | |||
645 | QFontMetrics fm = p.fontMetrics(); | ||
646 | |||
647 | QString text = "SFCave"; | ||
648 | p.drawText( (sWidth/2) - (fm.width( text )/2), 60, text ); | ||
649 | |||
650 | text = "Written by Andy Qua"; | ||
651 | p.drawText( (sWidth/2) - (fm.width( text )/2), 85, text ); | ||
652 | |||
653 | // Draw options | ||
654 | int pos = 170; | ||
655 | for ( int i = 0 ; menuOptions[currentMenuNr][i] != "" ; ++i, pos += 25 ) | ||
656 | { | ||
657 | if ( currentMenuOption[currentMenuNr] == i ) | ||
658 | p.setPen( Qt::yellow ); | ||
659 | else | ||
660 | p.setPen( Qt::white ); | ||
661 | |||
662 | QString text; | ||
663 | if ( menuOptions[currentMenuNr][i].find( "%s" ) != -1 ) | ||
664 | { | ||
665 | QString val; | ||
666 | if ( i == MENU_GAME_TYPE ) | ||
667 | val = gameTypes[currentGameType]; | ||
668 | else | ||
669 | val = dificultyOption[currentGameDifficulty]; | ||
670 | |||
671 | text.sprintf( (const char *)menuOptions[currentMenuNr][i], (const char *)val ); | ||
672 | } | ||
673 | else | ||
674 | text = menuOptions[currentMenuNr][i]; | ||
675 | |||
676 | p.drawText( (sWidth/2) - (fm.width( text )/2), pos, text ); | ||
677 | } | ||
678 | |||
679 | p.end(); | ||
680 | bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true ); | ||
681 | } | ||
682 | |||
683 | void SFCave :: dealWithMenuSelection() | ||
684 | { | ||
685 | switch( currentMenuNr ) | ||
686 | { | ||
687 | case MENU_MAIN_MENU: | ||
688 | { | ||
689 | switch( currentMenuOption[currentMenuNr] ) | ||
690 | { | ||
691 | case MENU_START_GAME: | ||
692 | state = STATE_NEWGAME; | ||
693 | break; | ||
694 | |||
695 | case MENU_OPTIONS: | ||
696 | currentMenuNr = MENU_OPTIONS_MENU; | ||
697 | currentMenuOption[currentMenuNr] = 0; | ||
698 | break; | ||
699 | |||
700 | case MENU_QUIT: | ||
701 | QApplication::exit(); | ||
702 | break; | ||
703 | } | ||
704 | |||
705 | break; | ||
706 | } | ||
707 | |||
708 | case MENU_OPTIONS_MENU: | ||
709 | { | ||
710 | switch( currentMenuOption[currentMenuNr] ) | ||
711 | { | ||
712 | case MENU_GAME_TYPE: | ||
713 | break; | ||
714 | |||
715 | case MENU_GAME_DIFFICULTY: | ||
716 | break; | ||
717 | |||
718 | case MENU_BACK: | ||
719 | currentMenuNr = MENU_MAIN_MENU; | ||
720 | |||
721 | #ifdef QWS | ||
722 | Config cfg( "sfcave" ); | ||
723 | cfg.setGroup( "settings" ); | ||
724 | cfg.writeEntry( "difficulty", currentGameDifficulty ); | ||
725 | cfg.writeEntry( "gameType", currentGameType ); | ||
726 | #endif | ||
727 | break; | ||
728 | } | ||
729 | |||
730 | break; | ||
731 | } | ||
732 | } | ||
733 | } \ No newline at end of file | ||
diff --git a/noncore/games/sfcave/sfcave.h b/noncore/games/sfcave/sfcave.h index 18eeef9..b19d147 100644 --- a/noncore/games/sfcave/sfcave.h +++ b/noncore/games/sfcave/sfcave.h | |||
@@ -8,15 +8,10 @@ | |||
8 | 8 | ||
9 | 9 | ||
10 | #define MAPSIZE 52 | 10 | #define MAPSIZE 52 |
11 | #define BLOCKSIZE 5 | 11 | #define BLOCKSIZE 6 |
12 | #define TRAILSIZE 30 | 12 | #define TRAILSIZE 30 |
13 | 13 | ||
14 | #define STATE_BOSS 0 | 14 | class SFCave : public QMainWindow |
15 | #define STATE_RUNNING 1 | ||
16 | #define STATE_CRASHED 2 | ||
17 | #define STATE_NEWGAME 3 | ||
18 | |||
19 | class Main : public QMainWindow | ||
20 | { | 15 | { |
21 | Q_OBJECT | 16 | Q_OBJECT |
22 | 17 | ||
@@ -27,22 +22,37 @@ public: | |||
27 | 22 | ||
28 | int blockWidth; | 23 | int blockWidth; |
29 | int blockHeight; | 24 | int blockHeight; |
25 | int gapHeight; | ||
30 | int state; | 26 | int state; |
31 | int prevState; | 27 | int prevState; |
32 | int speed; | 28 | int speed; |
33 | int crashLineLength; | 29 | int crashLineLength; |
34 | 30 | ||
31 | int gateDistance; | ||
32 | int nextGate; | ||
33 | int lastGateBottomY; | ||
34 | |||
35 | static QString menuOptions[2][5]; | ||
36 | int currentMenuNr; | ||
37 | int nrMenuOptions[2]; | ||
38 | int currentMenuOption[2]; | ||
39 | |||
40 | static QString dificultyOption[3]; | ||
41 | static QString gameTypes[3]; | ||
42 | int currentGameType; | ||
43 | int currentGameDifficulty; | ||
44 | |||
35 | QPixmap *offscreen; | 45 | QPixmap *offscreen; |
36 | QTimer *gameTimer; | 46 | QTimer *gameTimer; |
37 | 47 | ||
38 | int score; | 48 | int score; |
39 | int highestScore; | 49 | int highestScore[3]; |
40 | 50 | ||
41 | int mapTop[52]; | 51 | int mapTop[MAPSIZE]; |
42 | int mapBottom[52]; | 52 | int mapBottom[MAPSIZE]; |
43 | QRect blocks[5]; | 53 | QRect blocks[BLOCKSIZE]; |
44 | QRect user; | 54 | QRect user; |
45 | QPoint trail[30]; | 55 | QPoint trail[TRAILSIZE]; |
46 | 56 | ||
47 | int offset; | 57 | int offset; |
48 | int maxHeight; | 58 | int maxHeight; |
@@ -55,19 +65,23 @@ public: | |||
55 | double thrust; | 65 | double thrust; |
56 | bool running; | 66 | bool running; |
57 | 67 | ||
58 | Main( int speed = 3, QWidget *p = 0, char *name = 0 ); | 68 | SFCave( int speed = 3, QWidget *p = 0, char *name = 0 ); |
59 | ~Main(); | 69 | ~SFCave(); |
60 | void start(); | 70 | void start(); |
61 | int nextInt( int range ); | 71 | int nextInt( int range ); |
62 | void setUp(); | 72 | void setUp(); |
63 | bool checkCollision(); | 73 | bool checkCollision(); |
64 | void moveLandscape(); | 74 | void moveLandscape(); |
65 | void addBlock(); | 75 | void addBlock(); |
76 | void addGate(); | ||
66 | void setPoint( int point ); | 77 | void setPoint( int point ); |
67 | void drawBoss(); | 78 | void drawBoss(); |
68 | void draw(); | 79 | void draw(); |
69 | void handleKeys(); | 80 | void handleKeys(); |
70 | 81 | ||
82 | void displayMenu(); | ||
83 | void dealWithMenuSelection(); | ||
84 | |||
71 | void keyPressEvent( QKeyEvent *e ); | 85 | void keyPressEvent( QKeyEvent *e ); |
72 | void keyReleaseEvent( QKeyEvent *e ); | 86 | void keyReleaseEvent( QKeyEvent *e ); |
73 | 87 | ||