-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 | |||
@@ -5,4 +5,5 @@ | |||
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> |
@@ -11,7 +12,53 @@ | |||
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 | { |
@@ -34,5 +81,5 @@ int main( int argc, char *argv[] ) | |||
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(); |
@@ -41,6 +88,7 @@ int main( int argc, char *argv[] ) | |||
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 |
@@ -54,10 +102,24 @@ Main :: Main( int spd, QWidget *w, char *name ) | |||
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; |
@@ -74,9 +136,9 @@ Main :: Main( int spd, QWidget *w, char *name ) | |||
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 ); |
@@ -84,13 +146,13 @@ void Main :: start() | |||
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; |
@@ -106,4 +168,7 @@ void Main :: setUp() | |||
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 ) |
@@ -121,5 +186,5 @@ void Main :: setUp() | |||
121 | } | 186 | } |
122 | 187 | ||
123 | void Main :: run() | 188 | void SFCave :: run() |
124 | { | 189 | { |
125 | //running = true; | 190 | //running = true; |
@@ -127,4 +192,7 @@ void Main :: run() | |||
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(); |
@@ -147,5 +215,9 @@ void Main :: run() | |||
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 ) |
@@ -161,10 +233,37 @@ void Main :: run() | |||
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; |
@@ -183,5 +282,5 @@ void Main :: run() | |||
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] ) |
@@ -199,5 +298,5 @@ bool Main :: checkCollision() | |||
199 | } | 298 | } |
200 | 299 | ||
201 | void Main :: moveLandscape() | 300 | void SFCave :: moveLandscape() |
202 | { | 301 | { |
203 | offset++; | 302 | offset++; |
@@ -227,5 +326,5 @@ void Main :: moveLandscape() | |||
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 ) |
@@ -238,7 +337,34 @@ void Main :: addBlock() | |||
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; |
@@ -247,5 +373,5 @@ void Main :: addBlock() | |||
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 ) |
@@ -268,5 +394,5 @@ void Main :: setPoint( int 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 ); |
@@ -275,5 +401,5 @@ void Main :: drawBoss() | |||
275 | } | 401 | } |
276 | 402 | ||
277 | void Main :: draw() | 403 | void SFCave :: draw() |
278 | { | 404 | { |
279 | //printf( "Paint\n" ); | 405 | //printf( "Paint\n" ); |
@@ -281,4 +407,5 @@ void Main :: draw() | |||
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 | ||
@@ -307,5 +434,5 @@ void Main :: draw() | |||
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 | ||
@@ -325,5 +452,12 @@ void Main :: draw() | |||
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 ++; |
@@ -335,5 +469,5 @@ void Main :: draw() | |||
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 |
@@ -383,5 +517,65 @@ void Main :: handleKeys() | |||
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() ) |
@@ -392,4 +586,9 @@ void Main :: keyPressEvent( QKeyEvent *e ) | |||
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(); |
@@ -397,14 +596,23 @@ void Main :: keyPressEvent( QKeyEvent *e ) | |||
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: |
@@ -415,4 +623,6 @@ void Main :: keyReleaseEvent( QKeyEvent *e ) | |||
415 | else | 623 | else |
416 | movel = true; | 624 | movel = true; |
625 | break; | ||
626 | |||
417 | default: | 627 | default: |
418 | e->ignore(); | 628 | e->ignore(); |
@@ -420,2 +630,104 @@ void Main :: keyReleaseEvent( QKeyEvent *e ) | |||
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 | |||
@@ -9,13 +9,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 |
@@ -28,4 +23,5 @@ public: | |||
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; |
@@ -33,15 +29,29 @@ public: | |||
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; |
@@ -56,6 +66,6 @@ public: | |||
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 ); |
@@ -64,4 +74,5 @@ public: | |||
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(); |
@@ -69,4 +80,7 @@ public: | |||
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 ); |