summaryrefslogtreecommitdiff
authorandyq <andyq>2002-12-13 15:03:41 (UTC)
committer andyq <andyq>2002-12-13 15:03:41 (UTC)
commit28a78f938ae995fbc29f76afa84b1bee62178a79 (patch) (unidiff)
tree47fdf14787de5748acafb151a63222b726a42a20
parent18c7cd23a85562cd23a4161e1006138e602a0be7 (diff)
downloadopie-28a78f938ae995fbc29f76afa84b1bee62178a79.zip
opie-28a78f938ae995fbc29f76afa84b1bee62178a79.tar.gz
opie-28a78f938ae995fbc29f76afa84b1bee62178a79.tar.bz2
Cleanup up some code, replays now know what game they were saved for, moved
the replay stuff into its own menu, and allowed the menus to have3 more items each.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/sfcave/sfcave.cpp367
-rw-r--r--noncore/games/sfcave/sfcave.h10
2 files changed, 219 insertions, 158 deletions
diff --git a/noncore/games/sfcave/sfcave.cpp b/noncore/games/sfcave/sfcave.cpp
index d551afe..0160d34 100644
--- a/noncore/games/sfcave/sfcave.cpp
+++ b/noncore/games/sfcave/sfcave.cpp
@@ -1,1105 +1,1164 @@
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.10 by AndyQ" 17#define CAPTION "SFCave 1.10 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 37
37// Main Menu Options 38// Main Menu Options
38#define MENU_START_GAME 0 39#define MENU_START_GAME 0
39#define MENU_OPTIONS 1 40#define MENU_REPLAY 1
40#define MENU_HELP 2 41#define MENU_OPTIONS 2
41#define MENU_QUIT 3 42#define MENU_HELP 3
43#define MENU_QUIT 4
42 44
43// Option Menu Options 45// Option Menu Options
44#define MENU_GAME_TYPE 0 46#define MENU_GAME_TYPE 0
45#define MENU_GAME_DIFFICULTY 1 47#define MENU_GAME_DIFFICULTY 1
46#define MENU_CLEAR_HIGHSCORES 2 48#define MENU_CLEAR_HIGHSCORES 2
47#define MENU_BACK 3 49#define MENU_BACK 3
48 50
51// Replay Menu Options
52#define MENU_REPLAY_START 0
53#define MENU_REPLAY_LOAD 1
54#define MENU_REPLAY_SAVE 2
55#define MENU_REPLAY_BACK 3
56
49 57
50#define NR_GAME_DIFFICULTIES 3 58#define NR_GAME_DIFFICULTIES 3
51#define NR_GAME_TYPES 3 59#define NR_GAME_TYPES 3
52 60
53#define DIFICULTY_EASY 0 61#define DIFICULTY_EASY 0
54#define DIFICULTY_NORMAL 1 62#define DIFICULTY_NORMAL 1
55#define DIFICULTY_HARD 2 63#define DIFICULTY_HARD 2
56#define EASY "Easy" 64#define EASY "Easy"
57#define NORMAL "Normal" 65#define NORMAL "Normal"
58#define HARD "Hard" 66#define HARD "Hard"
59 67
60#define SFCAVE_GAME_TYPE 0 68#define SFCAVE_GAME_TYPE 0
61#define GATES_GAME_TYPE 1 69#define GATES_GAME_TYPE 1
62#define FLY_GAME_TYPE 2 70#define FLY_GAME_TYPE 2
63#define SFCAVE_GAME "SFCave" 71#define SFCAVE_GAME "SFCave"
64#define GATES_GAME "Gates" 72#define GATES_GAME "Gates"
65#define FLY_GAME "Fly" 73#define FLY_GAME "Fly"
66#define CURRENT_GAME_TYPE gameTypes[currentGameType] 74#define CURRENT_GAME_TYPE gameTypes[currentGameType]
67#define CURRENT_GAME_DIFFICULTY difficultyOption[currentGameDifficulty]; 75#define CURRENT_GAME_DIFFICULTY difficultyOption[currentGameDifficulty];
68 76
69QString SFCave::dificultyOption[] = { EASY, NORMAL, HARD }; 77QString SFCave::dificultyOption[] = { EASY, NORMAL, HARD };
70QString SFCave::gameTypes[] = { SFCAVE_GAME, GATES_GAME, FLY_GAME }; 78QString SFCave::gameTypes[] = { SFCAVE_GAME, GATES_GAME, FLY_GAME };
71 79
72QString SFCave::menuOptions[2][5] = { { "Start Game", "Options", "Help", "Quit", "" }, 80QString SFCave::menuOptions[NR_MENUS][MAX_MENU_OPTIONS] = { { "Start Game", "Replays", "Options", "Help", "Quit", "", "", "" },
73 { "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", "", "", "", "" } };
74 83
84int SFCave::nrMenuOptions[NR_MENUS] = { 5, 4, 4 };
85int SFCave ::currentMenuOption[NR_MENUS] = { 0, 0, 0 };
86
75#define UP_THRUST 0.6 87#define UP_THRUST 0.6
76#define NO_THRUST 0.8 88#define NO_THRUST 0.8
77#define MAX_DOWN_THRUST 4.0 89#define MAX_DOWN_THRUST 4.0
78#define MAX_UP_THRUST -3.5 90#define MAX_UP_THRUST -3.5
79double SFCave::UpThrustVals[3][3] = {{ 0.6, 0.6, 0.6 }, // SFCave 91double SFCave::UpThrustVals[3][3] = {{ 0.6, 0.6, 0.6 }, // SFCave
80 { 0.6, 0.6, 0.8 }, // Gates 92 { 0.6, 0.6, 0.8 }, // Gates
81 { 0.4, 0.7, 1.0 } }; // Fly 93 { 0.4, 0.7, 1.0 } }; // Fly
82 94
83double SFCave::DownThrustVals[3][3] = {{ 0.8, 0.8, 0.8 }, // SFCave 95double SFCave::DownThrustVals[3][3] = {{ 0.8, 0.8, 0.8 }, // SFCave
84 { 0.8, 0.8, 1.0 }, // Gates 96 { 0.8, 0.8, 1.0 }, // Gates
85 { 0.4, 0.7, 1.0 } }; // Fly 97 { 0.4, 0.7, 1.0 } }; // Fly
86 98
87double SFCave::MaxUpThrustVals[3][3] = {{ -3.5, -3.5, -3.5 }, // SFCave 99double SFCave::MaxUpThrustVals[3][3] = {{ -3.5, -3.5, -3.5 }, // SFCave
88 { -3.5, -4.0, -5.0 }, // Gates 100 { -3.5, -4.0, -5.0 }, // Gates
89 { -3.5, -4.0, -5.0 } }; // Fly 101 { -3.5, -4.0, -5.0 } }; // Fly
90 102
91double SFCave::MaxDownThrustVals[3][3] = {{ 4.0, 4.0, 4.0 }, // SFCave 103double SFCave::MaxDownThrustVals[3][3] = {{ 4.0, 4.0, 4.0 }, // SFCave
92 { 4.0, 5.0, 5.5 }, // Gates 104 { 4.0, 5.0, 5.5 }, // Gates
93 { 3.5, 4.0, 5.0 } }; // Fly 105 { 3.5, 4.0, 5.0 } }; // Fly
94 106
95int SFCave::initialGateGaps[] = { 75, 50, 25 }; 107int SFCave::initialGateGaps[] = { 75, 50, 25 };
96 108
97int SFCave::nrMenuOptions[2] = { 4, 4 };
98int SFCave ::currentMenuOption[2] = { 0, 0 };
99 109
100bool movel; 110bool movel;
101 111
102 112
103int main( int argc, char *argv[] ) 113int main( int argc, char *argv[] )
104{ 114{
105 movel = true; 115 movel = true;
106#ifdef QWS 116#ifdef QWS
107 QPEApplication a( argc, argv ); 117 QPEApplication a( argc, argv );
108#else 118#else
109 QApplication a( argc, argv ); 119 QApplication a( argc, argv );
110#endif 120#endif
111 121
112 int speed = 3; 122 int speed = 3;
113 for ( int i = 0 ; i < argc ; ++i ) 123 for ( int i = 0 ; i < argc ; ++i )
114 { 124 {
115 if ( strcmp( argv[i], "-s" ) == 0 ) 125 if ( strcmp( argv[i], "-s" ) == 0 )
116 { 126 {
117 if ( i+1 < argc ) 127 if ( i+1 < argc )
118 speed = atoi( argv[i+1] ); 128 speed = atoi( argv[i+1] );
119 } 129 }
120 } 130 }
121 131
122 SFCave app( speed ); 132 SFCave app( speed );
123 a.setMainWidget( &app ); 133 a.setMainWidget( &app );
124 app.show(); 134 app.show();
125 app.start(); 135 app.start();
126 a.exec(); 136 a.exec();
127} 137}
128 138
129SFCave :: SFCave( int spd, QWidget *w, char *name ) 139SFCave :: SFCave( int spd, QWidget *w, char *name )
130 : QMainWindow( w, name ) 140 : QMainWindow( w, name )
131 141
132{ 142{
133 replayIt = 0; 143 replayIt = 0;
134#ifdef QWS 144#ifdef QWS
135 showMaximized(); 145 showMaximized();
136#else 146#else
137 resize( 240, 284 ); 147 resize( 240, 284 );
138#endif 148#endif
139 149
140 replayFile = QDir::home().path(); 150 replayFile = QDir::home().path();
141 replayFile += "/sfcave.replay"; 151 replayFile += "/sfcave.replay";
142 printf( "%s\n", (const char *)replayFile ); 152 printf( "%s\n", (const char *)replayFile );
143 153
144 sWidth = width(); 154 sWidth = width();
145 sHeight = height(); 155 sHeight = height();
146 segSize = sWidth/(MAPSIZE-1)+1; 156 segSize = sWidth/(MAPSIZE-1)+1;
147 157
148 currentMenuNr = 0; 158 currentMenuNr = 0;
149 currentGameType = 0; 159 currentGameType = 0;
150 currentGameDifficulty = 0; 160 currentGameDifficulty = 0;
151 161
152 setCaption( CAPTION ); 162 setCaption( CAPTION );
153 showScoreZones = false; 163 showScoreZones = false;
154 164
155#ifdef QWS 165#ifdef QWS
156 Config cfg( "sfcave" ); 166 Config cfg( "sfcave" );
157 cfg.setGroup( "settings" ); 167 cfg.setGroup( "settings" );
158 QString key = "highScore_"; 168 QString key = "highScore_";
159 169
160 for ( int i = 0 ; i < 3 ; ++i ) 170 for ( int i = 0 ; i < 3 ; ++i )
161 { 171 {
162 for ( int j = 0 ; j < 3 ; ++j ) 172 for ( int j = 0 ; j < 3 ; ++j )
163 highestScore[i][j] = cfg.readNumEntry( key + gameTypes[i] + "_" + dificultyOption[j], 0 ); 173 highestScore[i][j] = cfg.readNumEntry( key + gameTypes[i] + "_" + dificultyOption[j], 0 );
164 } 174 }
165 175
166 currentGameType = cfg.readNumEntry( "gameType", 0 ); 176 currentGameType = cfg.readNumEntry( "gameType", 0 );
167 currentGameDifficulty = cfg.readNumEntry( "difficulty", 0 ); 177 currentGameDifficulty = cfg.readNumEntry( "difficulty", 0 );
168#endif 178#endif
169 speed = spd; // Change to 2 for PC 179 speed = spd; // Change to 2 for PC
170 press = false; 180 press = false;
171 181
172 offscreen = new QPixmap( sWidth, sHeight ); 182 offscreen = new QPixmap( sWidth, sHeight );
173 offscreen->fill( Qt::black ); 183 offscreen->fill( Qt::black );
174 184
175// setUp(); 185// setUp();
176 crashLineLength = -1; 186 crashLineLength = -1;
177 state = STATE_MENU; 187 state = STATE_MENU;
178 prevState = STATE_MENU; 188 prevState = STATE_MENU;
179 189
180 gameTimer = new QTimer( this, "game timer" ); 190 gameTimer = new QTimer( this, "game timer" );
181 connect( gameTimer, SIGNAL( timeout() ), 191 connect( gameTimer, SIGNAL( timeout() ),
182 this, SLOT( run() ) ); 192 this, SLOT( run() ) );
183} 193}
184 194
185SFCave :: ~SFCave() 195SFCave :: ~SFCave()
186{ 196{
187} 197}
188 198
189void SFCave :: start() 199void SFCave :: start()
190{ 200{
191 gameTimer->start( 10 ); 201 gameTimer->start( 10 );
192 202
193} 203}
194 204
195void SFCave :: setSeed( int seed ) 205void SFCave :: setSeed( int seed )
196{ 206{
197 if ( seed == -1 ) 207 if ( seed == -1 )
198 currentSeed = ((unsigned long) time((time_t *) NULL)); 208 currentSeed = ((unsigned long) time((time_t *) NULL));
199 else 209 else
200 currentSeed = seed; 210 currentSeed = seed;
201 PutSeed( currentSeed ); 211 PutSeed( currentSeed );
202} 212}
203 213
204int SFCave :: nextInt( int range ) 214int SFCave :: nextInt( int range )
205{ 215{
206 int val = (int)(Random( ) * range); 216 int val = (int)(Random( ) * range);
207 217
208 return val; 218 return val;
209 219
210} 220}
211 221
212void SFCave :: setUp() 222void SFCave :: setUp()
213{ 223{
214 score = 0; 224 score = 0;
215 offset = 0; 225 offset = 0;
216 nrFrames = 0; 226 nrFrames = 0;
217 dir = 1; 227 dir = 1;
218 thrust = 0; 228 thrust = 0;
219 229
220 if ( CURRENT_GAME_TYPE == SFCAVE_GAME ) 230 if ( CURRENT_GAME_TYPE == SFCAVE_GAME )
221 { 231 {
222 thrustUp = UpThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];; 232 thrustUp = UpThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];;
223 noThrust = DownThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];; 233 noThrust = DownThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];;
224 maxUpThrust = MaxUpThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];; 234 maxUpThrust = MaxUpThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];;
225 maxDownThrust = MaxDownThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];; 235 maxDownThrust = MaxDownThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];;
226 } 236 }
227 else if ( CURRENT_GAME_TYPE == GATES_GAME ) 237 else if ( CURRENT_GAME_TYPE == GATES_GAME )
228 { 238 {
229 thrustUp = UpThrustVals[GATES_GAME_TYPE][currentGameDifficulty];; 239 thrustUp = UpThrustVals[GATES_GAME_TYPE][currentGameDifficulty];;
230 noThrust = DownThrustVals[GATES_GAME_TYPE][currentGameDifficulty];; 240 noThrust = DownThrustVals[GATES_GAME_TYPE][currentGameDifficulty];;
231 maxUpThrust = MaxUpThrustVals[GATES_GAME_TYPE][currentGameDifficulty];; 241 maxUpThrust = MaxUpThrustVals[GATES_GAME_TYPE][currentGameDifficulty];;
232 maxDownThrust = MaxDownThrustVals[GATES_GAME_TYPE][currentGameDifficulty];; 242 maxDownThrust = MaxDownThrustVals[GATES_GAME_TYPE][currentGameDifficulty];;
233 } 243 }
234 else 244 else
235 { 245 {
236 thrustUp = UpThrustVals[FLY_GAME_TYPE][currentGameDifficulty]; 246 thrustUp = UpThrustVals[FLY_GAME_TYPE][currentGameDifficulty];
237 noThrust = DownThrustVals[FLY_GAME_TYPE][currentGameDifficulty]; 247 noThrust = DownThrustVals[FLY_GAME_TYPE][currentGameDifficulty];
238 maxUpThrust = MaxUpThrustVals[FLY_GAME_TYPE][currentGameDifficulty]; 248 maxUpThrust = MaxUpThrustVals[FLY_GAME_TYPE][currentGameDifficulty];
239 maxDownThrust = MaxDownThrustVals[FLY_GAME_TYPE][currentGameDifficulty]; 249 maxDownThrust = MaxDownThrustVals[FLY_GAME_TYPE][currentGameDifficulty];
240 } 250 }
241 251
242 crashLineLength = 0; 252 crashLineLength = 0;
243 lastGateBottomY = 0; 253 lastGateBottomY = 0;
244 254
245 user.setRect( 50, sWidth/2, 4, 4 ); 255 user.setRect( 50, sWidth/2, 4, 4 );
246 256
247 blockWidth = 20; 257 blockWidth = 20;
248 blockHeight = 70; 258 blockHeight = 70;
249 gapHeight = initialGateGaps[currentGameDifficulty]; 259 gapHeight = initialGateGaps[currentGameDifficulty];
250 gateDistance = 75; 260 gateDistance = 75;
251 nextGate = nextInt( 50 ) + gateDistance; 261 nextGate = nextInt( 50 ) + gateDistance;
252 262
253 for ( int i = 0 ; i < TRAILSIZE ; ++i ) 263 for ( int i = 0 ; i < TRAILSIZE ; ++i )
254 { 264 {
255 trail[i].setX( -1 ); 265 trail[i].setX( -1 );
256 trail[i].setY( 0 ); 266 trail[i].setY( 0 );
257 } 267 }
258 268
259 if ( CURRENT_GAME_TYPE != FLY_GAME ) 269 if ( CURRENT_GAME_TYPE != FLY_GAME )
260 { 270 {
261 maxHeight = 50; 271 maxHeight = 50;
262 272
263 mapTop[0] = (int)(nextInt(50)) + 5; 273 mapTop[0] = (int)(nextInt(50)) + 5;
264 mapBottom[0] = (int)(nextInt(50)) + 5; 274 mapBottom[0] = (int)(nextInt(50)) + 5;
265 for ( int i = 1 ; i < MAPSIZE ; ++i ) 275 for ( int i = 1 ; i < MAPSIZE ; ++i )
266 setPoint( i ); 276 setPoint( i );
267 } 277 }
268 else 278 else
269 { 279 {
270 maxHeight = 100; 280 maxHeight = 100;
271 281
272 for ( int i = 0 ; i < MAPSIZE ; ++i ) 282 for ( int i = 0 ; i < MAPSIZE ; ++i )
273 mapBottom[i] = sHeight - 10; 283 mapBottom[i] = sHeight - 10;
274 } 284 }
275 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 285 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
276 blocks[i].setY( -1 ); 286 blocks[i].setY( -1 );
277 287
278} 288}
279 289
280void SFCave :: run() 290void SFCave :: run()
281{ 291{
282 switch ( state ) 292 switch ( state )
283 { 293 {
284 case STATE_MENU: 294 case STATE_MENU:
285 displayMenu(); 295 displayMenu();
286 break; 296 break;
287 case STATE_NEWGAME: 297 case STATE_NEWGAME:
288 setSeed( -1 ); 298 setSeed( -1 );
289 setUp(); 299 setUp();
290 draw(); 300 draw();
291 state = STATE_RUNNING; 301 state = STATE_RUNNING;
292 replay = false; 302 replay = false;
293 replayList.clear(); 303 replayList.clear();
294 break; 304 break;
295 case STATE_REPLAY: 305 case STATE_REPLAY:
296 setSeed( currentSeed ); 306 setSeed( currentSeed );
297 setUp(); 307 setUp();
298 draw(); 308 draw();
299 state = STATE_RUNNING; 309 state = STATE_RUNNING;
300 replay = true; 310 replay = true;
301 if ( replayIt ) 311 if ( replayIt )
302 delete replayIt; 312 delete replayIt;
303 replayIt = new QListIterator<int>( replayList ); 313 replayIt = new QListIterator<int>( replayList );
304 case STATE_BOSS: 314 case STATE_BOSS:
305 drawBoss(); 315 drawBoss();
306 break; 316 break;
307 317
308 case STATE_CRASHING: 318 case STATE_CRASHING:
309 case STATE_CRASHED: 319 case STATE_CRASHED:
310 draw(); 320 draw();
311 break; 321 break;
312 322
313 case STATE_RUNNING: 323 case STATE_RUNNING:
314 { 324 {
315 if ( nrFrames % 2 == 0 ) 325 if ( nrFrames % 2 == 0 )
316 handleKeys(); 326 handleKeys();
317 327
318 // Apply Game rules 328 // Apply Game rules
319 nrFrames ++; 329 nrFrames ++;
320 330
321 if ( replay ) 331 if ( replay )
322 { 332 {
323 while( replayIt->current() && *(replayIt->current()) == nrFrames ) 333 while( replayIt->current() && *(replayIt->current()) == nrFrames )
324 { 334 {
325 press = !press; 335 press = !press;
326 ++(*replayIt); 336 ++(*replayIt);
327 } 337 }
328 } 338 }
329 339
330 if ( CURRENT_GAME_TYPE == SFCAVE_GAME ) 340 if ( CURRENT_GAME_TYPE == SFCAVE_GAME )
331 handleGameSFCave(); 341 handleGameSFCave();
332 else if ( CURRENT_GAME_TYPE == GATES_GAME ) 342 else if ( CURRENT_GAME_TYPE == GATES_GAME )
333 handleGameGates(); 343 handleGameGates();
334 else if ( CURRENT_GAME_TYPE == FLY_GAME ) 344 else if ( CURRENT_GAME_TYPE == FLY_GAME )
335 handleGameFly(); 345 handleGameFly();
336 346
337 draw(); 347 draw();
338 break; 348 break;
339 } 349 }
340 } 350 }
341} 351}
342 352
343void SFCave :: handleGameSFCave() 353void SFCave :: handleGameSFCave()
344{ 354{
345 // Update score 355 // Update score
346 if ( nrFrames % 5 == 0 ) 356 if ( nrFrames % 5 == 0 )
347 score ++; 357 score ++;
348 358
349 if ( nrFrames % 500 == 0 ) 359 if ( nrFrames % 500 == 0 )
350 { 360 {
351 if ( maxHeight < sHeight - 100 ) 361 if ( maxHeight < sHeight - 100 )
352 { 362 {
353 maxHeight += 10; 363 maxHeight += 10;
354 364
355 // Reduce block height 365 // Reduce block height
356 if ( maxHeight > sHeight - 150 ) 366 if ( maxHeight > sHeight - 150 )
357 blockHeight -= 5; 367 blockHeight -= 5;
358 } 368 }
359 } 369 }
360 370
361 if ( nrFrames % 100 == 0 ) 371 if ( nrFrames % 100 == 0 )
362 addBlock(); 372 addBlock();
363 373
364 if ( checkCollision() ) 374 if ( checkCollision() )
365 { 375 {
366 if ( score > highestScore[currentGameType][currentGameDifficulty] ) 376 if ( score > highestScore[currentGameType][currentGameDifficulty] )
367 { 377 {
368 highestScore[currentGameType][currentGameDifficulty] = score; 378 highestScore[currentGameType][currentGameDifficulty] = score;
369 saveScore(); 379 saveScore();
370 } 380 }
371 state = STATE_CRASHING; 381 state = STATE_CRASHING;
372 } 382 }
373 else 383 else
374 { 384 {
375 moveLandscape(); 385 moveLandscape();
376 } 386 }
377 387
378} 388}
379 389
380 390
381void SFCave :: handleGameGates() 391void SFCave :: handleGameGates()
382{ 392{
383 // Update score 393 // Update score
384 if ( nrFrames % 5 == 0 ) 394 if ( nrFrames % 5 == 0 )
385 score ++; 395 score ++;
386 396
387 // Slightly random gap distance 397 // Slightly random gap distance
388 if ( nrFrames >= nextGate ) 398 if ( nrFrames >= nextGate )
389 { 399 {
390 nextGate = nrFrames + nextInt( 50 ) + gateDistance; 400 nextGate = nrFrames + nextInt( 50 ) + gateDistance;
391 addGate(); 401 addGate();
392 } 402 }
393 403
394 if ( nrFrames % 500 == 0 ) 404 if ( nrFrames % 500 == 0 )
395 { 405 {
396 if ( gapHeight > 75 ) 406 if ( gapHeight > 75 )
397 gapHeight -= 5; 407 gapHeight -= 5;
398 } 408 }
399 409
400 if ( checkCollision() ) 410 if ( checkCollision() )
401 { 411 {
402 if ( score > highestScore[currentGameType][currentGameDifficulty] ) 412 if ( score > highestScore[currentGameType][currentGameDifficulty] )
403 { 413 {
404 highestScore[currentGameType][currentGameDifficulty] = score; 414 highestScore[currentGameType][currentGameDifficulty] = score;
405 saveScore(); 415 saveScore();
406 } 416 }
407 state = STATE_CRASHING; 417 state = STATE_CRASHING;
408 } 418 }
409 else 419 else
410 { 420 {
411 moveLandscape(); 421 moveLandscape();
412 } 422 }
413 423
414} 424}
415 425
416void SFCave :: handleGameFly() 426void SFCave :: handleGameFly()
417{ 427{
418 if ( nrFrames % 4 == 0 ) 428 if ( nrFrames % 4 == 0 )
419 { 429 {
420 // Update score 430 // Update score
421 // get distance between landscape and ship 431 // get distance between landscape and ship
422 int diff = mapBottom[10] - user.y(); 432 int diff = mapBottom[10] - user.y();
423 433
424 // the closer the difference is to 0 means more points 434 // the closer the difference is to 0 means more points
425 if ( diff < 10 ) 435 if ( diff < 10 )
426 score += 5; 436 score += 5;
427 else if ( diff < 20 ) 437 else if ( diff < 20 )
428 score += 3; 438 score += 3;
429 else if ( diff < 30 ) 439 else if ( diff < 30 )
430 score += 2; 440 score += 2;
431 else if ( diff < 40 ) 441 else if ( diff < 40 )
432 score += 1; 442 score += 1;
433 } 443 }
434 444
435 if ( checkFlyGameCollision() ) 445 if ( checkFlyGameCollision() )
436 { 446 {
437 if ( score > highestScore[currentGameType][currentGameDifficulty] ) 447 if ( score > highestScore[currentGameType][currentGameDifficulty] )
438 { 448 {
439 highestScore[currentGameType][currentGameDifficulty] = score; 449 highestScore[currentGameType][currentGameDifficulty] = score;
440 saveScore(); 450 saveScore();
441 } 451 }
442 state = STATE_CRASHING; 452 state = STATE_CRASHING;
443 } 453 }
444 else 454 else
445 { 455 {
446 moveFlyGameLandscape(); 456 moveFlyGameLandscape();
447 } 457 }
448} 458}
449 459
450bool SFCave :: checkFlyGameCollision() 460bool SFCave :: checkFlyGameCollision()
451{ 461{
452 if ( (user.y() + user.width()) >= mapBottom[11] ) 462 if ( (user.y() + user.width()) >= mapBottom[11] )
453 return true; 463 return true;
454 464
455 return false; 465 return false;
456} 466}
457 467
458void SFCave :: moveFlyGameLandscape() 468void SFCave :: moveFlyGameLandscape()
459{ 469{
460 offset++; 470 offset++;
461 471
462 if ( offset >= segSize ) 472 if ( offset >= segSize )
463 { 473 {
464 offset = 0; 474 offset = 0;
465 for ( int i = 0 ; i < MAPSIZE-speed ; ++i ) 475 for ( int i = 0 ; i < MAPSIZE-speed ; ++i )
466 mapBottom[i] = mapBottom[i+speed]; 476 mapBottom[i] = mapBottom[i+speed];
467 477
468 for ( int i = speed ; i > 0 ; --i ) 478 for ( int i = speed ; i > 0 ; --i )
469 setFlyPoint( MAPSIZE-i ); 479 setFlyPoint( MAPSIZE-i );
470 } 480 }
471} 481}
472 482
473void SFCave :: setFlyPoint( int point ) 483void SFCave :: setFlyPoint( int point )
474{ 484{
475 static int fly_difficulty_levels[] = { 5, 10, 15 }; 485 static int fly_difficulty_levels[] = { 5, 10, 15 };
476 if ( nextInt(100) >= 75 ) 486 if ( nextInt(100) >= 75 )
477 dir *= -1; 487 dir *= -1;
478 488
479 int prevPoint = mapBottom[point-1]; 489 int prevPoint = mapBottom[point-1];
480 490
481 int nextPoint = prevPoint + (dir * nextInt( fly_difficulty_levels[currentGameDifficulty] ) ); 491 int nextPoint = prevPoint + (dir * nextInt( fly_difficulty_levels[currentGameDifficulty] ) );
482 492
483 if ( nextPoint > sHeight ) 493 if ( nextPoint > sHeight )
484 { 494 {
485 nextPoint = sHeight; 495 nextPoint = sHeight;
486 dir *= -1; 496 dir *= -1;
487 } 497 }
488 else if ( nextPoint < maxHeight ) 498 else if ( nextPoint < maxHeight )
489 { 499 {
490 nextPoint = maxHeight; 500 nextPoint = maxHeight;
491 dir *= 1; 501 dir *= 1;
492 } 502 }
493 503
494 mapBottom[point] = nextPoint; 504 mapBottom[point] = nextPoint;
495} 505}
496 506
497bool SFCave :: checkCollision() 507bool SFCave :: checkCollision()
498{ 508{
499 if ( (user.y() + user.width()) >= mapBottom[11] || user.y() <= mapTop[11] ) 509 if ( (user.y() + user.width()) >= mapBottom[11] || user.y() <= mapTop[11] )
500 return true; 510 return true;
501 511
502 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 512 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
503 { 513 {
504 if ( blocks[i].y() != -1 ) 514 if ( blocks[i].y() != -1 )
505 { 515 {
506 if ( blocks[i].intersects( user ) ) 516 if ( blocks[i].intersects( user ) )
507 return true; 517 return true;
508 } 518 }
509 } 519 }
510 return false; 520 return false;
511} 521}
512 522
513void SFCave :: moveLandscape() 523void SFCave :: moveLandscape()
514{ 524{
515 offset++; 525 offset++;
516 526
517 if ( offset >= segSize ) 527 if ( offset >= segSize )
518 { 528 {
519 offset = 0; 529 offset = 0;
520 for ( int i = 0 ; i < MAPSIZE-speed ; ++i ) 530 for ( int i = 0 ; i < MAPSIZE-speed ; ++i )
521 { 531 {
522 mapTop[i] = mapTop[i+speed]; 532 mapTop[i] = mapTop[i+speed];
523 mapBottom[i] = mapBottom[i+speed]; 533 mapBottom[i] = mapBottom[i+speed];
524 } 534 }
525 535
526 for ( int i = speed ; i > 0 ; --i ) 536 for ( int i = speed ; i > 0 ; --i )
527 setPoint( MAPSIZE-i ); 537 setPoint( MAPSIZE-i );
528 } 538 }
529 539
530 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 540 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
531 { 541 {
532 if ( blocks[i].y() != -1 ) 542 if ( blocks[i].y() != -1 )
533 { 543 {
534 blocks[i].moveBy( -speed, 0 ); 544 blocks[i].moveBy( -speed, 0 );
535 if ( blocks[i].x() + blocks[i].width() < 0 ) 545 if ( blocks[i].x() + blocks[i].width() < 0 )
536 blocks[i].setY( -1 ); 546 blocks[i].setY( -1 );
537 } 547 }
538 } 548 }
539} 549}
540 550
541void SFCave :: addBlock() 551void SFCave :: addBlock()
542{ 552{
543 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 553 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
544 { 554 {
545 if ( blocks[i].y() == -1 ) 555 if ( blocks[i].y() == -1 )
546 { 556 {
547 int x = sWidth; 557 int x = sWidth;
548 558
549 int y = mapTop[50] + (int)(nextInt(mapBottom[50] - mapTop[50] - blockHeight)); 559 int y = mapTop[50] + (int)(nextInt(mapBottom[50] - mapTop[50] - blockHeight));
550 560
551 blocks[i].setRect( x, y, blockWidth, blockHeight ); 561 blocks[i].setRect( x, y, blockWidth, blockHeight );
552 562
553 break; 563 break;
554 } 564 }
555 } 565 }
556} 566}
557 567
558void SFCave :: addGate() 568void SFCave :: addGate()
559{ 569{
560 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 570 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
561 { 571 {
562 if ( blocks[i].y() == -1 ) 572 if ( blocks[i].y() == -1 )
563 { 573 {
564 int x1 = sWidth; 574 int x1 = sWidth;
565 int y1 = mapTop[50]; 575 int y1 = mapTop[50];
566 int b1Height = nextInt(mapBottom[50] - mapTop[50] - gapHeight); 576 int b1Height = nextInt(mapBottom[50] - mapTop[50] - gapHeight);
567 577
568 // See if height between last gate and this one is too big 578 // See if height between last gate and this one is too big
569 if ( b1Height - 100 > lastGateBottomY ) 579 if ( b1Height - 100 > lastGateBottomY )
570 b1Height -= 25; 580 b1Height -= 25;
571 else if ( b1Height + 100 < lastGateBottomY ) 581 else if ( b1Height + 100 < lastGateBottomY )
572 b1Height += 25; 582 b1Height += 25;
573 lastGateBottomY = b1Height; 583 lastGateBottomY = b1Height;
574 584
575 585
576 int x2 = sWidth; 586 int x2 = sWidth;
577 int y2 = y1 + b1Height + gapHeight; 587 int y2 = y1 + b1Height + gapHeight;
578 int b2Height = mapBottom[50] - y2; 588 int b2Height = mapBottom[50] - y2;
579 589
580 590
581 blocks[i].setRect( x1, y1, blockWidth, b1Height ); 591 blocks[i].setRect( x1, y1, blockWidth, b1Height );
582 blocks[i+1].setRect( x2, y2, blockWidth, b2Height ); 592 blocks[i+1].setRect( x2, y2, blockWidth, b2Height );
583 593
584 break; 594 break;
585 } 595 }
586 } 596 }
587} 597}
588 598
589void SFCave :: setPoint( int point ) 599void SFCave :: setPoint( int point )
590{ 600{
591 if ( nextInt(100) >= 80 ) 601 if ( nextInt(100) >= 80 )
592 dir *= -1; 602 dir *= -1;
593 603
594 mapTop[point] = mapTop[point-1] + (dir * nextInt( 5 ) ); 604 mapTop[point] = mapTop[point-1] + (dir * nextInt( 5 ) );
595 if ( mapTop[point] < 0 ) 605 if ( mapTop[point] < 0 )
596 { 606 {
597 mapTop[point] = 0; 607 mapTop[point] = 0;
598 dir *= -1; 608 dir *= -1;
599 } 609 }
600 else if ( mapTop[point] >= maxHeight ) 610 else if ( mapTop[point] >= maxHeight )
601 { 611 {
602 mapTop[point] = maxHeight; 612 mapTop[point] = maxHeight;
603 dir *= -1; 613 dir *= -1;
604 } 614 }
605 615
606// mapBottom[point] = sHeight - (maxHeight - mapBottom[point]); 616// mapBottom[point] = sHeight - (maxHeight - mapBottom[point]);
607 mapBottom[point] = sHeight - (maxHeight - mapTop[point]); 617 mapBottom[point] = sHeight - (maxHeight - mapTop[point]);
608} 618}
609 619
610void SFCave :: drawBoss() 620void SFCave :: drawBoss()
611{ 621{
612 offscreen->fill( Qt::black ); 622 offscreen->fill( Qt::black );
613 623
614 bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true ); 624 bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true );
615} 625}
616 626
617void SFCave :: draw() 627void SFCave :: draw()
618{ 628{
619 //printf( "Paint\n" ); 629 //printf( "Paint\n" );
620 offscreen->fill( Qt::black ); 630 offscreen->fill( Qt::black );
621 631
622 QPainter p( offscreen ); 632 QPainter p( offscreen );
623 QFontMetrics fm = p.fontMetrics(); 633 QFontMetrics fm = p.fontMetrics();
624 p.setPen( Qt::white ); 634 p.setPen( Qt::white );
625 635
626 for ( int i = 0 ; i < MAPSIZE -3; ++i ) 636 for ( int i = 0 ; i < MAPSIZE -3; ++i )
627 { 637 {
628 // Only display top landscape if not running FLY_GAME 638 // Only display top landscape if not running FLY_GAME
629 if ( CURRENT_GAME_TYPE != FLY_GAME ) 639 if ( CURRENT_GAME_TYPE != FLY_GAME )
630 p.drawLine( (i*segSize) - (offset*speed), mapTop[i], ((i+1)*segSize)-(offset*speed), mapTop[i+1] ); 640 p.drawLine( (i*segSize) - (offset*speed), mapTop[i], ((i+1)*segSize)-(offset*speed), mapTop[i+1] );
631 641
632 p.drawLine( (i*segSize) - (offset*speed), mapBottom[i], ((i+1)*segSize)-(offset*speed), mapBottom[i+1] ); 642 p.drawLine( (i*segSize) - (offset*speed), mapBottom[i], ((i+1)*segSize)-(offset*speed), mapBottom[i+1] );
633 643
634 if ( CURRENT_GAME_TYPE == FLY_GAME && showScoreZones ) 644 if ( CURRENT_GAME_TYPE == FLY_GAME && showScoreZones )
635 { 645 {
636 p.setPen( Qt::red ); 646 p.setPen( Qt::red );
637 p.drawLine( (i*segSize) - (offset*speed), mapBottom[i]-10, ((i+1)*segSize)-(offset*speed), mapBottom[i+1]-10 ); 647 p.drawLine( (i*segSize) - (offset*speed), mapBottom[i]-10, ((i+1)*segSize)-(offset*speed), mapBottom[i+1]-10 );
638 p.drawLine( (i*segSize) - (offset*speed), mapBottom[i]-20, ((i+1)*segSize)-(offset*speed), mapBottom[i+1]-20 ); 648 p.drawLine( (i*segSize) - (offset*speed), mapBottom[i]-20, ((i+1)*segSize)-(offset*speed), mapBottom[i+1]-20 );
639 p.drawLine( (i*segSize) - (offset*speed), mapBottom[i]-30, ((i+1)*segSize)-(offset*speed), mapBottom[i+1]-30 ); 649 p.drawLine( (i*segSize) - (offset*speed), mapBottom[i]-30, ((i+1)*segSize)-(offset*speed), mapBottom[i+1]-30 );
640 p.drawLine( (i*segSize) - (offset*speed), mapBottom[i]-40, ((i+1)*segSize)-(offset*speed), mapBottom[i+1]-40 ); 650 p.drawLine( (i*segSize) - (offset*speed), mapBottom[i]-40, ((i+1)*segSize)-(offset*speed), mapBottom[i+1]-40 );
641 p.setPen( Qt::white ); 651 p.setPen( Qt::white );
642 } 652 }
643 } 653 }
644 654
645 // Uncomment this to show user segment (usful for checking collision boundary with landscape 655 // Uncomment this to show user segment (usful for checking collision boundary with landscape
646// p.setPen( Qt::red ); 656// p.setPen( Qt::red );
647// p.drawLine( (11*segSize) - (offset*speed), 0, ((11)*segSize)-(offset*speed), sHeight ); 657// p.drawLine( (11*segSize) - (offset*speed), 0, ((11)*segSize)-(offset*speed), sHeight );
648// p.setPen( Qt::white ); 658// p.setPen( Qt::white );
649 659
650 // Draw user 660 // Draw user
651 p.drawRect( user ); 661 p.drawRect( user );
652 662
653 // Draw trails 663 // Draw trails
654 for ( int i = 0 ; i < TRAILSIZE ; ++i ) 664 for ( int i = 0 ; i < TRAILSIZE ; ++i )
655 if ( trail[i].x() >= 0 ) 665 if ( trail[i].x() >= 0 )
656 p.drawRect( trail[i].x(), trail[i].y(), 2, 2 ); 666 p.drawRect( trail[i].x(), trail[i].y(), 2, 2 );
657 667
658 // Draw blocks 668 // Draw blocks
659 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 669 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
660 if ( blocks[i].y() != -1 ) 670 if ( blocks[i].y() != -1 )
661 { 671 {
662 p.fillRect( blocks[i], Qt::black ); 672 p.fillRect( blocks[i], Qt::black );
663 p.drawRect( blocks[i] ); 673 p.drawRect( blocks[i] );
664 } 674 }
665 675
666 // draw score 676 // draw score
667 QString s; 677 QString s;
668 s.sprintf( "score %06d high score %06d", score, highestScore[currentGameType][currentGameDifficulty] ); 678 s.sprintf( "score %06d high score %06d", score, highestScore[currentGameType][currentGameDifficulty] );
669 p.drawText( 5, 10, s ); 679 p.drawText( 5, 10, s );
670 680
671 681
672 if ( state == STATE_CRASHING || state == STATE_CRASHED ) 682 if ( state == STATE_CRASHING || state == STATE_CRASHED )
673 { 683 {
674 // add next crash line 684 // add next crash line
675 685
676 if ( crashLineLength != -1 ) 686 if ( crashLineLength != -1 )
677 { 687 {
678 for ( int i = 0 ; i < 36 ; ++i ) 688 for ( int i = 0 ; i < 36 ; ++i )
679 { 689 {
680 int x = (int)(user.x() + (crashLineLength+nextInt(10)) * cos( (M_PI/180) * (10.0 * i) ) ); 690 int x = (int)(user.x() + (crashLineLength+nextInt(10)) * cos( (M_PI/180) * (10.0 * i) ) );
681 int y = (int)(user.y() + (crashLineLength+nextInt(10)) * sin( (M_PI/180) * (10.0 * i) ) ); p.drawLine( user.x(), user.y(), x, y ); 691 int y = (int)(user.y() + (crashLineLength+nextInt(10)) * sin( (M_PI/180) * (10.0 * i) ) ); p.drawLine( user.x(), user.y(), x, y );
682 } 692 }
683 } 693 }
684 694
685 if ( state == STATE_CRASHING && crashLineLength >= 15 ) //|| crashLineLength == -1) ) 695 if ( state == STATE_CRASHING && crashLineLength >= 15 ) //|| crashLineLength == -1) )
686 state = STATE_CRASHED; 696 state = STATE_CRASHED;
687 697
688 if ( state == STATE_CRASHED ) 698 if ( state == STATE_CRASHED )
689 { 699 {
690 QString text = "Press up or down to start"; 700 QString text = "Press up or down to start";
691 p.drawText( (sWidth/2) - (fm.width( text )/2), 120, text ); 701 p.drawText( (sWidth/2) - (fm.width( text )/2), 120, text );
692 702
693 text = "Press OK for menu"; 703 text = "Press OK for menu";
694 p.drawText( (sWidth/2) - (fm.width( text )/2), 135, text ); 704 p.drawText( (sWidth/2) - (fm.width( text )/2), 135, text );
695 705/*
696 text = "Press r to replay"; 706 text = "Press r to replay";
697 p.drawText( (sWidth/2) - (fm.width( text )/2), 150, text ); 707 p.drawText( (sWidth/2) - (fm.width( text )/2), 150, text );
698 708
699 text = "Press s to save the replay"; 709 text = "Press s to save the replay";
700 p.drawText( (sWidth/2) - (fm.width( text )/2), 165, text ); 710 p.drawText( (sWidth/2) - (fm.width( text )/2), 165, text );
701 711
702 text = "Press r to load a saved replay"; 712 text = "Press r to load a saved replay";
703 p.drawText( (sWidth/2) - (fm.width( text )/2), 180, text ); 713 p.drawText( (sWidth/2) - (fm.width( text )/2), 180, text );
714*/
704 } 715 }
705 else 716 else
706 crashLineLength ++; 717 crashLineLength ++;
707 } 718 }
708 719
709 p.end(); 720 p.end();
710 bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true ); 721 bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true );
711 //printf( "endpaint\n" ); 722 //printf( "endpaint\n" );
712} 723}
713 724
714void SFCave :: handleKeys() 725void SFCave :: handleKeys()
715{ 726{
716 // Find enpty trail and move others 727 // Find enpty trail and move others
717 bool done = false; 728 bool done = false;
718 for ( int i = 0 ; i < TRAILSIZE ; ++i ) 729 for ( int i = 0 ; i < TRAILSIZE ; ++i )
719 { 730 {
720 if ( trail[i].x() < 0 ) 731 if ( trail[i].x() < 0 )
721 { 732 {
722 if ( !done ) 733 if ( !done )
723 { 734 {
724 trail[i].setX( user.x() - 5 ); 735 trail[i].setX( user.x() - 5 );
725 trail[i].setY( user.y() ); 736 trail[i].setY( user.y() );
726 done = true; 737 done = true;
727 } 738 }
728 } 739 }
729 else 740 else
730 { 741 {
731 trail[i].setX( trail[i].x() - (2) ); 742 trail[i].setX( trail[i].x() - (2) );
732 } 743 }
733 } 744 }
734 745
735 if ( speed <= 3 ) 746 if ( speed <= 3 )
736 { 747 {
737 if ( press ) 748 if ( press )
738 thrust -= thrustUp; 749 thrust -= thrustUp;
739 else 750 else
740 thrust += noThrust; 751 thrust += noThrust;
741 752
742 if ( thrust > maxDownThrust ) 753 if ( thrust > maxDownThrust )
743 thrust = maxDownThrust; 754 thrust = maxDownThrust;
744 else if ( thrust < maxUpThrust ) 755 else if ( thrust < maxUpThrust )
745 thrust = maxUpThrust; 756 thrust = maxUpThrust;
746 } 757 }
747 else 758 else
748 { 759 {
749 if ( press ) 760 if ( press )
750 thrust -= 0.5; 761 thrust -= 0.5;
751 else 762 else
752 thrust += 0.8; 763 thrust += 0.8;
753 764
754 if ( thrust > 5.0 ) 765 if ( thrust > 5.0 )
755 thrust = 5.0; 766 thrust = 5.0;
756 else if ( thrust < -3.5 ) 767 else if ( thrust < -3.5 )
757 thrust = -3.5; 768 thrust = -3.5;
758 } 769 }
759 user.moveBy( 0, (int)thrust ); 770 user.moveBy( 0, (int)thrust );
760} 771}
761 772
762void SFCave :: keyPressEvent( QKeyEvent *e ) 773void SFCave :: keyPressEvent( QKeyEvent *e )
763{ 774{
764 if ( state == STATE_MENU ) 775 if ( state == STATE_MENU )
765 { 776 handleMenuKeys( e );
766 switch( e->key() )
767 {
768 case Qt::Key_Down:
769 currentMenuOption[currentMenuNr] ++;
770 if ( menuOptions[currentMenuNr][currentMenuOption[currentMenuNr]] == "" )
771 currentMenuOption[currentMenuNr] = 0;
772 break;
773 case Qt::Key_Up:
774 currentMenuOption[currentMenuNr] --;
775 if ( currentMenuOption[currentMenuNr] < 0 )
776 currentMenuOption[currentMenuNr] = nrMenuOptions[currentMenuNr]-1;
777 break;
778
779 case Qt::Key_Left:
780 if ( currentMenuNr == MENU_OPTIONS_MENU )
781 {
782 if ( currentMenuOption[currentMenuNr] == MENU_GAME_TYPE )
783 {
784 currentGameType --;
785 if ( currentGameType < 0 )
786 currentGameType = NR_GAME_TYPES - 1;
787 }
788 else if ( currentMenuOption[currentMenuNr] == MENU_GAME_DIFFICULTY )
789 {
790 currentGameDifficulty --;
791 if ( currentGameDifficulty < 0 )
792 currentGameDifficulty = NR_GAME_DIFFICULTIES - 1;
793 }
794 }
795 break;
796
797 case Qt::Key_Right:
798 if ( currentMenuNr == MENU_OPTIONS_MENU )
799 {
800 if ( currentMenuOption[currentMenuNr] == MENU_GAME_TYPE )
801 {
802 currentGameType ++;
803 if ( currentGameType == NR_GAME_TYPES )
804 currentGameType = 0;
805 }
806 else if ( currentMenuOption[currentMenuNr] == MENU_GAME_DIFFICULTY )
807 {
808 currentGameDifficulty ++;
809 if ( currentGameDifficulty == NR_GAME_DIFFICULTIES )
810 currentGameDifficulty = 0;
811 }
812 }
813 break;
814
815 case Qt::Key_Space:
816 case Qt::Key_Return:
817 case Qt::Key_Enter:
818 dealWithMenuSelection();
819 break;
820 }
821 }
822 else 777 else
823 { 778 {
824 switch( e->key() ) 779 switch( e->key() )
825 { 780 {
826 case Qt::Key_Up: 781 case Qt::Key_Up:
827 case Qt::Key_F9: 782 case Qt::Key_F9:
828 case Qt::Key_Space: 783 case Qt::Key_Space:
829 if ( !replay && !press ) 784 if ( !replay && !press )
830 { 785 {
831 press = true; 786 press = true;
832 replayList.append( new int( nrFrames ) ); 787 replayList.append( new int( nrFrames ) );
833 } 788 }
834 break; 789 break;
835 case Qt::Key_M: 790 case Qt::Key_M:
836 case Qt::Key_Return: 791 case Qt::Key_Return:
837 case Qt::Key_Enter: 792 case Qt::Key_Enter:
838 if ( state == STATE_CRASHED ) 793 if ( state == STATE_CRASHED )
794 {
839 state = STATE_MENU; 795 state = STATE_MENU;
796 currentMenuNr = 0;
797 currentMenuOption[currentMenuNr] = 0;
798 }
840 break; 799 break;
841 800
842 case Qt::Key_Z: 801 case Qt::Key_Z:
843 showScoreZones = !showScoreZones; 802 showScoreZones = !showScoreZones;
844 break; 803 break;
845 804
846 default: 805 default:
847 e->ignore(); 806 e->ignore();
848 break; 807 break;
849 } 808 }
850 } 809 }
851} 810}
852 811
853void SFCave :: keyReleaseEvent( QKeyEvent *e ) 812void SFCave :: keyReleaseEvent( QKeyEvent *e )
854{ 813{
855 if ( state == STATE_MENU ) 814 if ( state == STATE_MENU )
856 { 815 {
857 } 816 }
858 else 817 else
859 { 818 {
860 switch( e->key() ) 819 switch( e->key() )
861 { 820 {
862 case Qt::Key_F9: 821 case Qt::Key_F9:
863 case Qt::Key_Space: 822 case Qt::Key_Space:
864 case Qt::Key_Up: 823 case Qt::Key_Up:
865 if ( !replay && press ) 824 if ( !replay && press )
866 { 825 {
867 press = false; 826 press = false;
868 827
869 replayList.append( new int( nrFrames ) ); 828 replayList.append( new int( nrFrames ) );
870 } 829 }
871 break; 830 break;
872 831
873 case Qt::Key_R: 832 case Qt::Key_R:
874 if ( state == STATE_CRASHED ) 833 if ( state == STATE_CRASHED )
875 { 834 {
876 state = STATE_REPLAY; 835 state = STATE_REPLAY;
877 } 836 }
878 break; 837 break;
879 838
880 case Qt::Key_Down: 839 case Qt::Key_Down:
881 if ( state == STATE_CRASHED ) 840 if ( state == STATE_CRASHED )
882 state = STATE_NEWGAME; 841 state = STATE_NEWGAME;
883 break; 842 break;
884 843
885 case Qt::Key_S: 844 case Qt::Key_S:
886 if ( state == STATE_CRASHED ) 845 if ( state == STATE_CRASHED )
887 saveReplay(); 846 saveReplay();
888 break; 847 break;
889 848
890 case Qt::Key_L: 849 case Qt::Key_L:
891 if ( state == STATE_CRASHED ) 850 if ( state == STATE_CRASHED )
892 loadReplay(); 851 loadReplay();
893 break; 852 break;
894 default: 853 default:
895 e->ignore(); 854 e->ignore();
896 break; 855 break;
897 } 856 }
898 } 857 }
899 858
900} 859}
901 860
861
862void SFCave :: saveScore()
863{
864#ifdef QWS
865 Config cfg( "sfcave" );
866 cfg.setGroup( "settings" );
867 QString key = "highScore_";
868
869 cfg.writeEntry( key + gameTypes[currentGameType] + "_" + dificultyOption[currentGameDifficulty], highestScore[currentGameType][currentGameDifficulty] );
870 key += CURRENT_GAME_TYPE;
871 cfg.writeEntry( key, highestScore[currentGameType] );
872#endif
873}
874
875void SFCave :: saveReplay()
876{
877 FILE *out;
878 out = fopen( (const char *)replayFile, "w" );
879 if ( !out )
880 {
881 printf( "Couldn't write to /home/root/sfcave.replay\n" );
882 return;
883 }
884
885 // Build up string of values
886 // Format is:: <landscape seed> <game type> <difficulty> <framenr> <framenr>.......
887 QString val;
888 val.sprintf( "%d %d %d ", currentSeed, currentGameType, currentGameDifficulty );
889
890 QListIterator<int> it( replayList );
891 while( it.current() )
892 {
893 QString tmp;
894 tmp.sprintf( "%d ", (*it.current()) );
895 val += tmp;
896
897 ++it;
898 }
899 val += "\n";
900
901 QString line;
902 line.sprintf( "%d\n", val.length() );
903 fwrite( (const char *)line, 1, line.length(), out );
904
905 fwrite( (const char *)val, 1, val.length(), out );
906
907 fclose( out );
908
909 printf( "Replay saved to %s\n", (const char *)replayFile );
910
911}
912
913void SFCave :: loadReplay()
914{
915 FILE *in = fopen( (const char *)replayFile, "r" );
916
917 if ( in == 0 )
918 {
919 printf( "Couldn't load replay file!\n" );
920 return;
921 }
922
923 // Read next line - contains the size of the options
924 char line[10+1];
925 fgets( line, 10, in );
926
927 int length = -1;
928 sscanf( line, "%d", &length );
929 char *data = new char[length+1];
930
931 fread( data, 1, length, in );
932// printf( "data - %s", data );
933
934 QString sep = " ";
935 QStringList list = QStringList::split( sep, QString( data ) );
936
937 // print it out
938 QStringList::Iterator it = list.begin();
939 currentSeed = (*it).toInt();
940 ++it;
941 currentGameType = (*it).toInt();
942 ++it;
943 currentGameDifficulty = (*it).toInt();
944 ++it;
945
946 replayList.clear();
947 for ( ; it != list.end(); ++it )
948 {
949 int v = (*it).toInt();
950 replayList.append( new int( v ) );
951 }
952
953 delete data;
954
955 fclose( in );
956
957 printf( "Replay loaded from %s\n", (const char *)replayFile );
958}
959
960
961//--------------- MENU CODE ---------------------
962void SFCave :: handleMenuKeys( QKeyEvent *e )
963{
964 switch( e->key() )
965 {
966 case Qt::Key_Down:
967 currentMenuOption[currentMenuNr] ++;
968 if ( menuOptions[currentMenuNr][currentMenuOption[currentMenuNr]] == "" )
969 currentMenuOption[currentMenuNr] = 0;
970 break;
971 case Qt::Key_Up:
972 currentMenuOption[currentMenuNr] --;
973 if ( currentMenuOption[currentMenuNr] < 0 )
974 currentMenuOption[currentMenuNr] = nrMenuOptions[currentMenuNr]-1;
975 break;
976
977 case Qt::Key_Left:
978 if ( currentMenuNr == MENU_OPTIONS_MENU )
979 {
980 if ( currentMenuOption[currentMenuNr] == MENU_GAME_TYPE )
981 {
982 currentGameType --;
983 if ( currentGameType < 0 )
984 currentGameType = NR_GAME_TYPES - 1;
985 }
986 else if ( currentMenuOption[currentMenuNr] == MENU_GAME_DIFFICULTY )
987 {
988 currentGameDifficulty --;
989 if ( currentGameDifficulty < 0 )
990 currentGameDifficulty = NR_GAME_DIFFICULTIES - 1;
991 }
992 }
993 break;
994
995 case Qt::Key_Right:
996 if ( currentMenuNr == MENU_OPTIONS_MENU )
997 {
998 if ( currentMenuOption[currentMenuNr] == MENU_GAME_TYPE )
999 {
1000 currentGameType ++;
1001 if ( currentGameType == NR_GAME_TYPES )
1002 currentGameType = 0;
1003 }
1004 else if ( currentMenuOption[currentMenuNr] == MENU_GAME_DIFFICULTY )
1005 {
1006 currentGameDifficulty ++;
1007 if ( currentGameDifficulty == NR_GAME_DIFFICULTIES )
1008 currentGameDifficulty = 0;
1009 }
1010 }
1011 break;
1012
1013 case Qt::Key_Space:
1014 case Qt::Key_Return:
1015 case Qt::Key_Enter:
1016 dealWithMenuSelection();
1017 break;
1018 }
1019}
1020
902void SFCave :: displayMenu() 1021void SFCave :: displayMenu()
903{ 1022{
904 offscreen->fill( Qt::black ); 1023 offscreen->fill( Qt::black );
905 1024
906 QPainter p( offscreen ); 1025 QPainter p( offscreen );
907 p.setPen( Qt::white ); 1026 p.setPen( Qt::white );
908 1027
909 QFont f( "Helvetica", 16 ); 1028 QFont f( "Helvetica", 16 );
910 p.setFont( f ); 1029 p.setFont( f );
911 1030
912 QFontMetrics fm = p.fontMetrics(); 1031 QFontMetrics fm = p.fontMetrics();
913 1032
914 QString text = "SFCave"; 1033 QString text = "SFCave";
915 p.drawText( (sWidth/2) - (fm.width( text )/2), 60, text ); 1034 p.drawText( (sWidth/2) - (fm.width( text )/2), 60, text );
916 1035
917 text = "Written by Andy Qua"; 1036 text = "Written by Andy Qua";
918 p.drawText( (sWidth/2) - (fm.width( text )/2), 85, text ); 1037 p.drawText( (sWidth/2) - (fm.width( text )/2), 85, text );
919 1038
920 // Draw options 1039 // Draw options
921 int pos = 170; 1040 int pos = 140;
922 for ( int i = 0 ; menuOptions[currentMenuNr][i] != "" ; ++i, pos += 25 ) 1041 for ( int i = 0 ; menuOptions[currentMenuNr][i] != "" ; ++i, pos += 25 )
923 { 1042 {
924 if ( currentMenuOption[currentMenuNr] == i ) 1043 if ( currentMenuOption[currentMenuNr] == i )
925 p.setPen( Qt::yellow ); 1044 p.setPen( Qt::yellow );
926 else 1045 else
927 p.setPen( Qt::white ); 1046 p.setPen( Qt::white );
928 1047
929 QString text; 1048 QString text;
930 if ( menuOptions[currentMenuNr][i].find( "%s" ) != -1 ) 1049 if ( menuOptions[currentMenuNr][i].find( "%s" ) != -1 )
931 { 1050 {
932 QString val; 1051 QString val;
933 if ( i == MENU_GAME_TYPE ) 1052 if ( i == MENU_GAME_TYPE )
934 val = gameTypes[currentGameType]; 1053 val = gameTypes[currentGameType];
935 else 1054 else
936 val = dificultyOption[currentGameDifficulty]; 1055 val = dificultyOption[currentGameDifficulty];
937 1056
938 text.sprintf( (const char *)menuOptions[currentMenuNr][i], (const char *)val ); 1057 text.sprintf( (const char *)menuOptions[currentMenuNr][i], (const char *)val );
939 } 1058 }
940 else 1059 else
941 text = menuOptions[currentMenuNr][i]; 1060 text = menuOptions[currentMenuNr][i];
942 1061
943 p.drawText( (sWidth/2) - (fm.width( text )/2), pos, text ); 1062 p.drawText( (sWidth/2) - (fm.width( text )/2), pos, text );
944 } 1063 }
945 1064
946 p.end(); 1065 p.end();
947 bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true ); 1066 bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true );
948} 1067}
949 1068
950void SFCave :: dealWithMenuSelection() 1069void SFCave :: dealWithMenuSelection()
951{ 1070{
952 switch( currentMenuNr ) 1071 switch( currentMenuNr )
953 { 1072 {
954 case MENU_MAIN_MENU: 1073 case MENU_MAIN_MENU:
955 { 1074 {
956 switch( currentMenuOption[currentMenuNr] ) 1075 switch( currentMenuOption[currentMenuNr] )
957 { 1076 {
958 case MENU_START_GAME: 1077 case MENU_START_GAME:
959 state = STATE_NEWGAME; 1078 state = STATE_NEWGAME;
960 break; 1079 break;
961 1080
1081 case MENU_REPLAY:
1082 currentMenuNr = MENU_REPLAY_MENU;
1083 currentMenuOption[currentMenuNr] = 0;
1084 break;
1085
962 case MENU_OPTIONS: 1086 case MENU_OPTIONS:
963 currentMenuNr = MENU_OPTIONS_MENU; 1087 currentMenuNr = MENU_OPTIONS_MENU;
964 currentMenuOption[currentMenuNr] = 0; 1088 currentMenuOption[currentMenuNr] = 0;
965 break; 1089 break;
966 1090
967 case MENU_HELP: 1091 case MENU_HELP:
968 { 1092 {
969 // Display Help Menu 1093 // Display Help Menu
970 HelpWindow *dlg = new HelpWindow( this ); 1094 HelpWindow *dlg = new HelpWindow( this );
971 dlg->exec(); 1095 dlg->exec();
972 delete dlg; 1096 delete dlg;
973 break; 1097 break;
974 } 1098 }
975 1099
976 case MENU_QUIT: 1100 case MENU_QUIT:
977 QApplication::exit(); 1101 QApplication::exit();
978 break; 1102 break;
979 } 1103 }
980 1104
981 break; 1105 break;
982 } 1106 }
983 1107
984 case MENU_OPTIONS_MENU: 1108 case MENU_OPTIONS_MENU:
985 { 1109 {
986 switch( currentMenuOption[currentMenuNr] ) 1110 switch( currentMenuOption[currentMenuNr] )
987 { 1111 {
988 case MENU_GAME_TYPE: 1112 case MENU_GAME_TYPE:
989 break; 1113 break;
990 1114
991 case MENU_GAME_DIFFICULTY: 1115 case MENU_GAME_DIFFICULTY:
992 break; 1116 break;
993 1117
994 case MENU_CLEAR_HIGHSCORES: 1118 case MENU_CLEAR_HIGHSCORES:
995 for ( int i = 0 ; i < 3 ; ++i ) 1119 for ( int i = 0 ; i < 3 ; ++i )
996 highestScore[currentGameType][i] = 0; 1120 highestScore[currentGameType][i] = 0;
997 break; 1121 break;
998 1122
999 case MENU_BACK: 1123 case MENU_BACK:
1000 currentMenuNr = MENU_MAIN_MENU; 1124 currentMenuNr = MENU_MAIN_MENU;
1001 1125
1002#ifdef QWS 1126#ifdef QWS
1003 Config cfg( "sfcave" ); 1127 Config cfg( "sfcave" );
1004 cfg.setGroup( "settings" ); 1128 cfg.setGroup( "settings" );
1005 cfg.writeEntry( "difficulty", currentGameDifficulty ); 1129 cfg.writeEntry( "difficulty", currentGameDifficulty );
1006 cfg.writeEntry( "gameType", currentGameType ); 1130 cfg.writeEntry( "gameType", currentGameType );
1007#endif 1131#endif
1008 break; 1132 break;
1009 } 1133 }
1010 1134
1011 break; 1135 break;
1012 } 1136 }
1013 }
1014}
1015 1137
1016void SFCave :: saveScore() 1138 case MENU_REPLAY_MENU:
1017{ 1139 {
1018#ifdef QWS 1140 switch( currentMenuOption[currentMenuNr] )
1019 Config cfg( "sfcave" ); 1141 {
1020 cfg.setGroup( "settings" ); 1142 case MENU_REPLAY_START:
1021 QString key = "highScore_"; 1143 if ( currentSeed != 0 )
1144 state = STATE_REPLAY;
1145 // Display No Replay
1146 break;
1022 1147
1023 cfg.writeEntry( key + gameTypes[currentGameType] + "_" + dificultyOption[currentGameDifficulty], highestScore[currentGameType][currentGameDifficulty] ); 1148 case MENU_REPLAY_LOAD:
1024 key += CURRENT_GAME_TYPE; 1149 loadReplay();
1025 cfg.writeEntry( key, highestScore[currentGameType] ); 1150 break;
1026#endif
1027}
1028 1151
1029void SFCave :: saveReplay() 1152 case MENU_REPLAY_SAVE:
1030{ 1153 saveReplay();
1031 FILE *out; 1154 break;
1032 out = fopen( (const char *)replayFile, "w" );
1033 if ( !out )
1034 {
1035 printf( "Couldn't write to /home/root/sfcave.replay\n" );
1036 return;
1037 }
1038 1155
1039 // Build up string of values 1156 case MENU_REPLAY_BACK:
1040 // Format is:: <landscape seed> <framenr> <framenr>....... 1157 currentMenuNr = MENU_MAIN_MENU;
1041 QString val; 1158 break;
1042 val.sprintf( "%d ", currentSeed );
1043
1044 QListIterator<int> it( replayList );
1045 while( it.current() )
1046 {
1047 QString tmp;
1048 tmp.sprintf( "%d ", (*it.current()) );
1049 val += tmp;
1050 1159
1051 ++it; 1160 }
1161 }
1052 } 1162 }
1053 val += "\n";
1054
1055 QString line;
1056 line.sprintf( "%d\n", val.length() );
1057 fwrite( (const char *)line, 1, line.length(), out );
1058 fwrite( (const char *)val, 1, val.length(), out );
1059
1060 fclose( out );
1061
1062 printf( "Replay saved to %s\n", (const char *)replayFile );
1063
1064} 1163}
1065 1164
1066void SFCave :: loadReplay()
1067{
1068 FILE *in = fopen( (const char *)replayFile, "r" );
1069
1070 if ( in == 0 )
1071 {
1072 printf( "Couldn't load replay file!\n" );
1073 return;
1074 }
1075 // Read size of next line
1076 char line[10+1];
1077 fgets( line, 10, in );
1078
1079 int length = -1;
1080 sscanf( line, "%d", &length );
1081 char *data = new char[length+1];
1082
1083 fread( data, 1, length, in );
1084
1085 QString sep = " ";
1086 QStringList list = QStringList::split( sep, QString( data ) );
1087
1088 // print it out
1089 QStringList::Iterator it = list.begin();
1090 currentSeed = (*it).toInt();
1091 ++it;
1092
1093 replayList.clear();
1094 for ( ; it != list.end(); ++it )
1095 {
1096 int v = (*it).toInt();
1097 replayList.append( new int( v ) );
1098 }
1099
1100 delete data;
1101
1102 fclose( in );
1103
1104 printf( "Replay loaded from %s\n", (const char *)replayFile );
1105} \ No newline at end of file
diff --git a/noncore/games/sfcave/sfcave.h b/noncore/games/sfcave/sfcave.h
index 238a615..65e5ae4 100644
--- a/noncore/games/sfcave/sfcave.h
+++ b/noncore/games/sfcave/sfcave.h
@@ -1,121 +1,123 @@
1#include <qmainwindow.h> 1#include <qmainwindow.h>
2#include <qpainter.h> 2#include <qpainter.h>
3#include <qpixmap.h> 3#include <qpixmap.h>
4#include <qpoint.h> 4#include <qpoint.h>
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 15#define NR_MENUS 3
16#define MAX_MENU_OPTIONS 8
16 17
17class SFCave : public QMainWindow 18class SFCave : public QMainWindow
18{ 19{
19Q_OBJECT 20Q_OBJECT
20 21
21public: 22public:
22 int sWidth; 23 int sWidth;
23 int sHeight; 24 int sHeight;
24 int segSize; 25 int segSize;
25 26
26 int currentSeed; 27 int currentSeed;
27 28
28 QList<int> replayList; 29 QList<int> replayList;
29 QListIterator<int> *replayIt; 30 QListIterator<int> *replayIt;
30 bool replay; 31 bool replay;
31 QString replayFile; 32 QString replayFile;
32 33
33 int blockWidth; 34 int blockWidth;
34 int blockHeight; 35 int blockHeight;
35 int gapHeight; 36 int gapHeight;
36 int state; 37 int state;
37 int prevState; 38 int prevState;
38 int speed; 39 int speed;
39 int crashLineLength; 40 int crashLineLength;
40 41
41 static double UpThrustVals[3][3]; 42 static double UpThrustVals[3][3];
42 static double DownThrustVals[3][3]; 43 static double DownThrustVals[3][3];
43 static double MaxUpThrustVals[3][3]; 44 static double MaxUpThrustVals[3][3];
44 static double MaxDownThrustVals[3][3]; 45 static double MaxDownThrustVals[3][3];
45 static int initialGateGaps[]; 46 static int initialGateGaps[];
46 47
47 double thrustUp; 48 double thrustUp;
48 double noThrust; 49 double noThrust;
49 double maxUpThrust; 50 double maxUpThrust;
50 double maxDownThrust; 51 double maxDownThrust;
51 52
52 int gateDistance; 53 int gateDistance;
53 int nextGate; 54 int nextGate;
54 int lastGateBottomY; 55 int lastGateBottomY;
55 56
56 static QString menuOptions[2][5]; 57 static QString menuOptions[NR_MENUS][MAX_MENU_OPTIONS];
57 int currentMenuNr; 58 int currentMenuNr;
58 static int nrMenuOptions[2]; 59 static int nrMenuOptions[NR_MENUS];
59 static int currentMenuOption[2]; 60 static int currentMenuOption[NR_MENUS];
60 61
61 static QString dificultyOption[3]; 62 static QString dificultyOption[3];
62 static QString gameTypes[3]; 63 static QString gameTypes[3];
63 int currentGameType; 64 int currentGameType;
64 int currentGameDifficulty; 65 int currentGameDifficulty;
65 66
66 QPixmap *offscreen; 67 QPixmap *offscreen;
67 QTimer *gameTimer; 68 QTimer *gameTimer;
68 69
69 int score; 70 int score;
70 int highestScore[3][3]; 71 int highestScore[3][3];
71 72
72 int mapTop[MAPSIZE]; 73 int mapTop[MAPSIZE];
73 int mapBottom[MAPSIZE]; 74 int mapBottom[MAPSIZE];
74 QRect blocks[BLOCKSIZE]; 75 QRect blocks[BLOCKSIZE];
75 QRect user; 76 QRect user;
76 QPoint trail[TRAILSIZE]; 77 QPoint trail[TRAILSIZE];
77 78
78 int offset; 79 int offset;
79 int maxHeight; 80 int maxHeight;
80 int nrFrames; 81 int nrFrames;
81 int dir; 82 int dir;
82 83
83 bool showScoreZones; 84 bool showScoreZones;
84 85
85 bool press; 86 bool press;
86 double thrust; 87 double thrust;
87 bool running; 88 bool running;
88 89
89 SFCave( int speed = 3, QWidget *p = 0, char *name = 0 ); 90 SFCave( int speed = 3, QWidget *p = 0, char *name = 0 );
90 ~SFCave(); 91 ~SFCave();
91 void start(); 92 void start();
92 void setSeed( int seed ); 93 void setSeed( int seed );
93 int nextInt( int range ); 94 int nextInt( int range );
94 void setUp(); 95 void setUp();
95 void handleGameSFCave(); 96 void handleGameSFCave();
96 void handleGameGates(); 97 void handleGameGates();
97 void handleGameFly(); 98 void handleGameFly();
98 bool checkFlyGameCollision(); 99 bool checkFlyGameCollision();
99 void moveFlyGameLandscape(); 100 void moveFlyGameLandscape();
100 void setFlyPoint( int point ); 101 void setFlyPoint( int point );
101 bool checkCollision(); 102 bool checkCollision();
102 void moveLandscape(); 103 void moveLandscape();
103 void addBlock(); 104 void addBlock();
104 void addGate(); 105 void addGate();
105 void setPoint( int point ); 106 void setPoint( int point );
106 void drawBoss(); 107 void drawBoss();
107 void draw(); 108 void draw();
108 void handleKeys(); 109 void handleKeys();
109 110
111 void handleMenuKeys( QKeyEvent * e );
110 void displayMenu(); 112 void displayMenu();
111 void dealWithMenuSelection(); 113 void dealWithMenuSelection();
112 114
113 void keyPressEvent( QKeyEvent *e ); 115 void keyPressEvent( QKeyEvent *e );
114 void keyReleaseEvent( QKeyEvent *e ); 116 void keyReleaseEvent( QKeyEvent *e );
115 void saveScore(); 117 void saveScore();
116 void saveReplay(); 118 void saveReplay();
117 void loadReplay(); 119 void loadReplay();
118 120
119private slots: 121private slots:
120 void run(); 122 void run();
121}; 123};