summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/sfcave/sfcave.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/noncore/games/sfcave/sfcave.cpp b/noncore/games/sfcave/sfcave.cpp
index 929dc41..5633a8f 100644
--- a/noncore/games/sfcave/sfcave.cpp
+++ b/noncore/games/sfcave/sfcave.cpp
@@ -1,627 +1,637 @@
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#include <time.h> 4#include <time.h>
5 5
6#ifdef QWS 6#ifdef QWS
7#include <qpe/qpeapplication.h> 7#include <qpe/qpeapplication.h>
8#include <qpe/config.h> 8#include <qpe/config.h>
9#else 9#else
10#include <qapplication.h> 10#include <qapplication.h>
11#endif 11#endif
12#include <qdir.h> 12#include <qdir.h>
13 13
14#include "helpwindow.h" 14#include "helpwindow.h"
15#include "sfcave.h" 15#include "sfcave.h"
16 16
17#define CAPTION "SFCave 1.11 by AndyQ" 17#define CAPTION "SFCave 1.12 by AndyQ"
18 18
19#define UP_THRUST 0.6 19#define UP_THRUST 0.6
20#define NO_THRUST 0.8 20#define NO_THRUST 0.8
21#define MAX_DOWN_THRUST 4.0 21#define MAX_DOWN_THRUST 4.0
22#define MAX_UP_THRUST -3.5 22#define MAX_UP_THRUST -3.5
23 23
24// States 24// States
25#define STATE_BOSS 0 25#define STATE_BOSS 0
26#define STATE_RUNNING 1 26#define STATE_RUNNING 1
27#define STATE_CRASHING 2 27#define STATE_CRASHING 2
28#define STATE_CRASHED 3 28#define STATE_CRASHED 3
29#define STATE_NEWGAME 4 29#define STATE_NEWGAME 4
30#define STATE_MENU 5 30#define STATE_MENU 5
31#define STATE_REPLAY 6 31#define STATE_REPLAY 6
32 32
33// Menus 33// Menus
34#define MENU_MAIN_MENU 0 34#define MENU_MAIN_MENU 0
35#define MENU_OPTIONS_MENU 1 35#define MENU_OPTIONS_MENU 1
36#define MENU_REPLAY_MENU 2 36#define MENU_REPLAY_MENU 2
37 37
38// Main Menu Options 38// Main Menu Options
39#define MENU_START_GAME 0 39#define MENU_START_GAME 0
40#define MENU_REPLAY 1 40#define MENU_REPLAY 1
41#define MENU_OPTIONS 2 41#define MENU_OPTIONS 2
42#define MENU_HELP 3 42#define MENU_HELP 3
43#define MENU_QUIT 4 43#define MENU_QUIT 4
44 44
45// Option Menu Options 45// Option Menu Options
46#define MENU_GAME_TYPE 0 46#define MENU_GAME_TYPE 0
47#define MENU_GAME_DIFFICULTY 1 47#define MENU_GAME_DIFFICULTY 1
48#define MENU_CLEAR_HIGHSCORES 2 48#define MENU_CLEAR_HIGHSCORES 2
49#define MENU_BACK 3 49#define MENU_BACK 3
50 50
51// Replay Menu Options 51// Replay Menu Options
52#define MENU_REPLAY_START 0 52#define MENU_REPLAY_START 0
53#define MENU_REPLAY_LOAD 1 53#define MENU_REPLAY_LOAD 1
54#define MENU_REPLAY_SAVE 2 54#define MENU_REPLAY_SAVE 2
55#define MENU_REPLAY_BACK 3 55#define MENU_REPLAY_BACK 3
56 56
57 57
58#define NR_GAME_DIFFICULTIES 3 58#define NR_GAME_DIFFICULTIES 3
59#define NR_GAME_TYPES 3 59#define NR_GAME_TYPES 3
60 60
61#define DIFICULTY_EASY 0 61#define DIFICULTY_EASY 0
62#define DIFICULTY_NORMAL 1 62#define DIFICULTY_NORMAL 1
63#define DIFICULTY_HARD 2 63#define DIFICULTY_HARD 2
64#define EASY "Easy" 64#define EASY "Easy"
65#define NORMAL "Normal" 65#define NORMAL "Normal"
66#define HARD "Hard" 66#define HARD "Hard"
67 67
68#define SFCAVE_GAME_TYPE 0 68#define SFCAVE_GAME_TYPE 0
69#define GATES_GAME_TYPE 1 69#define GATES_GAME_TYPE 1
70#define FLY_GAME_TYPE 2 70#define FLY_GAME_TYPE 2
71#define SFCAVE_GAME "SFCave" 71#define SFCAVE_GAME "SFCave"
72#define GATES_GAME "Gates" 72#define GATES_GAME "Gates"
73#define FLY_GAME "Fly" 73#define FLY_GAME "Fly"
74#define CURRENT_GAME_TYPE gameTypes[currentGameType] 74#define CURRENT_GAME_TYPE gameTypes[currentGameType]
75#define CURRENT_GAME_DIFFICULTY difficultyOption[currentGameDifficulty]; 75#define CURRENT_GAME_DIFFICULTY difficultyOption[currentGameDifficulty];
76 76
77QString SFCave::dificultyOption[] = { EASY, NORMAL, HARD }; 77QString SFCave::dificultyOption[] = { EASY, NORMAL, HARD };
78QString SFCave::gameTypes[] = { SFCAVE_GAME, GATES_GAME, FLY_GAME }; 78QString SFCave::gameTypes[] = { SFCAVE_GAME, GATES_GAME, FLY_GAME };
79 79
80QString SFCave::menuOptions[NR_MENUS][MAX_MENU_OPTIONS] = { { "Start Game", "Replays", "Options", "Help", "Quit", "", "", "" }, 80QString SFCave::menuOptions[NR_MENUS][MAX_MENU_OPTIONS] = { { "Start Game", "Replays", "Options", "Help", "Quit", "", "", "" },
81 { "Game Type - %s", "Game Difficulty - %s", "Clear High Scores for this game", "Back", "", "", "", "" }, 81 { "Game Type - %s", "Game Difficulty - %s", "Clear High Scores for this game", "Back", "", "", "", "" },
82 { "Play Reply", "Load Replay", "Save Replay", "Back", "", "", "", "" } }; 82 { "Play Reply", "Load Replay", "Save Replay", "Back", "", "", "", "" } };
83 83
84int SFCave::nrMenuOptions[NR_MENUS] = { 5, 4, 4 }; 84int SFCave::nrMenuOptions[NR_MENUS] = { 5, 4, 4 };
85int SFCave ::currentMenuOption[NR_MENUS] = { 0, 0, 0 }; 85int 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
91double SFCave::UpThrustVals[3][3] = {{ 0.6, 0.6, 0.6 }, // SFCave 91double 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
95double SFCave::DownThrustVals[3][3] = {{ 0.8, 0.8, 0.8 }, // SFCave 95double 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
99double SFCave::MaxUpThrustVals[3][3] = {{ -3.5, -3.5, -3.5 }, // SFCave 99double 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
103double SFCave::MaxDownThrustVals[3][3] = {{ 4.0, 4.0, 4.0 }, // SFCave 103double 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
107int SFCave::initialGateGaps[] = { 75, 50, 25 }; 107int SFCave::initialGateGaps[] = { 75, 50, 25 };
108 108
109 109
110bool movel; 110bool movel;
111 111
112 112
113int main( int argc, char *argv[] ) 113int main( int argc, char *argv[] )
114{ 114{
115 movel = true; 115 movel = true;
116#ifdef QWS 116#ifdef QWS
117 QPEApplication a( argc, argv ); 117 QPEApplication a( argc, argv );
118#else 118#else
119 QApplication a( argc, argv ); 119 QApplication a( argc, argv );
120#endif 120#endif
121 121
122 int speed = 3; 122 int speed = 3;
123 for ( int i = 0 ; i < argc ; ++i ) 123 for ( int i = 0 ; i < argc ; ++i )
124 { 124 {
125 if ( strcmp( argv[i], "-s" ) == 0 ) 125 if ( strcmp( argv[i], "-s" ) == 0 )
126 { 126 {
127 if ( i+1 < argc ) 127 if ( i+1 < argc )
128 speed = atoi( argv[i+1] ); 128 speed = atoi( argv[i+1] );
129 } 129 }
130 } 130 }
131 131
132 SFCave app( speed ); 132 SFCave app( speed );
133 a.setMainWidget( &app ); 133 a.setMainWidget( &app );
134 app.show(); 134 app.show();
135 app.start(); 135 app.start();
136 a.exec(); 136 a.exec();
137} 137}
138 138
139SFCave :: SFCave( int spd, QWidget *w, char *name ) 139SFCave :: SFCave( int spd, QWidget *w, char *name )
140 : QMainWindow( w, name ) 140 : QMainWindow( w, name )
141 141
142{ 142{
143 replayIt = 0; 143 replayIt = 0;
144#ifdef QWS 144#ifdef QWS
145 showMaximized(); 145 showMaximized();
146#else 146#else
147 resize( 240, 284 ); 147 resize( 240, 284 );
148#endif 148#endif
149 149
150 replayFile = QDir::home().path(); 150 replayFile = QDir::home().path();
151 replayFile += "/sfcave.replay"; 151 replayFile += "/sfcave.replay";
152 printf( "%s\n", (const char *)replayFile ); 152 printf( "%s\n", (const char *)replayFile );
153 153
154 sWidth = width(); 154 sWidth = width();
155 sHeight = height(); 155 sHeight = height();
156 segSize = sWidth/(MAPSIZE-1)+1; 156 segSize = sWidth/(MAPSIZE-1)+1;
157 157
158 currentMenuNr = 0; 158 currentMenuNr = 0;
159 currentGameType = 0; 159 currentGameType = 0;
160 currentGameDifficulty = 0; 160 currentGameDifficulty = 0;
161 161
162 setCaption( CAPTION ); 162 setCaption( CAPTION );
163 showScoreZones = false; 163 showScoreZones = false;
164 164
165#ifdef QWS 165#ifdef QWS
166 Config cfg( "sfcave" ); 166 Config cfg( "sfcave" );
167 cfg.setGroup( "settings" ); 167 cfg.setGroup( "settings" );
168 QString key = "highScore_"; 168 QString key = "highScore_";
169 169
170 for ( int i = 0 ; i < 3 ; ++i ) 170 for ( int i = 0 ; i < 3 ; ++i )
171 { 171 {
172 for ( int j = 0 ; j < 3 ; ++j ) 172 for ( int j = 0 ; j < 3 ; ++j )
173 highestScore[i][j] = cfg.readNumEntry( key + gameTypes[i] + "_" + dificultyOption[j], 0 ); 173 highestScore[i][j] = cfg.readNumEntry( key + gameTypes[i] + "_" + dificultyOption[j], 0 );
174 } 174 }
175 175
176 currentGameType = cfg.readNumEntry( "gameType", 0 ); 176 currentGameType = cfg.readNumEntry( "gameType", 0 );
177 currentGameDifficulty = cfg.readNumEntry( "difficulty", 0 ); 177 currentGameDifficulty = cfg.readNumEntry( "difficulty", 0 );
178#endif 178#endif
179 speed = spd; // Change to 2 for PC 179 speed = spd; // Change to 2 for PC
180 press = false; 180 press = false;
181 181
182 offscreen = new QPixmap( sWidth, sHeight ); 182 offscreen = new QPixmap( sWidth, sHeight );
183 offscreen->fill( Qt::black ); 183 offscreen->fill( Qt::black );
184 184
185// setUp(); 185// setUp();
186 crashLineLength = -1; 186 crashLineLength = -1;
187 state = STATE_MENU; 187 state = STATE_MENU;
188 prevState = STATE_MENU; 188 prevState = STATE_MENU;
189 189
190 gameTimer = new QTimer( this, "game timer" ); 190 gameTimer = new QTimer( this, "game timer" );
191 connect( gameTimer, SIGNAL( timeout() ), 191 connect( gameTimer, SIGNAL( timeout() ),
192 this, SLOT( run() ) ); 192 this, SLOT( run() ) );
193} 193}
194 194
195SFCave :: ~SFCave() 195SFCave :: ~SFCave()
196{ 196{
197} 197}
198 198
199void SFCave :: start() 199void SFCave :: start()
200{ 200{
201 gameTimer->start( 10 ); 201 gameTimer->start( 10 );
202 202
203} 203}
204 204
205void SFCave :: setSeed( int seed ) 205void SFCave :: setSeed( int seed )
206{ 206{
207 if ( seed == -1 ) 207 if ( seed == -1 )
208 currentSeed = ((unsigned long) time((time_t *) NULL)); 208 currentSeed = ((unsigned long) time((time_t *) NULL));
209 else 209 else
210 currentSeed = seed; 210 currentSeed = seed;
211 PutSeed( currentSeed ); 211 PutSeed( currentSeed );
212} 212}
213 213
214int SFCave :: nextInt( int range ) 214int SFCave :: nextInt( int range )
215{ 215{
216 int val = (int)(Random( ) * range); 216 int val = (int)(Random( ) * range);
217 217
218 return val; 218 return val;
219 219
220} 220}
221 221
222void SFCave :: setUp() 222void SFCave :: setUp()
223{ 223{
224 score = 0; 224 score = 0;
225 offset = 0; 225 offset = 0;
226 nrFrames = 0; 226 nrFrames = 0;
227 dir = 1; 227 dir = 1;
228 thrust = 0; 228 thrust = 0;
229 229
230 int dist[] = { 100, 60, 40 };
230 if ( CURRENT_GAME_TYPE == SFCAVE_GAME ) 231 if ( CURRENT_GAME_TYPE == SFCAVE_GAME )
231 { 232 {
232 thrustUp = UpThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];; 233 thrustUp = UpThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];;
233 noThrust = DownThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];; 234 noThrust = DownThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];;
234 maxUpThrust = MaxUpThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];; 235 maxUpThrust = MaxUpThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];;
235 maxDownThrust = MaxDownThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];; 236 maxDownThrust = MaxDownThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];;
237
238 if ( currentCameDifficulty == DIFICULTY_EASY )
239 gateDistance = 100;
240 else if ( currentCameDifficulty == DIFICULTY_EASY )
241 gateDistance = 60;
242 else
243 gateDistance = 40;
244
245 printf( "GD = %d\n", gateDistance );
236 } 246 }
237 else if ( CURRENT_GAME_TYPE == GATES_GAME ) 247 else if ( CURRENT_GAME_TYPE == GATES_GAME )
238 { 248 {
239 thrustUp = UpThrustVals[GATES_GAME_TYPE][currentGameDifficulty];; 249 thrustUp = UpThrustVals[GATES_GAME_TYPE][currentGameDifficulty];;
240 noThrust = DownThrustVals[GATES_GAME_TYPE][currentGameDifficulty];; 250 noThrust = DownThrustVals[GATES_GAME_TYPE][currentGameDifficulty];;
241 maxUpThrust = MaxUpThrustVals[GATES_GAME_TYPE][currentGameDifficulty];; 251 maxUpThrust = MaxUpThrustVals[GATES_GAME_TYPE][currentGameDifficulty];;
242 maxDownThrust = MaxDownThrustVals[GATES_GAME_TYPE][currentGameDifficulty];; 252 maxDownThrust = MaxDownThrustVals[GATES_GAME_TYPE][currentGameDifficulty];;
253 gateDistance = 75;
254 nextGate = nextInt( 50 ) + gateDistance;
243 } 255 }
244 else 256 else
245 { 257 {
246 thrustUp = UpThrustVals[FLY_GAME_TYPE][currentGameDifficulty]; 258 thrustUp = UpThrustVals[FLY_GAME_TYPE][currentGameDifficulty];
247 noThrust = DownThrustVals[FLY_GAME_TYPE][currentGameDifficulty]; 259 noThrust = DownThrustVals[FLY_GAME_TYPE][currentGameDifficulty];
248 maxUpThrust = MaxUpThrustVals[FLY_GAME_TYPE][currentGameDifficulty]; 260 maxUpThrust = MaxUpThrustVals[FLY_GAME_TYPE][currentGameDifficulty];
249 maxDownThrust = MaxDownThrustVals[FLY_GAME_TYPE][currentGameDifficulty]; 261 maxDownThrust = MaxDownThrustVals[FLY_GAME_TYPE][currentGameDifficulty];
250 } 262 }
251 263
252 crashLineLength = 0; 264 crashLineLength = 0;
253 lastGateBottomY = 0; 265 lastGateBottomY = 0;
254 266
255 user.setRect( 50, sWidth/2, 4, 4 ); 267 user.setRect( 50, sWidth/2, 4, 4 );
256 268
257 blockWidth = 20; 269 blockWidth = 20;
258 blockHeight = 70; 270 blockHeight = 70;
259 gapHeight = initialGateGaps[currentGameDifficulty]; 271 gapHeight = initialGateGaps[currentGameDifficulty];
260 gateDistance = 75;
261 nextGate = nextInt( 50 ) + gateDistance;
262 272
263 for ( int i = 0 ; i < TRAILSIZE ; ++i ) 273 for ( int i = 0 ; i < TRAILSIZE ; ++i )
264 { 274 {
265 trail[i].setX( -1 ); 275 trail[i].setX( -1 );
266 trail[i].setY( 0 ); 276 trail[i].setY( 0 );
267 } 277 }
268 278
269 if ( CURRENT_GAME_TYPE != FLY_GAME ) 279 if ( CURRENT_GAME_TYPE != FLY_GAME )
270 { 280 {
271 maxHeight = 50; 281 maxHeight = 50;
272 282
273 mapTop[0] = (int)(nextInt(50)) + 5; 283 mapTop[0] = (int)(nextInt(50)) + 5;
274 mapBottom[0] = (int)(nextInt(50)) + 5; 284 mapBottom[0] = (int)(nextInt(50)) + 5;
275 for ( int i = 1 ; i < MAPSIZE ; ++i ) 285 for ( int i = 1 ; i < MAPSIZE ; ++i )
276 setPoint( i ); 286 setPoint( i );
277 } 287 }
278 else 288 else
279 { 289 {
280 maxHeight = 100; 290 maxHeight = 100;
281 291
282 for ( int i = 0 ; i < MAPSIZE ; ++i ) 292 for ( int i = 0 ; i < MAPSIZE ; ++i )
283 mapBottom[i] = sHeight - 10; 293 mapBottom[i] = sHeight - 10;
284 } 294 }
285 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 295 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
286 blocks[i].setY( -1 ); 296 blocks[i].setY( -1 );
287 297
288} 298}
289 299
290void SFCave :: run() 300void SFCave :: run()
291{ 301{
292 switch ( state ) 302 switch ( state )
293 { 303 {
294 case STATE_MENU: 304 case STATE_MENU:
295 displayMenu(); 305 displayMenu();
296 break; 306 break;
297 case STATE_NEWGAME: 307 case STATE_NEWGAME:
298 setSeed( -1 ); 308 setSeed( -1 );
299 setUp(); 309 setUp();
300 draw(); 310 draw();
301 state = STATE_RUNNING; 311 state = STATE_RUNNING;
302 replay = false; 312 replay = false;
303 replayList.clear(); 313 replayList.clear();
304 break; 314 break;
305 case STATE_REPLAY: 315 case STATE_REPLAY:
306 setSeed( currentSeed ); 316 setSeed( currentSeed );
307 setUp(); 317 setUp();
308 draw(); 318 draw();
309 state = STATE_RUNNING; 319 state = STATE_RUNNING;
310 replay = true; 320 replay = true;
311 if ( replayIt ) 321 if ( replayIt )
312 delete replayIt; 322 delete replayIt;
313 replayIt = new QListIterator<int>( replayList ); 323 replayIt = new QListIterator<int>( replayList );
314 case STATE_BOSS: 324 case STATE_BOSS:
315 drawBoss(); 325 drawBoss();
316 break; 326 break;
317 327
318 case STATE_CRASHING: 328 case STATE_CRASHING:
319 case STATE_CRASHED: 329 case STATE_CRASHED:
320 draw(); 330 draw();
321 break; 331 break;
322 332
323 case STATE_RUNNING: 333 case STATE_RUNNING:
324 { 334 {
325 if ( nrFrames % 2 == 0 ) 335 if ( nrFrames % 2 == 0 )
326 handleKeys(); 336 handleKeys();
327 337
328 // Apply Game rules 338 // Apply Game rules
329 nrFrames ++; 339 nrFrames ++;
330 340
331 if ( replay ) 341 if ( replay )
332 { 342 {
333 while( replayIt->current() && *(replayIt->current()) == nrFrames ) 343 while( replayIt->current() && *(replayIt->current()) == nrFrames )
334 { 344 {
335 press = !press; 345 press = !press;
336 ++(*replayIt); 346 ++(*replayIt);
337 } 347 }
338 } 348 }
339 349
340 if ( CURRENT_GAME_TYPE == SFCAVE_GAME ) 350 if ( CURRENT_GAME_TYPE == SFCAVE_GAME )
341 handleGameSFCave(); 351 handleGameSFCave();
342 else if ( CURRENT_GAME_TYPE == GATES_GAME ) 352 else if ( CURRENT_GAME_TYPE == GATES_GAME )
343 handleGameGates(); 353 handleGameGates();
344 else if ( CURRENT_GAME_TYPE == FLY_GAME ) 354 else if ( CURRENT_GAME_TYPE == FLY_GAME )
345 handleGameFly(); 355 handleGameFly();
346 356
347 draw(); 357 draw();
348 break; 358 break;
349 } 359 }
350 } 360 }
351} 361}
352 362
353void SFCave :: handleGameSFCave() 363void SFCave :: handleGameSFCave()
354{ 364{
355 // Update score 365 // Update score
356 if ( nrFrames % 5 == 0 ) 366 if ( nrFrames % 5 == 0 )
357 score ++; 367 score ++;
358 368
359 if ( nrFrames % 500 == 0 ) 369 if ( nrFrames % 500 == 0 )
360 { 370 {
361 if ( maxHeight < sHeight - 100 ) 371 if ( maxHeight < sHeight - 100 )
362 { 372 {
363 maxHeight += 10; 373 maxHeight += 10;
364 374
365 // Reduce block height 375 // Reduce block height
366 if ( maxHeight > sHeight - 150 ) 376 if ( maxHeight > sHeight - 150 )
367 blockHeight -= 5; 377 blockHeight -= 5;
368 } 378 }
369 } 379 }
370 380
371 if ( nrFrames % 100 == 0 ) 381 if ( nrFrames % gateDistance == 0 )
372 addBlock(); 382 addBlock();
373 383
374 if ( checkCollision() ) 384 if ( checkCollision() )
375 { 385 {
376 if ( score > highestScore[currentGameType][currentGameDifficulty] ) 386 if ( score > highestScore[currentGameType][currentGameDifficulty] )
377 { 387 {
378 highestScore[currentGameType][currentGameDifficulty] = score; 388 highestScore[currentGameType][currentGameDifficulty] = score;
379 saveScore(); 389 saveScore();
380 } 390 }
381 state = STATE_CRASHING; 391 state = STATE_CRASHING;
382 } 392 }
383 else 393 else
384 { 394 {
385 moveLandscape(); 395 moveLandscape();
386 } 396 }
387 397
388} 398}
389 399
390 400
391void SFCave :: handleGameGates() 401void SFCave :: handleGameGates()
392{ 402{
393 // Update score 403 // Update score
394 if ( nrFrames % 5 == 0 ) 404 if ( nrFrames % 5 == 0 )
395 score ++; 405 score ++;
396 406
397 // Slightly random gap distance 407 // Slightly random gap distance
398 if ( nrFrames >= nextGate ) 408 if ( nrFrames >= nextGate )
399 { 409 {
400 nextGate = nrFrames + nextInt( 50 ) + gateDistance; 410 nextGate = nrFrames + nextInt( 50 ) + gateDistance;
401 addGate(); 411 addGate();
402 } 412 }
403 413
404 if ( nrFrames % 500 == 0 ) 414 if ( nrFrames % 500 == 0 )
405 { 415 {
406 if ( gapHeight > 75 ) 416 if ( gapHeight > 75 )
407 gapHeight -= 5; 417 gapHeight -= 5;
408 } 418 }
409 419
410 if ( checkCollision() ) 420 if ( checkCollision() )
411 { 421 {
412 if ( score > highestScore[currentGameType][currentGameDifficulty] ) 422 if ( score > highestScore[currentGameType][currentGameDifficulty] )
413 { 423 {
414 highestScore[currentGameType][currentGameDifficulty] = score; 424 highestScore[currentGameType][currentGameDifficulty] = score;
415 saveScore(); 425 saveScore();
416 } 426 }
417 state = STATE_CRASHING; 427 state = STATE_CRASHING;
418 } 428 }
419 else 429 else
420 { 430 {
421 moveLandscape(); 431 moveLandscape();
422 } 432 }
423 433
424} 434}
425 435
426void SFCave :: handleGameFly() 436void SFCave :: handleGameFly()
427{ 437{
428 if ( nrFrames % 4 == 0 ) 438 if ( nrFrames % 4 == 0 )
429 { 439 {
430 // Update score 440 // Update score
431 // get distance between landscape and ship 441 // get distance between landscape and ship
432 int diff = mapBottom[10] - user.y(); 442 int diff = mapBottom[10] - user.y();
433 443
434 // the closer the difference is to 0 means more points 444 // the closer the difference is to 0 means more points
435 if ( diff < 10 ) 445 if ( diff < 10 )
436 score += 5; 446 score += 5;
437 else if ( diff < 20 ) 447 else if ( diff < 20 )
438 score += 3; 448 score += 3;
439 else if ( diff < 30 ) 449 else if ( diff < 30 )
440 score += 2; 450 score += 2;
441 else if ( diff < 40 ) 451 else if ( diff < 40 )
442 score += 1; 452 score += 1;
443 } 453 }
444 454
445 if ( checkFlyGameCollision() ) 455 if ( checkFlyGameCollision() )
446 { 456 {
447 if ( score > highestScore[currentGameType][currentGameDifficulty] ) 457 if ( score > highestScore[currentGameType][currentGameDifficulty] )
448 { 458 {
449 highestScore[currentGameType][currentGameDifficulty] = score; 459 highestScore[currentGameType][currentGameDifficulty] = score;
450 saveScore(); 460 saveScore();
451 } 461 }
452 state = STATE_CRASHING; 462 state = STATE_CRASHING;
453 } 463 }
454 else 464 else
455 { 465 {
456 moveFlyGameLandscape(); 466 moveFlyGameLandscape();
457 } 467 }
458} 468}
459 469
460bool SFCave :: checkFlyGameCollision() 470bool SFCave :: checkFlyGameCollision()
461{ 471{
462 if ( (user.y() + user.width()) >= mapBottom[11] ) 472 if ( (user.y() + user.width()) >= mapBottom[11] )
463 return true; 473 return true;
464 474
465 return false; 475 return false;
466} 476}
467 477
468void SFCave :: moveFlyGameLandscape() 478void SFCave :: moveFlyGameLandscape()
469{ 479{
470 offset++; 480 offset++;
471 481
472 if ( offset >= segSize ) 482 if ( offset >= segSize )
473 { 483 {
474 offset = 0; 484 offset = 0;
475 for ( int i = 0 ; i < MAPSIZE-speed ; ++i ) 485 for ( int i = 0 ; i < MAPSIZE-speed ; ++i )
476 mapBottom[i] = mapBottom[i+speed]; 486 mapBottom[i] = mapBottom[i+speed];
477 487
478 for ( int i = speed ; i > 0 ; --i ) 488 for ( int i = speed ; i > 0 ; --i )
479 setFlyPoint( MAPSIZE-i ); 489 setFlyPoint( MAPSIZE-i );
480 } 490 }
481} 491}
482 492
483void SFCave :: setFlyPoint( int point ) 493void SFCave :: setFlyPoint( int point )
484{ 494{
485 static int fly_difficulty_levels[] = { 5, 10, 15 }; 495 static int fly_difficulty_levels[] = { 5, 10, 15 };
486 if ( nextInt(100) >= 75 ) 496 if ( nextInt(100) >= 75 )
487 dir *= -1; 497 dir *= -1;
488 498
489 int prevPoint = mapBottom[point-1]; 499 int prevPoint = mapBottom[point-1];
490 500
491 int nextPoint = prevPoint + (dir * nextInt( fly_difficulty_levels[currentGameDifficulty] ) ); 501 int nextPoint = prevPoint + (dir * nextInt( fly_difficulty_levels[currentGameDifficulty] ) );
492 502
493 if ( nextPoint > sHeight ) 503 if ( nextPoint > sHeight )
494 { 504 {
495 nextPoint = sHeight; 505 nextPoint = sHeight;
496 dir *= -1; 506 dir *= -1;
497 } 507 }
498 else if ( nextPoint < maxHeight ) 508 else if ( nextPoint < maxHeight )
499 { 509 {
500 nextPoint = maxHeight; 510 nextPoint = maxHeight;
501 dir *= 1; 511 dir *= 1;
502 } 512 }
503 513
504 mapBottom[point] = nextPoint; 514 mapBottom[point] = nextPoint;
505} 515}
506 516
507bool SFCave :: checkCollision() 517bool SFCave :: checkCollision()
508{ 518{
509 if ( (user.y() + user.width()) >= mapBottom[11] || user.y() <= mapTop[11] ) 519 if ( (user.y() + user.width()) >= mapBottom[11] || user.y() <= mapTop[11] )
510 return true; 520 return true;
511 521
512 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 522 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
513 { 523 {
514 if ( blocks[i].y() != -1 ) 524 if ( blocks[i].y() != -1 )
515 { 525 {
516 if ( blocks[i].intersects( user ) ) 526 if ( blocks[i].intersects( user ) )
517 return true; 527 return true;
518 } 528 }
519 } 529 }
520 return false; 530 return false;
521} 531}
522 532
523void SFCave :: moveLandscape() 533void SFCave :: moveLandscape()
524{ 534{
525 offset++; 535 offset++;
526 536
527 if ( offset >= segSize ) 537 if ( offset >= segSize )
528 { 538 {
529 offset = 0; 539 offset = 0;
530 for ( int i = 0 ; i < MAPSIZE-speed ; ++i ) 540 for ( int i = 0 ; i < MAPSIZE-speed ; ++i )
531 { 541 {
532 mapTop[i] = mapTop[i+speed]; 542 mapTop[i] = mapTop[i+speed];
533 mapBottom[i] = mapBottom[i+speed]; 543 mapBottom[i] = mapBottom[i+speed];
534 } 544 }
535 545
536 for ( int i = speed ; i > 0 ; --i ) 546 for ( int i = speed ; i > 0 ; --i )
537 setPoint( MAPSIZE-i ); 547 setPoint( MAPSIZE-i );
538 } 548 }
539 549
540 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 550 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
541 { 551 {
542 if ( blocks[i].y() != -1 ) 552 if ( blocks[i].y() != -1 )
543 { 553 {
544 blocks[i].moveBy( -speed, 0 ); 554 blocks[i].moveBy( -speed, 0 );
545 if ( blocks[i].x() + blocks[i].width() < 0 ) 555 if ( blocks[i].x() + blocks[i].width() < 0 )
546 blocks[i].setY( -1 ); 556 blocks[i].setY( -1 );
547 } 557 }
548 } 558 }
549} 559}
550 560
551void SFCave :: addBlock() 561void SFCave :: addBlock()
552{ 562{
553 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 563 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
554 { 564 {
555 if ( blocks[i].y() == -1 ) 565 if ( blocks[i].y() == -1 )
556 { 566 {
557 int x = sWidth; 567 int x = sWidth;
558 568
559 int y = mapTop[50] + (int)(nextInt(mapBottom[50] - mapTop[50] - blockHeight)); 569 int y = mapTop[50] + (int)(nextInt(mapBottom[50] - mapTop[50] - blockHeight));
560 570
561 blocks[i].setRect( x, y, blockWidth, blockHeight ); 571 blocks[i].setRect( x, y, blockWidth, blockHeight );
562 572
563 break; 573 break;
564 } 574 }
565 } 575 }
566} 576}
567 577
568void SFCave :: addGate() 578void SFCave :: addGate()
569{ 579{
570 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 580 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
571 { 581 {
572 if ( blocks[i].y() == -1 ) 582 if ( blocks[i].y() == -1 )
573 { 583 {
574 int x1 = sWidth; 584 int x1 = sWidth;
575 int y1 = mapTop[50]; 585 int y1 = mapTop[50];
576 int b1Height = nextInt(mapBottom[50] - mapTop[50] - gapHeight); 586 int b1Height = nextInt(mapBottom[50] - mapTop[50] - gapHeight);
577 587
578 // See if height between last gate and this one is too big 588 // See if height between last gate and this one is too big
579 if ( b1Height - 100 > lastGateBottomY ) 589 if ( b1Height - 100 > lastGateBottomY )
580 b1Height -= 25; 590 b1Height -= 25;
581 else if ( b1Height + 100 < lastGateBottomY ) 591 else if ( b1Height + 100 < lastGateBottomY )
582 b1Height += 25; 592 b1Height += 25;
583 lastGateBottomY = b1Height; 593 lastGateBottomY = b1Height;
584 594
585 595
586 int x2 = sWidth; 596 int x2 = sWidth;
587 int y2 = y1 + b1Height + gapHeight; 597 int y2 = y1 + b1Height + gapHeight;
588 int b2Height = mapBottom[50] - y2; 598 int b2Height = mapBottom[50] - y2;
589 599
590 600
591 blocks[i].setRect( x1, y1, blockWidth, b1Height ); 601 blocks[i].setRect( x1, y1, blockWidth, b1Height );
592 blocks[i+1].setRect( x2, y2, blockWidth, b2Height ); 602 blocks[i+1].setRect( x2, y2, blockWidth, b2Height );
593 603
594 break; 604 break;
595 } 605 }
596 } 606 }
597} 607}
598 608
599void SFCave :: setPoint( int point ) 609void SFCave :: setPoint( int point )
600{ 610{
601 if ( nextInt(100) >= 80 ) 611 if ( nextInt(100) >= 80 )
602 dir *= -1; 612 dir *= -1;
603 613
604 mapTop[point] = mapTop[point-1] + (dir * nextInt( 5 ) ); 614 mapTop[point] = mapTop[point-1] + (dir * nextInt( 5 ) );
605 if ( mapTop[point] < 0 ) 615 if ( mapTop[point] < 0 )
606 { 616 {
607 mapTop[point] = 0; 617 mapTop[point] = 0;
608 dir *= -1; 618 dir *= -1;
609 } 619 }
610 else if ( mapTop[point] >= maxHeight ) 620 else if ( mapTop[point] >= maxHeight )
611 { 621 {
612 mapTop[point] = maxHeight; 622 mapTop[point] = maxHeight;
613 dir *= -1; 623 dir *= -1;
614 } 624 }
615 625
616// mapBottom[point] = sHeight - (maxHeight - mapBottom[point]); 626// mapBottom[point] = sHeight - (maxHeight - mapBottom[point]);
617 mapBottom[point] = sHeight - (maxHeight - mapTop[point]); 627 mapBottom[point] = sHeight - (maxHeight - mapTop[point]);
618} 628}
619 629
620void SFCave :: drawBoss() 630void SFCave :: drawBoss()
621{ 631{
622 offscreen->fill( Qt::black ); 632 offscreen->fill( Qt::black );
623 633
624 bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true ); 634 bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true );
625} 635}
626 636
627void SFCave :: draw() 637void SFCave :: draw()