-rw-r--r-- | noncore/games/sfcave/sfcave.cpp | 19 | ||||
-rw-r--r-- | noncore/games/sfcave/sfcave.h | 2 |
2 files changed, 11 insertions, 10 deletions
diff --git a/noncore/games/sfcave/sfcave.cpp b/noncore/games/sfcave/sfcave.cpp index d6d28b2..9b30fe6 100644 --- a/noncore/games/sfcave/sfcave.cpp +++ b/noncore/games/sfcave/sfcave.cpp | |||
@@ -83,96 +83,97 @@ QString SFCave::menuOptions[NR_MENUS][MAX_MENU_OPTIONS] = { { "Start Game", "Rep | |||
83 | 83 | ||
84 | int SFCave::nrMenuOptions[NR_MENUS] = { 5, 4, 4 }; | 84 | int SFCave::nrMenuOptions[NR_MENUS] = { 5, 4, 4 }; |
85 | int SFCave ::currentMenuOption[NR_MENUS] = { 0, 0, 0 }; | 85 | int SFCave ::currentMenuOption[NR_MENUS] = { 0, 0, 0 }; |
86 | 86 | ||
87 | #define UP_THRUST 0.6 | 87 | #define UP_THRUST 0.6 |
88 | #define NO_THRUST 0.8 | 88 | #define NO_THRUST 0.8 |
89 | #define MAX_DOWN_THRUST 4.0 | 89 | #define MAX_DOWN_THRUST 4.0 |
90 | #define MAX_UP_THRUST -3.5 | 90 | #define MAX_UP_THRUST -3.5 |
91 | double SFCave::UpThrustVals[3][3] = {{ 0.6, 0.6, 0.6 }, // SFCave | 91 | double SFCave::UpThrustVals[3][3] = {{ 0.6, 0.6, 0.6 }, // SFCave |
92 | { 0.6, 0.6, 0.8 }, // Gates | 92 | { 0.6, 0.6, 0.8 }, // Gates |
93 | { 0.4, 0.7, 1.0 } }; // Fly | 93 | { 0.4, 0.7, 1.0 } }; // Fly |
94 | 94 | ||
95 | double SFCave::DownThrustVals[3][3] = {{ 0.8, 0.8, 0.8 }, // SFCave | 95 | double SFCave::DownThrustVals[3][3] = {{ 0.8, 0.8, 0.8 }, // SFCave |
96 | { 0.8, 0.8, 1.0 }, // Gates | 96 | { 0.8, 0.8, 1.0 }, // Gates |
97 | { 0.4, 0.7, 1.0 } }; // Fly | 97 | { 0.4, 0.7, 1.0 } }; // Fly |
98 | 98 | ||
99 | double SFCave::MaxUpThrustVals[3][3] = {{ -3.5, -3.5, -3.5 }, // SFCave | 99 | double SFCave::MaxUpThrustVals[3][3] = {{ -3.5, -3.5, -3.5 }, // SFCave |
100 | { -3.5, -4.0, -5.0 }, // Gates | 100 | { -3.5, -4.0, -5.0 }, // Gates |
101 | { -3.5, -4.0, -5.0 } }; // Fly | 101 | { -3.5, -4.0, -5.0 } }; // Fly |
102 | 102 | ||
103 | double SFCave::MaxDownThrustVals[3][3] = {{ 4.0, 4.0, 4.0 }, // SFCave | 103 | double SFCave::MaxDownThrustVals[3][3] = {{ 4.0, 4.0, 4.0 }, // SFCave |
104 | { 4.0, 5.0, 5.5 }, // Gates | 104 | { 4.0, 5.0, 5.5 }, // Gates |
105 | { 3.5, 4.0, 5.0 } }; // Fly | 105 | { 3.5, 4.0, 5.0 } }; // Fly |
106 | 106 | ||
107 | int SFCave::flyEasyScores[7][3] = { { 0, 10, 5 }, | 107 | int SFCave::flyEasyScores[7][3] = { { 0, 10, 5 }, |
108 | { 10, 20, 3 }, | 108 | { 10, 20, 3 }, |
109 | { 20, 30, 2 }, | 109 | { 20, 30, 2 }, |
110 | { 30, 40, 1 }, | 110 | { 30, 40, 1 }, |
111 | { 50, 70, -2 }, | 111 | { 50, 70, -2 }, |
112 | { 70, 300, -5 }, | 112 | { 70, 300, -5 }, |
113 | { -1, -1, -1 } }; | 113 | { -1, -1, -1 } }; |
114 | int SFCave::flyNormalScores[7][3] = { { 0, 10, 5 }, | 114 | int SFCave::flyNormalScores[7][3] = { { 0, 10, 5 }, |
115 | { 10, 20, 3 }, | 115 | { 10, 20, 3 }, |
116 | { 20, 30, 2 }, | 116 | { 20, 30, 2 }, |
117 | { 30, 40, 1 }, | 117 | { 30, 40, 1 }, |
118 | { 50, 70, -2 }, | 118 | { 50, 70, -2 }, |
119 | { 70, 300, -5 }, | 119 | { 70, 300, -5 }, |
120 | { -1, -1, -1 } }; | 120 | { -1, -1, -1 } }; |
121 | int SFCave::flyHardScores[7][3] = { { 0, 20, 5 }, | 121 | int SFCave::flyHardScores[7][3] = { { 0, 20, 5 }, |
122 | { 20, 40, 3 }, | 122 | { 20, 40, 3 }, |
123 | { 40, 100, 1 }, | 123 | { 40, 100, 1 }, |
124 | { 100, 150, -2 }, | 124 | { 100, 150, -2 }, |
125 | { 150, 300, -5 }, | 125 | { 150, 300, -5 }, |
126 | { -1, -1, -1 } }; | 126 | { -1, -1, -1 } }; |
127 | 127 | ||
128 | int SFCave::initialGateGaps[] = { 75, 50, 25 }; | 128 | int SFCave::initialGateGaps[] = { 75, 50, 25 }; |
129 | 129 | ||
130 | 130 | ||
131 | #define FLYSCORES( x, y ) (*(flyScores + ((x)*3) + y)) | ||
131 | bool movel; | 132 | bool movel; |
132 | 133 | ||
133 | 134 | ||
134 | int main( int argc, char *argv[] ) | 135 | int main( int argc, char *argv[] ) |
135 | { | 136 | { |
136 | movel = true; | 137 | movel = true; |
137 | #ifdef QWS | 138 | #ifdef QWS |
138 | QPEApplication a( argc, argv ); | 139 | QPEApplication a( argc, argv ); |
139 | #else | 140 | #else |
140 | QApplication a( argc, argv ); | 141 | QApplication a( argc, argv ); |
141 | #endif | 142 | #endif |
142 | 143 | ||
143 | int speed = 3; | 144 | int speed = 3; |
144 | for ( int i = 0 ; i < argc ; ++i ) | 145 | for ( int i = 0 ; i < argc ; ++i ) |
145 | { | 146 | { |
146 | if ( strcmp( argv[i], "-s" ) == 0 ) | 147 | if ( strcmp( argv[i], "-s" ) == 0 ) |
147 | { | 148 | { |
148 | if ( i+1 < argc ) | 149 | if ( i+1 < argc ) |
149 | speed = atoi( argv[i+1] ); | 150 | speed = atoi( argv[i+1] ); |
150 | } | 151 | } |
151 | } | 152 | } |
152 | 153 | ||
153 | SFCave app( speed ); | 154 | SFCave app( speed ); |
154 | a.setMainWidget( &app ); | 155 | a.setMainWidget( &app ); |
155 | app.show(); | 156 | app.show(); |
156 | app.start(); | 157 | app.start(); |
157 | a.exec(); | 158 | a.exec(); |
158 | } | 159 | } |
159 | 160 | ||
160 | SFCave :: SFCave( int spd, QWidget *w, char *name ) | 161 | SFCave :: SFCave( int spd, QWidget *w, char *name ) |
161 | : QMainWindow( w, name ) | 162 | : QMainWindow( w, name ) |
162 | 163 | ||
163 | { | 164 | { |
164 | replayIt = 0; | 165 | replayIt = 0; |
165 | #ifdef QWS | 166 | #ifdef QWS |
166 | showMaximized(); | 167 | showMaximized(); |
167 | #else | 168 | #else |
168 | resize( 240, 284 ); | 169 | resize( 240, 284 ); |
169 | #endif | 170 | #endif |
170 | 171 | ||
171 | replayFile = QDir::home().path(); | 172 | replayFile = QDir::home().path(); |
172 | replayFile += "/sfcave.replay"; | 173 | replayFile += "/sfcave.replay"; |
173 | printf( "%s\n", (const char *)replayFile ); | 174 | printf( "%s\n", (const char *)replayFile ); |
174 | 175 | ||
175 | sWidth = width(); | 176 | sWidth = width(); |
176 | sHeight = height(); | 177 | sHeight = height(); |
177 | segSize = sWidth/(MAPSIZE-1)+1; | 178 | segSize = sWidth/(MAPSIZE-1)+1; |
178 | 179 | ||
@@ -237,101 +238,101 @@ int SFCave :: nextInt( int range ) | |||
237 | { | 238 | { |
238 | int val = (int)(Random( ) * range); | 239 | int val = (int)(Random( ) * range); |
239 | 240 | ||
240 | return val; | 241 | return val; |
241 | 242 | ||
242 | } | 243 | } |
243 | 244 | ||
244 | void SFCave :: setUp() | 245 | void SFCave :: setUp() |
245 | { | 246 | { |
246 | score = 0; | 247 | score = 0; |
247 | offset = 0; | 248 | offset = 0; |
248 | nrFrames = 0; | 249 | nrFrames = 0; |
249 | dir = 1; | 250 | dir = 1; |
250 | thrust = 0; | 251 | thrust = 0; |
251 | startScoring = false; | 252 | startScoring = false; |
252 | press = false; | 253 | press = false; |
253 | 254 | ||
254 | if ( CURRENT_GAME_TYPE == SFCAVE_GAME ) | 255 | if ( CURRENT_GAME_TYPE == SFCAVE_GAME ) |
255 | { | 256 | { |
256 | thrustUp = UpThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];; | 257 | thrustUp = UpThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];; |
257 | noThrust = DownThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];; | 258 | noThrust = DownThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];; |
258 | maxUpThrust = MaxUpThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];; | 259 | maxUpThrust = MaxUpThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];; |
259 | maxDownThrust = MaxDownThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];; | 260 | maxDownThrust = MaxDownThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];; |
260 | 261 | ||
261 | if ( currentGameDifficulty == DIFICULTY_EASY ) | 262 | if ( currentGameDifficulty == DIFICULTY_EASY ) |
262 | gateDistance = 100; | 263 | gateDistance = 100; |
263 | else if ( currentGameDifficulty == DIFICULTY_NORMAL ) | 264 | else if ( currentGameDifficulty == DIFICULTY_NORMAL ) |
264 | gateDistance = 60; | 265 | gateDistance = 60; |
265 | else | 266 | else |
266 | gateDistance = 40; | 267 | gateDistance = 40; |
267 | } | 268 | } |
268 | else if ( CURRENT_GAME_TYPE == GATES_GAME ) | 269 | else if ( CURRENT_GAME_TYPE == GATES_GAME ) |
269 | { | 270 | { |
270 | thrustUp = UpThrustVals[GATES_GAME_TYPE][currentGameDifficulty];; | 271 | thrustUp = UpThrustVals[GATES_GAME_TYPE][currentGameDifficulty];; |
271 | noThrust = DownThrustVals[GATES_GAME_TYPE][currentGameDifficulty];; | 272 | noThrust = DownThrustVals[GATES_GAME_TYPE][currentGameDifficulty];; |
272 | maxUpThrust = MaxUpThrustVals[GATES_GAME_TYPE][currentGameDifficulty];; | 273 | maxUpThrust = MaxUpThrustVals[GATES_GAME_TYPE][currentGameDifficulty];; |
273 | maxDownThrust = MaxDownThrustVals[GATES_GAME_TYPE][currentGameDifficulty];; | 274 | maxDownThrust = MaxDownThrustVals[GATES_GAME_TYPE][currentGameDifficulty];; |
274 | gateDistance = 75; | 275 | gateDistance = 75; |
275 | nextGate = nextInt( 50 ) + gateDistance; | 276 | nextGate = nextInt( 50 ) + gateDistance; |
276 | } | 277 | } |
277 | else | 278 | else |
278 | { | 279 | { |
279 | thrustUp = UpThrustVals[FLY_GAME_TYPE][currentGameDifficulty]; | 280 | thrustUp = UpThrustVals[FLY_GAME_TYPE][currentGameDifficulty]; |
280 | noThrust = DownThrustVals[FLY_GAME_TYPE][currentGameDifficulty]; | 281 | noThrust = DownThrustVals[FLY_GAME_TYPE][currentGameDifficulty]; |
281 | maxUpThrust = MaxUpThrustVals[FLY_GAME_TYPE][currentGameDifficulty]; | 282 | maxUpThrust = MaxUpThrustVals[FLY_GAME_TYPE][currentGameDifficulty]; |
282 | maxDownThrust = MaxDownThrustVals[FLY_GAME_TYPE][currentGameDifficulty]; | 283 | maxDownThrust = MaxDownThrustVals[FLY_GAME_TYPE][currentGameDifficulty]; |
283 | 284 | ||
284 | if ( currentGameDifficulty == DIFICULTY_EASY ) | 285 | if ( currentGameDifficulty == DIFICULTY_EASY ) |
285 | flyScores = flyEasyScores; | 286 | flyScores = (int*)flyEasyScores; |
286 | else if ( currentGameDifficulty == DIFICULTY_NORMAL ) | 287 | else if ( currentGameDifficulty == DIFICULTY_NORMAL ) |
287 | flyScores = flyNormalScores; | 288 | flyScores = (int*)flyNormalScores; |
288 | else | 289 | else |
289 | flyScores = flyHardScores; | 290 | flyScores = (int*)flyHardScores; |
290 | } | 291 | } |
291 | 292 | ||
292 | crashLineLength = 0; | 293 | crashLineLength = 0; |
293 | lastGateBottomY = 0; | 294 | lastGateBottomY = 0; |
294 | 295 | ||
295 | user.setRect( 50, sWidth/2, 4, 4 ); | 296 | user.setRect( 50, sWidth/2, 4, 4 ); |
296 | 297 | ||
297 | blockWidth = 20; | 298 | blockWidth = 20; |
298 | blockHeight = 70; | 299 | blockHeight = 70; |
299 | gapHeight = initialGateGaps[currentGameDifficulty]; | 300 | gapHeight = initialGateGaps[currentGameDifficulty]; |
300 | 301 | ||
301 | for ( int i = 0 ; i < TRAILSIZE ; ++i ) | 302 | for ( int i = 0 ; i < TRAILSIZE ; ++i ) |
302 | { | 303 | { |
303 | trail[i].setX( -1 ); | 304 | trail[i].setX( -1 ); |
304 | trail[i].setY( 0 ); | 305 | trail[i].setY( 0 ); |
305 | } | 306 | } |
306 | 307 | ||
307 | if ( CURRENT_GAME_TYPE != FLY_GAME ) | 308 | if ( CURRENT_GAME_TYPE != FLY_GAME ) |
308 | { | 309 | { |
309 | maxHeight = 50; | 310 | maxHeight = 50; |
310 | 311 | ||
311 | mapTop[0] = (int)(nextInt(50)) + 5; | 312 | mapTop[0] = (int)(nextInt(50)) + 5; |
312 | mapBottom[0] = (int)(nextInt(50)) + 5; | 313 | mapBottom[0] = (int)(nextInt(50)) + 5; |
313 | for ( int i = 1 ; i < MAPSIZE ; ++i ) | 314 | for ( int i = 1 ; i < MAPSIZE ; ++i ) |
314 | setPoint( i ); | 315 | setPoint( i ); |
315 | } | 316 | } |
316 | else | 317 | else |
317 | { | 318 | { |
318 | maxHeight = 100; | 319 | maxHeight = 100; |
319 | 320 | ||
320 | for ( int i = 0 ; i < MAPSIZE ; ++i ) | 321 | for ( int i = 0 ; i < MAPSIZE ; ++i ) |
321 | mapBottom[i] = sHeight - 10; | 322 | mapBottom[i] = sHeight - 10; |
322 | } | 323 | } |
323 | for ( int i = 0 ; i < BLOCKSIZE ; ++i ) | 324 | for ( int i = 0 ; i < BLOCKSIZE ; ++i ) |
324 | blocks[i].setY( -1 ); | 325 | blocks[i].setY( -1 ); |
325 | 326 | ||
326 | } | 327 | } |
327 | 328 | ||
328 | void SFCave :: run() | 329 | void SFCave :: run() |
329 | { | 330 | { |
330 | switch ( state ) | 331 | switch ( state ) |
331 | { | 332 | { |
332 | case STATE_MENU: | 333 | case STATE_MENU: |
333 | displayMenu(); | 334 | displayMenu(); |
334 | break; | 335 | break; |
335 | case STATE_NEWGAME: | 336 | case STATE_NEWGAME: |
336 | setSeed( -1 ); | 337 | setSeed( -1 ); |
337 | setUp(); | 338 | setUp(); |
@@ -436,101 +437,101 @@ void SFCave :: handleGameGates() | |||
436 | 437 | ||
437 | // Slightly random gap distance | 438 | // Slightly random gap distance |
438 | if ( nrFrames >= nextGate ) | 439 | if ( nrFrames >= nextGate ) |
439 | { | 440 | { |
440 | nextGate = nrFrames + nextInt( 50 ) + gateDistance; | 441 | nextGate = nrFrames + nextInt( 50 ) + gateDistance; |
441 | addGate(); | 442 | addGate(); |
442 | } | 443 | } |
443 | 444 | ||
444 | if ( nrFrames % 500 == 0 ) | 445 | if ( nrFrames % 500 == 0 ) |
445 | { | 446 | { |
446 | if ( gapHeight > 75 ) | 447 | if ( gapHeight > 75 ) |
447 | gapHeight -= 5; | 448 | gapHeight -= 5; |
448 | } | 449 | } |
449 | 450 | ||
450 | if ( checkCollision() ) | 451 | if ( checkCollision() ) |
451 | { | 452 | { |
452 | if ( score > highestScore[currentGameType][currentGameDifficulty] ) | 453 | if ( score > highestScore[currentGameType][currentGameDifficulty] ) |
453 | { | 454 | { |
454 | highestScore[currentGameType][currentGameDifficulty] = score; | 455 | highestScore[currentGameType][currentGameDifficulty] = score; |
455 | saveScore(); | 456 | saveScore(); |
456 | } | 457 | } |
457 | state = STATE_CRASHING; | 458 | state = STATE_CRASHING; |
458 | } | 459 | } |
459 | else | 460 | else |
460 | { | 461 | { |
461 | moveLandscape(); | 462 | moveLandscape(); |
462 | } | 463 | } |
463 | 464 | ||
464 | } | 465 | } |
465 | 466 | ||
466 | void SFCave :: handleGameFly() | 467 | void SFCave :: handleGameFly() |
467 | { | 468 | { |
468 | int diff = mapBottom[10] - user.y(); | 469 | int diff = mapBottom[10] - user.y(); |
469 | 470 | ||
470 | if ( nrFrames % 4 == 0 ) | 471 | if ( nrFrames % 4 == 0 ) |
471 | { | 472 | { |
472 | if ( !startScoring ) | 473 | if ( !startScoring ) |
473 | { | 474 | { |
474 | if ( diff < 40 ) | 475 | if ( diff < 40 ) |
475 | startScoring = true; | 476 | startScoring = true; |
476 | } | 477 | } |
477 | 478 | ||
478 | if ( startScoring ) | 479 | if ( startScoring ) |
479 | { | 480 | { |
480 | // Update score | 481 | // Update score |
481 | // get distance between landscape and ship | 482 | // get distance between landscape and ship |
482 | 483 | ||
483 | // the closer the difference is to 0 means more points | 484 | // the closer the difference is to 0 means more points |
484 | for ( int i = 0 ; i < 10 && flyScores[i][0] != -1 ; ++i ) | 485 | for ( int i = 0 ; i < 10 && FLYSCORES( i, 0 ) != -1 ; ++i ) |
485 | { | 486 | { |
486 | if ( flyScores[i][0] <= diff && flyScores[i][1] > diff ) | 487 | if ( FLYSCORES( i, 0 ) <= diff && FLYSCORES(i, 1 ) > diff ) |
487 | { | 488 | { |
488 | score += flyScores[i][2]; | 489 | score += FLYSCORES( i, 2 ); |
489 | break; | 490 | break; |
490 | } | 491 | } |
491 | } | 492 | } |
492 | } | 493 | } |
493 | } | 494 | } |
494 | 495 | ||
495 | if ( checkFlyGameCollision() ) | 496 | if ( checkFlyGameCollision() ) |
496 | { | 497 | { |
497 | if ( score > highestScore[currentGameType][currentGameDifficulty] ) | 498 | if ( score > highestScore[currentGameType][currentGameDifficulty] ) |
498 | { | 499 | { |
499 | highestScore[currentGameType][currentGameDifficulty] = score; | 500 | highestScore[currentGameType][currentGameDifficulty] = score; |
500 | saveScore(); | 501 | saveScore(); |
501 | } | 502 | } |
502 | state = STATE_CRASHING; | 503 | state = STATE_CRASHING; |
503 | } | 504 | } |
504 | else | 505 | else |
505 | { | 506 | { |
506 | moveFlyGameLandscape(); | 507 | moveFlyGameLandscape(); |
507 | } | 508 | } |
508 | } | 509 | } |
509 | 510 | ||
510 | bool SFCave :: checkFlyGameCollision() | 511 | bool SFCave :: checkFlyGameCollision() |
511 | { | 512 | { |
512 | if ( (user.y() + user.width()) >= mapBottom[11] ) | 513 | if ( (user.y() + user.width()) >= mapBottom[11] ) |
513 | return true; | 514 | return true; |
514 | 515 | ||
515 | return false; | 516 | return false; |
516 | } | 517 | } |
517 | 518 | ||
518 | void SFCave :: moveFlyGameLandscape() | 519 | void SFCave :: moveFlyGameLandscape() |
519 | { | 520 | { |
520 | offset++; | 521 | offset++; |
521 | 522 | ||
522 | if ( offset >= segSize ) | 523 | if ( offset >= segSize ) |
523 | { | 524 | { |
524 | offset = 0; | 525 | offset = 0; |
525 | for ( int i = 0 ; i < MAPSIZE-speed ; ++i ) | 526 | for ( int i = 0 ; i < MAPSIZE-speed ; ++i ) |
526 | mapBottom[i] = mapBottom[i+speed]; | 527 | mapBottom[i] = mapBottom[i+speed]; |
527 | 528 | ||
528 | for ( int i = speed ; i > 0 ; --i ) | 529 | for ( int i = speed ; i > 0 ; --i ) |
529 | setFlyPoint( MAPSIZE-i ); | 530 | setFlyPoint( MAPSIZE-i ); |
530 | } | 531 | } |
531 | } | 532 | } |
532 | 533 | ||
533 | void SFCave :: setFlyPoint( int point ) | 534 | void SFCave :: setFlyPoint( int point ) |
534 | { | 535 | { |
535 | static int fly_difficulty_levels[] = { 5, 10, 15 }; | 536 | static int fly_difficulty_levels[] = { 5, 10, 15 }; |
536 | if ( nextInt(100) >= 75 ) | 537 | if ( nextInt(100) >= 75 ) |
@@ -649,102 +650,102 @@ void SFCave :: addGate() | |||
649 | void SFCave :: setPoint( int point ) | 650 | void SFCave :: setPoint( int point ) |
650 | { | 651 | { |
651 | if ( nextInt(100) >= 80 ) | 652 | if ( nextInt(100) >= 80 ) |
652 | dir *= -1; | 653 | dir *= -1; |
653 | 654 | ||
654 | mapTop[point] = mapTop[point-1] + (dir * nextInt( 5 ) ); | 655 | mapTop[point] = mapTop[point-1] + (dir * nextInt( 5 ) ); |
655 | if ( mapTop[point] < 0 ) | 656 | if ( mapTop[point] < 0 ) |
656 | { | 657 | { |
657 | mapTop[point] = 0; | 658 | mapTop[point] = 0; |
658 | dir *= -1; | 659 | dir *= -1; |
659 | } | 660 | } |
660 | else if ( mapTop[point] >= maxHeight ) | 661 | else if ( mapTop[point] >= maxHeight ) |
661 | { | 662 | { |
662 | mapTop[point] = maxHeight; | 663 | mapTop[point] = maxHeight; |
663 | dir *= -1; | 664 | dir *= -1; |
664 | } | 665 | } |
665 | 666 | ||
666 | // mapBottom[point] = sHeight - (maxHeight - mapBottom[point]); | 667 | // mapBottom[point] = sHeight - (maxHeight - mapBottom[point]); |
667 | mapBottom[point] = sHeight - (maxHeight - mapTop[point]); | 668 | mapBottom[point] = sHeight - (maxHeight - mapTop[point]); |
668 | } | 669 | } |
669 | 670 | ||
670 | void SFCave :: drawBoss() | 671 | void SFCave :: drawBoss() |
671 | { | 672 | { |
672 | offscreen->fill( Qt::black ); | 673 | offscreen->fill( Qt::black ); |
673 | 674 | ||
674 | bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true ); | 675 | bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true ); |
675 | } | 676 | } |
676 | 677 | ||
677 | void SFCave :: draw() | 678 | void SFCave :: draw() |
678 | { | 679 | { |
679 | //printf( "Paint\n" ); | 680 | //printf( "Paint\n" ); |
680 | offscreen->fill( Qt::black ); | 681 | offscreen->fill( Qt::black ); |
681 | 682 | ||
682 | QPainter p( offscreen ); | 683 | QPainter p( offscreen ); |
683 | QFontMetrics fm = p.fontMetrics(); | 684 | QFontMetrics fm = p.fontMetrics(); |
684 | p.setPen( Qt::white ); | 685 | p.setPen( Qt::white ); |
685 | 686 | ||
686 | for ( int i = 0 ; i < MAPSIZE -3; ++i ) | 687 | for ( int i = 0 ; i < MAPSIZE -3; ++i ) |
687 | { | 688 | { |
688 | // Only display top landscape if not running FLY_GAME | 689 | // Only display top landscape if not running FLY_GAME |
689 | if ( CURRENT_GAME_TYPE != FLY_GAME ) | 690 | if ( CURRENT_GAME_TYPE != FLY_GAME ) |
690 | p.drawLine( (i*segSize) - (offset*speed), mapTop[i], ((i+1)*segSize)-(offset*speed), mapTop[i+1] ); | 691 | p.drawLine( (i*segSize) - (offset*speed), mapTop[i], ((i+1)*segSize)-(offset*speed), mapTop[i+1] ); |
691 | 692 | ||
692 | p.drawLine( (i*segSize) - (offset*speed), mapBottom[i], ((i+1)*segSize)-(offset*speed), mapBottom[i+1] ); | 693 | p.drawLine( (i*segSize) - (offset*speed), mapBottom[i], ((i+1)*segSize)-(offset*speed), mapBottom[i+1] ); |
693 | 694 | ||
694 | if ( CURRENT_GAME_TYPE == FLY_GAME && showScoreZones ) | 695 | if ( CURRENT_GAME_TYPE == FLY_GAME && showScoreZones ) |
695 | { | 696 | { |
696 | p.setPen( Qt::blue ); | 697 | p.setPen( Qt::blue ); |
697 | for ( int j = 1 ; j < 10 && flyScores[j][0] != -1 ; ++j ) | 698 | for ( int j = 1 ; j < 10 && FLYSCORES( j, 0 ) != -1 ; ++j ) |
698 | { | 699 | { |
699 | if ( flyScores[j][2] < 0 ) | 700 | if ( FLYSCORES( j, 2 ) < 0 ) |
700 | p.setPen( Qt::red ); | 701 | p.setPen( Qt::red ); |
701 | 702 | ||
702 | p.drawLine( (i*segSize) - (offset*speed), mapBottom[i]-flyScores[j][0], ((i+1)*segSize)-(offset*speed), mapBottom[i+1]-flyScores[j][0] ); | 703 | p.drawLine( (i*segSize) - (offset*speed), mapBottom[i]-FLYSCORES( j, 0 ), ((i+1)*segSize)-(offset*speed), mapBottom[i+1]-FLYSCORES( j, 0 ) ); |
703 | } | 704 | } |
704 | 705 | ||
705 | p.setPen( Qt::white ); | 706 | p.setPen( Qt::white ); |
706 | } | 707 | } |
707 | } | 708 | } |
708 | 709 | ||
709 | // Uncomment this to show user segment (usful for checking collision boundary with landscape | 710 | // Uncomment this to show user segment (usful for checking collision boundary with landscape |
710 | // p.setPen( Qt::red ); | 711 | // p.setPen( Qt::red ); |
711 | // p.drawLine( (11*segSize) - (offset*speed), 0, ((11)*segSize)-(offset*speed), sHeight ); | 712 | // p.drawLine( (11*segSize) - (offset*speed), 0, ((11)*segSize)-(offset*speed), sHeight ); |
712 | // p.setPen( Qt::white ); | 713 | // p.setPen( Qt::white ); |
713 | 714 | ||
714 | // Draw user | 715 | // Draw user |
715 | p.drawRect( user ); | 716 | p.drawRect( user ); |
716 | 717 | ||
717 | // Draw trails | 718 | // Draw trails |
718 | for ( int i = 0 ; i < TRAILSIZE ; ++i ) | 719 | for ( int i = 0 ; i < TRAILSIZE ; ++i ) |
719 | if ( trail[i].x() >= 0 ) | 720 | if ( trail[i].x() >= 0 ) |
720 | { | 721 | { |
721 | if ( showEyeCandy ) | 722 | if ( showEyeCandy ) |
722 | p.setPen( Qt::white.light((int)(100.0-3*(user.x()/100.0)* (user.x()-trail[i].x())) ) ); | 723 | p.setPen( Qt::white.light((int)(100.0-3*(user.x()/100.0)* (user.x()-trail[i].x())) ) ); |
723 | p.drawRect( trail[i].x(), trail[i].y(), 2, 2 ); | 724 | p.drawRect( trail[i].x(), trail[i].y(), 2, 2 ); |
724 | } | 725 | } |
725 | 726 | ||
726 | p.setPen( Qt::white ); | 727 | p.setPen( Qt::white ); |
727 | // Draw blocks | 728 | // Draw blocks |
728 | for ( int i = 0 ; i < BLOCKSIZE ; ++i ) | 729 | for ( int i = 0 ; i < BLOCKSIZE ; ++i ) |
729 | if ( blocks[i].y() != -1 ) | 730 | if ( blocks[i].y() != -1 ) |
730 | { | 731 | { |
731 | p.fillRect( blocks[i], Qt::black ); | 732 | p.fillRect( blocks[i], Qt::black ); |
732 | p.drawRect( blocks[i] ); | 733 | p.drawRect( blocks[i] ); |
733 | } | 734 | } |
734 | 735 | ||
735 | // draw score | 736 | // draw score |
736 | QString s; | 737 | QString s; |
737 | s.sprintf( "score %06d high score %06d", score, highestScore[currentGameType][currentGameDifficulty] ); | 738 | s.sprintf( "score %06d high score %06d", score, highestScore[currentGameType][currentGameDifficulty] ); |
738 | p.drawText( 5, 10, s ); | 739 | p.drawText( 5, 10, s ); |
739 | 740 | ||
740 | 741 | ||
741 | if ( state == STATE_CRASHING || state == STATE_CRASHED ) | 742 | if ( state == STATE_CRASHING || state == STATE_CRASHED ) |
742 | { | 743 | { |
743 | // add next crash line | 744 | // add next crash line |
744 | 745 | ||
745 | if ( crashLineLength != -1 ) | 746 | if ( crashLineLength != -1 ) |
746 | { | 747 | { |
747 | for ( int i = 0 ; i < 36 ; ++i ) | 748 | for ( int i = 0 ; i < 36 ; ++i ) |
748 | { | 749 | { |
749 | int x = (int)(user.x() + (crashLineLength+nextInt(10)) * cos( (M_PI/180) * (10.0 * i) ) ); | 750 | int x = (int)(user.x() + (crashLineLength+nextInt(10)) * cos( (M_PI/180) * (10.0 * i) ) ); |
750 | int y = (int)(user.y() + (crashLineLength+nextInt(10)) * sin( (M_PI/180) * (10.0 * i) ) ); p.drawLine( user.x(), user.y(), x, y ); | 751 | int y = (int)(user.y() + (crashLineLength+nextInt(10)) * sin( (M_PI/180) * (10.0 * i) ) ); p.drawLine( user.x(), user.y(), x, y ); |
diff --git a/noncore/games/sfcave/sfcave.h b/noncore/games/sfcave/sfcave.h index f95558d..b1fe819 100644 --- a/noncore/games/sfcave/sfcave.h +++ b/noncore/games/sfcave/sfcave.h | |||
@@ -5,97 +5,97 @@ | |||
5 | #include <qrect.h> | 5 | #include <qrect.h> |
6 | #include <qtimer.h> | 6 | #include <qtimer.h> |
7 | #include <qlist.h> | 7 | #include <qlist.h> |
8 | 8 | ||
9 | #include "random.h" | 9 | #include "random.h" |
10 | 10 | ||
11 | #define MAPSIZE 52 | 11 | #define MAPSIZE 52 |
12 | #define BLOCKSIZE 6 | 12 | #define BLOCKSIZE 6 |
13 | #define TRAILSIZE 30 | 13 | #define TRAILSIZE 30 |
14 | 14 | ||
15 | #define NR_MENUS 3 | 15 | #define NR_MENUS 3 |
16 | #define MAX_MENU_OPTIONS 8 | 16 | #define MAX_MENU_OPTIONS 8 |
17 | 17 | ||
18 | class SFCave : public QMainWindow | 18 | class SFCave : public QMainWindow |
19 | { | 19 | { |
20 | Q_OBJECT | 20 | Q_OBJECT |
21 | 21 | ||
22 | public: | 22 | public: |
23 | int sWidth; | 23 | int sWidth; |
24 | int sHeight; | 24 | int sHeight; |
25 | int segSize; | 25 | int segSize; |
26 | 26 | ||
27 | int currentSeed; | 27 | int currentSeed; |
28 | 28 | ||
29 | QList<int> replayList; | 29 | QList<int> replayList; |
30 | QListIterator<int> *replayIt; | 30 | QListIterator<int> *replayIt; |
31 | bool replay; | 31 | bool replay; |
32 | QString replayFile; | 32 | QString replayFile; |
33 | 33 | ||
34 | int blockWidth; | 34 | int blockWidth; |
35 | int blockHeight; | 35 | int blockHeight; |
36 | int gapHeight; | 36 | int gapHeight; |
37 | int state; | 37 | int state; |
38 | int prevState; | 38 | int prevState; |
39 | int speed; | 39 | int speed; |
40 | int crashLineLength; | 40 | int crashLineLength; |
41 | bool startScoring; | 41 | bool startScoring; |
42 | bool showEyeCandy; | 42 | bool showEyeCandy; |
43 | 43 | ||
44 | static double UpThrustVals[3][3]; | 44 | static double UpThrustVals[3][3]; |
45 | static double DownThrustVals[3][3]; | 45 | static double DownThrustVals[3][3]; |
46 | static double MaxUpThrustVals[3][3]; | 46 | static double MaxUpThrustVals[3][3]; |
47 | static double MaxDownThrustVals[3][3]; | 47 | static double MaxDownThrustVals[3][3]; |
48 | static int initialGateGaps[]; | 48 | static int initialGateGaps[]; |
49 | 49 | ||
50 | static int flyEasyScores[7][3]; | 50 | static int flyEasyScores[7][3]; |
51 | static int flyNormalScores[7][3]; | 51 | static int flyNormalScores[7][3]; |
52 | static int flyHardScores[7][3]; | 52 | static int flyHardScores[7][3]; |
53 | int flyScores[7][3]; | 53 | int *flyScores; |
54 | 54 | ||
55 | 55 | ||
56 | double thrustUp; | 56 | double thrustUp; |
57 | double noThrust; | 57 | double noThrust; |
58 | double maxUpThrust; | 58 | double maxUpThrust; |
59 | double maxDownThrust; | 59 | double maxDownThrust; |
60 | 60 | ||
61 | int gateDistance; | 61 | int gateDistance; |
62 | int nextGate; | 62 | int nextGate; |
63 | int lastGateBottomY; | 63 | int lastGateBottomY; |
64 | 64 | ||
65 | static QString menuOptions[NR_MENUS][MAX_MENU_OPTIONS]; | 65 | static QString menuOptions[NR_MENUS][MAX_MENU_OPTIONS]; |
66 | int currentMenuNr; | 66 | int currentMenuNr; |
67 | static int nrMenuOptions[NR_MENUS]; | 67 | static int nrMenuOptions[NR_MENUS]; |
68 | static int currentMenuOption[NR_MENUS]; | 68 | static int currentMenuOption[NR_MENUS]; |
69 | 69 | ||
70 | static QString dificultyOption[3]; | 70 | static QString dificultyOption[3]; |
71 | static QString gameTypes[3]; | 71 | static QString gameTypes[3]; |
72 | int currentGameType; | 72 | int currentGameType; |
73 | int currentGameDifficulty; | 73 | int currentGameDifficulty; |
74 | 74 | ||
75 | QPixmap *offscreen; | 75 | QPixmap *offscreen; |
76 | QTimer *gameTimer; | 76 | QTimer *gameTimer; |
77 | 77 | ||
78 | int score; | 78 | int score; |
79 | int highestScore[3][3]; | 79 | int highestScore[3][3]; |
80 | 80 | ||
81 | int mapTop[MAPSIZE]; | 81 | int mapTop[MAPSIZE]; |
82 | int mapBottom[MAPSIZE]; | 82 | int mapBottom[MAPSIZE]; |
83 | QRect blocks[BLOCKSIZE]; | 83 | QRect blocks[BLOCKSIZE]; |
84 | QRect user; | 84 | QRect user; |
85 | QPoint trail[TRAILSIZE]; | 85 | QPoint trail[TRAILSIZE]; |
86 | 86 | ||
87 | int offset; | 87 | int offset; |
88 | int maxHeight; | 88 | int maxHeight; |
89 | int nrFrames; | 89 | int nrFrames; |
90 | int dir; | 90 | int dir; |
91 | 91 | ||
92 | bool showScoreZones; | 92 | bool showScoreZones; |
93 | 93 | ||
94 | bool press; | 94 | bool press; |
95 | double thrust; | 95 | double thrust; |
96 | bool running; | 96 | bool running; |
97 | 97 | ||
98 | SFCave( int speed = 3, QWidget *p = 0, char *name = 0 ); | 98 | SFCave( int speed = 3, QWidget *p = 0, char *name = 0 ); |
99 | ~SFCave(); | 99 | ~SFCave(); |
100 | void start(); | 100 | void start(); |
101 | void setSeed( int seed ); | 101 | void setSeed( int seed ); |