summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/games/sfcave/sfcave.cpp374
-rw-r--r--noncore/games/sfcave/sfcave.h42
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
@@ -1,21 +1,68 @@
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#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
37QString 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"
54QString SFCave::dificultyOption[] = { EASY, NORMAL, HARD };
55QString SFCave::gameTypes[] = { SFCAVE_GAME, GATES_GAME, FLY_GAME };
56
57#define CURRENT_GAME_TYPE gameTypes[currentGameType]
58#define CURRENT_GAME_DIFFICULTY difficultyOption[currentGameDifficulty];
59
14bool movel; 60bool movel;
15 61
62
16int main( int argc, char *argv[] ) 63int main( int argc, char *argv[] )
17{ 64{
18 movel = true; 65 movel = true;
19 66
20#ifdef QWS 67#ifdef QWS
21 QPEApplication a( argc, argv ); 68 QPEApplication a( argc, argv );
@@ -30,38 +77,53 @@ int main( int argc, char *argv[] )
30 { 77 {
31 if ( i+1 < argc ) 78 if ( i+1 < argc )
32 speed = atoi( argv[i+1] ); 79 speed = atoi( argv[i+1] );
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
43Main :: Main( int spd, QWidget *w, char *name ) 90SFCave :: 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();
48#else 96#else
49 resize( 240, 284 ); 97 resize( 240, 284 );
50#endif 98#endif
51 99
52 sWidth = width(); 100 sWidth = width();
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
65 offscreen = new QPixmap( sWidth, sHeight ); 127 offscreen = new QPixmap( sWidth, sHeight );
66 offscreen->fill( Qt::black ); 128 offscreen->fill( Qt::black );
67 129
@@ -70,31 +132,31 @@ Main :: Main( int spd, QWidget *w, char *name )
70 132
71 gameTimer = new QTimer( this, "game timer" ); 133 gameTimer = new QTimer( this, "game timer" );
72 connect( gameTimer, SIGNAL( timeout() ), 134 connect( gameTimer, SIGNAL( timeout() ),
73 this, SLOT( run() ) ); 135 this, SLOT( run() ) );
74} 136}
75 137
76Main :: ~Main() 138SFCave :: ~SFCave()
77{ 139{
78} 140}
79 141
80void Main :: start() 142void SFCave :: start()
81{ 143{
82 gameTimer->start( 10 ); 144 gameTimer->start( 10 );
83 145
84} 146}
85 147
86int Main :: nextInt( int range ) 148int SFCave :: nextInt( int range )
87{ 149{
88 return rand() % range; 150 return rand() % range;
89} 151}
90 152
91void Main :: setUp() 153void 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;
98 maxHeight = 50; 160 maxHeight = 50;
99 nrFrames = 0; 161 nrFrames = 0;
100 dir = 1; 162 dir = 1;
@@ -102,12 +164,15 @@ void Main :: setUp()
102 crashLineLength = 0; 164 crashLineLength = 0;
103 165
104 user.setRect( 50, sWidth/2, 4, 4 ); 166 user.setRect( 50, sWidth/2, 4, 4 );
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 {
111 trail[i].setX( -1 ); 176 trail[i].setX( -1 );
112 trail[i].setY( 0 ); 177 trail[i].setY( 0 );
113 } 178 }
@@ -117,18 +182,21 @@ void Main :: setUp()
117 setPoint( i ); 182 setPoint( i );
118 183
119 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 184 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
120 blocks[i].setY( -1 ); 185 blocks[i].setY( -1 );
121} 186}
122 187
123void Main :: run() 188void 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();
132 state = STATE_RUNNING; 200 state = STATE_RUNNING;
133 break; 201 break;
134 case STATE_BOSS: 202 case STATE_BOSS:
@@ -143,13 +211,17 @@ void Main :: run()
143 { 211 {
144 if ( nrFrames % 5 == 0 ) 212 if ( nrFrames % 5 == 0 )
145 score ++; 213 score ++;
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 {
153 maxHeight += 10; 225 maxHeight += 10;
154 226
155 // Reduce block height 227 // Reduce block height
@@ -157,18 +229,45 @@ void Main :: run()
157 blockHeight -= 5; 229 blockHeight -= 5;
158 } 230 }
159 } 231 }
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 }
172 else 271 else
173 { 272 {
174 if ( movel ) 273 if ( movel )
@@ -179,13 +278,13 @@ void Main :: run()
179 draw(); 278 draw();
180 break; 279 break;
181 } 280 }
182 } 281 }
183} 282}
184 283
185bool Main :: checkCollision() 284bool 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;
189 288
190 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 289 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
191 { 290 {
@@ -195,13 +294,13 @@ bool Main :: checkCollision()
195 return true; 294 return true;
196 } 295 }
197 } 296 }
198 return false; 297 return false;
199} 298}
200 299
201void Main :: moveLandscape() 300void SFCave :: moveLandscape()
202{ 301{
203 offset++; 302 offset++;
204 303
205 if ( offset >= segSize ) 304 if ( offset >= segSize )
206 { 305 {
207 offset = 0; 306 offset = 0;
@@ -223,33 +322,60 @@ void Main :: moveLandscape()
223 if ( blocks[i].x() + blocks[i].width() < 0 ) 322 if ( blocks[i].x() + blocks[i].width() < 0 )
224 blocks[i].setY( -1 ); 323 blocks[i].setY( -1 );
225 } 324 }
226 } 325 }
227} 326}
228 327
229void Main :: addBlock() 328void SFCave :: addBlock()
230{ 329{
231 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 330 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
232 { 331 {
233 if ( blocks[i].y() == -1 ) 332 if ( blocks[i].y() == -1 )
234 { 333 {
235 int x = sWidth; 334 int x = sWidth;
236 335
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
345void 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
249void Main :: setPoint( int point ) 375void SFCave :: setPoint( int point )
250{ 376{
251 if ( nextInt(100) >= 80 ) 377 if ( nextInt(100) >= 80 )
252 dir *= -1; 378 dir *= -1;
253 379
254 mapTop[point] = mapTop[point-1] + (dir * nextInt( 5 ) ); 380 mapTop[point] = mapTop[point-1] + (dir * nextInt( 5 ) );
255 if ( mapTop[point] < 0 ) 381 if ( mapTop[point] < 0 )
@@ -264,25 +390,26 @@ void Main :: setPoint( int point )
264 } 390 }
265 391
266 mapBottom[point] = sHeight - (maxHeight - mapBottom[point]); 392 mapBottom[point] = sHeight - (maxHeight - mapBottom[point]);
267 mapBottom[point] = sHeight - (maxHeight - mapTop[point]); 393 mapBottom[point] = sHeight - (maxHeight - mapTop[point]);
268} 394}
269 395
270void Main :: drawBoss() 396void 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
277void Main :: draw() 403void 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 )
286 { 413 {
287 p.drawLine( (i*segSize) - (offset*speed), mapTop[i], ((i+1)*segSize)-(offset*speed), mapTop[i+1] ); 414 p.drawLine( (i*segSize) - (offset*speed), mapTop[i], ((i+1)*segSize)-(offset*speed), mapTop[i+1] );
288 p.drawLine( (i*segSize) - (offset*speed), mapBottom[i], ((i+1)*segSize)-(offset*speed), mapBottom[i+1] ); 415 p.drawLine( (i*segSize) - (offset*speed), mapBottom[i], ((i+1)*segSize)-(offset*speed), mapBottom[i+1] );
@@ -303,13 +430,13 @@ void Main :: draw()
303 p.fillRect( blocks[i], Qt::black ); 430 p.fillRect( blocks[i], Qt::black );
304 p.drawRect( blocks[i] ); 431 p.drawRect( blocks[i] );
305 } 432 }
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
313 if ( state == STATE_CRASHED ) 440 if ( state == STATE_CRASHED )
314 { 441 {
315 // add next crash line 442 // add next crash line
@@ -321,23 +448,30 @@ void Main :: draw()
321 int x = (int)(user.x() + (crashLineLength+nextInt(10)) * cos( (M_PI/180) * (10.0 * i) ) ); 448 int x = (int)(user.x() + (crashLineLength+nextInt(10)) * cos( (M_PI/180) * (10.0 * i) ) );
322 int y = (int)(user.y() + (crashLineLength+nextInt(10)) * sin( (M_PI/180) * (10.0 * i) ) ); p.drawLine( user.x(), user.y(), x, y ); 449 int y = (int)(user.y() + (crashLineLength+nextInt(10)) * sin( (M_PI/180) * (10.0 * i) ) ); p.drawLine( user.x(), user.y(), x, y );
323 } 450 }
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 }
331 465
332 p.end(); 466 p.end();
333 bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true ); 467 bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true );
334 //printf( "endpaint\n" ); 468 //printf( "endpaint\n" );
335} 469}
336 470
337void Main :: handleKeys() 471void 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;
341 for ( int i = 0 ; i < TRAILSIZE ; ++i ) 475 for ( int i = 0 ; i < TRAILSIZE ; ++i )
342 { 476 {
343 if ( trail[i].x() < 0 ) 477 if ( trail[i].x() < 0 )
@@ -379,43 +513,221 @@ void Main :: handleKeys()
379 else if ( thrust < -3.5 ) 513 else if ( thrust < -3.5 )
380 thrust = -3.5; 514 thrust = -3.5;
381 } 515 }
382 user.moveBy( 0, (int)thrust ); 516 user.moveBy( 0, (int)thrust );
383} 517}
384 518
385void Main :: keyPressEvent( QKeyEvent *e ) 519void 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 {
389 case Qt::Key_Up: 583 case Qt::Key_Up:
390 case Qt::Key_F9: 584 case Qt::Key_F9:
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
400void Main :: keyReleaseEvent( QKeyEvent *e ) 600void 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 )
412 { 620 {
413 state = STATE_NEWGAME; 621 state = STATE_NEWGAME;
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
635void 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
683void 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
@@ -5,72 +5,86 @@
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 5 11#define BLOCKSIZE 6
12#define TRAILSIZE 30 12#define TRAILSIZE 30
13 13
14#define STATE_BOSS 0 14class SFCave : public QMainWindow
15#define STATE_RUNNING 1
16#define STATE_CRASHED 2
17#define STATE_NEWGAME 3
18
19class Main : public QMainWindow
20{ 15{
21Q_OBJECT 16Q_OBJECT
22 17
23public: 18public:
24 int sWidth; 19 int sWidth;
25 int sHeight; 20 int sHeight;
26 int segSize; 21 int segSize;
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;
49 int nrFrames; 59 int nrFrames;
50 int dir; 60 int dir;
51 61
52 bool bossMode; 62 bool bossMode;
53 63
54 bool press; 64 bool press;
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
74private slots: 88private slots:
75 void run(); 89 void run();
76}; 90};