summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/sfcave/sfcave.cpp19
-rw-r--r--noncore/games/sfcave/sfcave.h2
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
@@ -1,894 +1,895 @@
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.13 by AndyQ" 17#define CAPTION "SFCave 1.13 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::flyEasyScores[7][3] = { { 0, 10, 5 }, 107int 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 } };
114int SFCave::flyNormalScores[7][3] = { { 0, 10, 5 }, 114int 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 } };
121int SFCave::flyHardScores[7][3] = { { 0, 20, 5 }, 121int 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
128int SFCave::initialGateGaps[] = { 75, 50, 25 }; 128int SFCave::initialGateGaps[] = { 75, 50, 25 };
129 129
130 130
131#define FLYSCORES( x, y ) (*(flyScores + ((x)*3) + y))
131bool movel; 132bool movel;
132 133
133 134
134int main( int argc, char *argv[] ) 135int 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
160SFCave :: SFCave( int spd, QWidget *w, char *name ) 161SFCave :: 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
179 currentMenuNr = 0; 180 currentMenuNr = 0;
180 currentGameType = 0; 181 currentGameType = 0;
181 currentGameDifficulty = 0; 182 currentGameDifficulty = 0;
182 183
183 setCaption( CAPTION ); 184 setCaption( CAPTION );
184 showScoreZones = false; 185 showScoreZones = false;
185 186
186#ifdef QWS 187#ifdef QWS
187 Config cfg( "sfcave" ); 188 Config cfg( "sfcave" );
188 cfg.setGroup( "settings" ); 189 cfg.setGroup( "settings" );
189 QString key = "highScore_"; 190 QString key = "highScore_";
190 191
191 for ( int i = 0 ; i < 3 ; ++i ) 192 for ( int i = 0 ; i < 3 ; ++i )
192 { 193 {
193 for ( int j = 0 ; j < 3 ; ++j ) 194 for ( int j = 0 ; j < 3 ; ++j )
194 highestScore[i][j] = cfg.readNumEntry( key + gameTypes[i] + "_" + dificultyOption[j], 0 ); 195 highestScore[i][j] = cfg.readNumEntry( key + gameTypes[i] + "_" + dificultyOption[j], 0 );
195 } 196 }
196 197
197 currentGameType = cfg.readNumEntry( "gameType", 0 ); 198 currentGameType = cfg.readNumEntry( "gameType", 0 );
198 currentGameDifficulty = cfg.readNumEntry( "difficulty", 0 ); 199 currentGameDifficulty = cfg.readNumEntry( "difficulty", 0 );
199#endif 200#endif
200 speed = spd; // Change to 2 for PC 201 speed = spd; // Change to 2 for PC
201 press = false; 202 press = false;
202 showEyeCandy = false; 203 showEyeCandy = false;
203 204
204 offscreen = new QPixmap( sWidth, sHeight ); 205 offscreen = new QPixmap( sWidth, sHeight );
205 offscreen->fill( Qt::black ); 206 offscreen->fill( Qt::black );
206 207
207// setUp(); 208// setUp();
208 crashLineLength = -1; 209 crashLineLength = -1;
209 state = STATE_MENU; 210 state = STATE_MENU;
210 prevState = STATE_MENU; 211 prevState = STATE_MENU;
211 212
212 gameTimer = new QTimer( this, "game timer" ); 213 gameTimer = new QTimer( this, "game timer" );
213 connect( gameTimer, SIGNAL( timeout() ), 214 connect( gameTimer, SIGNAL( timeout() ),
214 this, SLOT( run() ) ); 215 this, SLOT( run() ) );
215} 216}
216 217
217SFCave :: ~SFCave() 218SFCave :: ~SFCave()
218{ 219{
219} 220}
220 221
221void SFCave :: start() 222void SFCave :: start()
222{ 223{
223 gameTimer->start( 10 ); 224 gameTimer->start( 10 );
224 225
225} 226}
226 227
227void SFCave :: setSeed( int seed ) 228void SFCave :: setSeed( int seed )
228{ 229{
229 if ( seed == -1 ) 230 if ( seed == -1 )
230 currentSeed = ((unsigned long) time((time_t *) NULL)); 231 currentSeed = ((unsigned long) time((time_t *) NULL));
231 else 232 else
232 currentSeed = seed; 233 currentSeed = seed;
233 PutSeed( currentSeed ); 234 PutSeed( currentSeed );
234} 235}
235 236
236int SFCave :: nextInt( int range ) 237int 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
244void SFCave :: setUp() 245void 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
328void SFCave :: run() 329void 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();
338 draw(); 339 draw();
339 state = STATE_RUNNING; 340 state = STATE_RUNNING;
340 replay = false; 341 replay = false;
341 replayList.clear(); 342 replayList.clear();
342 break; 343 break;
343 case STATE_REPLAY: 344 case STATE_REPLAY:
344 setSeed( currentSeed ); 345 setSeed( currentSeed );
345 setUp(); 346 setUp();
346 draw(); 347 draw();
347 state = STATE_RUNNING; 348 state = STATE_RUNNING;
348 replay = true; 349 replay = true;
349 if ( replayIt ) 350 if ( replayIt )
350 delete replayIt; 351 delete replayIt;
351 replayIt = new QListIterator<int>( replayList ); 352 replayIt = new QListIterator<int>( replayList );
352 break; 353 break;
353 case STATE_BOSS: 354 case STATE_BOSS:
354 drawBoss(); 355 drawBoss();
355 break; 356 break;
356 357
357 case STATE_CRASHING: 358 case STATE_CRASHING:
358 case STATE_CRASHED: 359 case STATE_CRASHED:
359 press = false; 360 press = false;
360 draw(); 361 draw();
361 break; 362 break;
362 363
363 case STATE_RUNNING: 364 case STATE_RUNNING:
364 { 365 {
365 if ( nrFrames % 2 == 0 ) 366 if ( nrFrames % 2 == 0 )
366 handleKeys(); 367 handleKeys();
367 368
368 // Apply Game rules 369 // Apply Game rules
369 nrFrames ++; 370 nrFrames ++;
370 371
371 if ( replay ) 372 if ( replay )
372 { 373 {
373 while( replayIt->current() && *(replayIt->current()) == nrFrames ) 374 while( replayIt->current() && *(replayIt->current()) == nrFrames )
374 { 375 {
375 press = !press; 376 press = !press;
376 ++(*replayIt); 377 ++(*replayIt);
377 } 378 }
378 } 379 }
379 380
380 if ( CURRENT_GAME_TYPE == SFCAVE_GAME ) 381 if ( CURRENT_GAME_TYPE == SFCAVE_GAME )
381 handleGameSFCave(); 382 handleGameSFCave();
382 else if ( CURRENT_GAME_TYPE == GATES_GAME ) 383 else if ( CURRENT_GAME_TYPE == GATES_GAME )
383 handleGameGates(); 384 handleGameGates();
384 else if ( CURRENT_GAME_TYPE == FLY_GAME ) 385 else if ( CURRENT_GAME_TYPE == FLY_GAME )
385 handleGameFly(); 386 handleGameFly();
386 387
387 draw(); 388 draw();
388 break; 389 break;
389 } 390 }
390 } 391 }
391} 392}
392 393
393void SFCave :: handleGameSFCave() 394void SFCave :: handleGameSFCave()
394{ 395{
395 // Update score 396 // Update score
396 if ( nrFrames % 5 == 0 ) 397 if ( nrFrames % 5 == 0 )
397 score ++; 398 score ++;
398 399
399 if ( nrFrames % 500 == 0 ) 400 if ( nrFrames % 500 == 0 )
400 { 401 {
401 if ( maxHeight < sHeight - 100 ) 402 if ( maxHeight < sHeight - 100 )
402 { 403 {
403 maxHeight += 10; 404 maxHeight += 10;
404 405
405 // Reduce block height 406 // Reduce block height
406 if ( maxHeight > sHeight - 150 ) 407 if ( maxHeight > sHeight - 150 )
407 blockHeight -= 5; 408 blockHeight -= 5;
408 } 409 }
409 } 410 }
410 411
411 if ( nrFrames % gateDistance == 0 ) 412 if ( nrFrames % gateDistance == 0 )
412 addBlock(); 413 addBlock();
413 414
414 if ( checkCollision() ) 415 if ( checkCollision() )
415 { 416 {
416 if ( score > highestScore[currentGameType][currentGameDifficulty] ) 417 if ( score > highestScore[currentGameType][currentGameDifficulty] )
417 { 418 {
418 highestScore[currentGameType][currentGameDifficulty] = score; 419 highestScore[currentGameType][currentGameDifficulty] = score;
419 saveScore(); 420 saveScore();
420 } 421 }
421 state = STATE_CRASHING; 422 state = STATE_CRASHING;
422 } 423 }
423 else 424 else
424 { 425 {
425 moveLandscape(); 426 moveLandscape();
426 } 427 }
427 428
428} 429}
429 430
430 431
431void SFCave :: handleGameGates() 432void SFCave :: handleGameGates()
432{ 433{
433 // Update score 434 // Update score
434 if ( nrFrames % 5 == 0 ) 435 if ( nrFrames % 5 == 0 )
435 score ++; 436 score ++;
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
466void SFCave :: handleGameFly() 467void 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
510bool SFCave :: checkFlyGameCollision() 511bool 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
518void SFCave :: moveFlyGameLandscape() 519void 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
533void SFCave :: setFlyPoint( int point ) 534void 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 )
537 dir *= -1; 538 dir *= -1;
538 539
539 int prevPoint = mapBottom[point-1]; 540 int prevPoint = mapBottom[point-1];
540 541
541 int nextPoint = prevPoint + (dir * nextInt( fly_difficulty_levels[currentGameDifficulty] ) ); 542 int nextPoint = prevPoint + (dir * nextInt( fly_difficulty_levels[currentGameDifficulty] ) );
542 543
543 if ( nextPoint > sHeight ) 544 if ( nextPoint > sHeight )
544 { 545 {
545 nextPoint = sHeight; 546 nextPoint = sHeight;
546 dir *= -1; 547 dir *= -1;
547 } 548 }
548 else if ( nextPoint < maxHeight ) 549 else if ( nextPoint < maxHeight )
549 { 550 {
550 nextPoint = maxHeight; 551 nextPoint = maxHeight;
551 dir *= 1; 552 dir *= 1;
552 } 553 }
553 554
554 mapBottom[point] = nextPoint; 555 mapBottom[point] = nextPoint;
555} 556}
556 557
557bool SFCave :: checkCollision() 558bool SFCave :: checkCollision()
558{ 559{
559 if ( (user.y() + user.width()) >= mapBottom[11] || user.y() <= mapTop[11] ) 560 if ( (user.y() + user.width()) >= mapBottom[11] || user.y() <= mapTop[11] )
560 return true; 561 return true;
561 562
562 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 563 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
563 { 564 {
564 if ( blocks[i].y() != -1 ) 565 if ( blocks[i].y() != -1 )
565 { 566 {
566 if ( blocks[i].intersects( user ) ) 567 if ( blocks[i].intersects( user ) )
567 return true; 568 return true;
568 } 569 }
569 } 570 }
570 return false; 571 return false;
571} 572}
572 573
573void SFCave :: moveLandscape() 574void SFCave :: moveLandscape()
574{ 575{
575 offset++; 576 offset++;
576 577
577 if ( offset >= segSize ) 578 if ( offset >= segSize )
578 { 579 {
579 offset = 0; 580 offset = 0;
580 for ( int i = 0 ; i < MAPSIZE-speed ; ++i ) 581 for ( int i = 0 ; i < MAPSIZE-speed ; ++i )
581 { 582 {
582 mapTop[i] = mapTop[i+speed]; 583 mapTop[i] = mapTop[i+speed];
583 mapBottom[i] = mapBottom[i+speed]; 584 mapBottom[i] = mapBottom[i+speed];
584 } 585 }
585 586
586 for ( int i = speed ; i > 0 ; --i ) 587 for ( int i = speed ; i > 0 ; --i )
587 setPoint( MAPSIZE-i ); 588 setPoint( MAPSIZE-i );
588 } 589 }
589 590
590 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 591 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
591 { 592 {
592 if ( blocks[i].y() != -1 ) 593 if ( blocks[i].y() != -1 )
593 { 594 {
594 blocks[i].moveBy( -speed, 0 ); 595 blocks[i].moveBy( -speed, 0 );
595 if ( blocks[i].x() + blocks[i].width() < 0 ) 596 if ( blocks[i].x() + blocks[i].width() < 0 )
596 blocks[i].setY( -1 ); 597 blocks[i].setY( -1 );
597 } 598 }
598 } 599 }
599} 600}
600 601
601void SFCave :: addBlock() 602void SFCave :: addBlock()
602{ 603{
603 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 604 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
604 { 605 {
605 if ( blocks[i].y() == -1 ) 606 if ( blocks[i].y() == -1 )
606 { 607 {
607 int x = sWidth; 608 int x = sWidth;
608 609
609 int y = mapTop[50] + (int)(nextInt(mapBottom[50] - mapTop[50] - blockHeight)); 610 int y = mapTop[50] + (int)(nextInt(mapBottom[50] - mapTop[50] - blockHeight));
610 611
611 blocks[i].setRect( x, y, blockWidth, blockHeight ); 612 blocks[i].setRect( x, y, blockWidth, blockHeight );
612 613
613 break; 614 break;
614 } 615 }
615 } 616 }
616} 617}
617 618
618void SFCave :: addGate() 619void SFCave :: addGate()
619{ 620{
620 for ( int i = 0 ; i < BLOCKSIZE ; ++i ) 621 for ( int i = 0 ; i < BLOCKSIZE ; ++i )
621 { 622 {
622 if ( blocks[i].y() == -1 ) 623 if ( blocks[i].y() == -1 )
623 { 624 {
624 int x1 = sWidth; 625 int x1 = sWidth;
625 int y1 = mapTop[50]; 626 int y1 = mapTop[50];
626 int b1Height = nextInt(mapBottom[50] - mapTop[50] - gapHeight); 627 int b1Height = nextInt(mapBottom[50] - mapTop[50] - gapHeight);
627 628
628 // See if height between last gate and this one is too big 629 // See if height between last gate and this one is too big
629 if ( b1Height - 100 > lastGateBottomY ) 630 if ( b1Height - 100 > lastGateBottomY )
630 b1Height -= 25; 631 b1Height -= 25;
631 else if ( b1Height + 100 < lastGateBottomY ) 632 else if ( b1Height + 100 < lastGateBottomY )
632 b1Height += 25; 633 b1Height += 25;
633 lastGateBottomY = b1Height; 634 lastGateBottomY = b1Height;
634 635
635 636
636 int x2 = sWidth; 637 int x2 = sWidth;
637 int y2 = y1 + b1Height + gapHeight; 638 int y2 = y1 + b1Height + gapHeight;
638 int b2Height = mapBottom[50] - y2; 639 int b2Height = mapBottom[50] - y2;
639 640
640 641
641 blocks[i].setRect( x1, y1, blockWidth, b1Height ); 642 blocks[i].setRect( x1, y1, blockWidth, b1Height );
642 blocks[i+1].setRect( x2, y2, blockWidth, b2Height ); 643 blocks[i+1].setRect( x2, y2, blockWidth, b2Height );
643 644
644 break; 645 break;
645 } 646 }
646 } 647 }
647} 648}
648 649
649void SFCave :: setPoint( int point ) 650void 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
670void SFCave :: drawBoss() 671void 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
677void SFCave :: draw() 678void 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 );
751 } 752 }
752 } 753 }
753 754
754 if ( state == STATE_CRASHING && crashLineLength >= 15 ) //|| crashLineLength == -1) ) 755 if ( state == STATE_CRASHING && crashLineLength >= 15 ) //|| crashLineLength == -1) )
755 state = STATE_CRASHED; 756 state = STATE_CRASHED;
756 757
757 if ( state == STATE_CRASHED ) 758 if ( state == STATE_CRASHED )
758 { 759 {
759 QString text = "Press up or down to start"; 760 QString text = "Press up or down to start";
760 p.drawText( (sWidth/2) - (fm.width( text )/2), 120, text ); 761 p.drawText( (sWidth/2) - (fm.width( text )/2), 120, text );
761 762
762 text = "Press OK for menu"; 763 text = "Press OK for menu";
763 p.drawText( (sWidth/2) - (fm.width( text )/2), 135, text ); 764 p.drawText( (sWidth/2) - (fm.width( text )/2), 135, text );
764/* 765/*
765 text = "Press r to replay"; 766 text = "Press r to replay";
766 p.drawText( (sWidth/2) - (fm.width( text )/2), 150, text ); 767 p.drawText( (sWidth/2) - (fm.width( text )/2), 150, text );
767 768
768 text = "Press s to save the replay"; 769 text = "Press s to save the replay";
769 p.drawText( (sWidth/2) - (fm.width( text )/2), 165, text ); 770 p.drawText( (sWidth/2) - (fm.width( text )/2), 165, text );
770 771
771 text = "Press r to load a saved replay"; 772 text = "Press r to load a saved replay";
772 p.drawText( (sWidth/2) - (fm.width( text )/2), 180, text ); 773 p.drawText( (sWidth/2) - (fm.width( text )/2), 180, text );
773*/ 774*/
774 } 775 }
775 else 776 else
776 crashLineLength ++; 777 crashLineLength ++;
777 } 778 }
778 779
779 p.end(); 780 p.end();
780 bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true ); 781 bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true );
781 //printf( "endpaint\n" ); 782 //printf( "endpaint\n" );
782} 783}
783 784
784void SFCave :: handleKeys() 785void SFCave :: handleKeys()
785{ 786{
786 // Find enpty trail and move others 787 // Find enpty trail and move others
787 bool done = false; 788 bool done = false;
788 for ( int i = 0 ; i < TRAILSIZE ; ++i ) 789 for ( int i = 0 ; i < TRAILSIZE ; ++i )
789 { 790 {
790 if ( trail[i].x() < 0 ) 791 if ( trail[i].x() < 0 )
791 { 792 {
792 if ( !done ) 793 if ( !done )
793 { 794 {
794 trail[i].setX( user.x() - 5 ); 795 trail[i].setX( user.x() - 5 );
795 trail[i].setY( user.y() ); 796 trail[i].setY( user.y() );
796 done = true; 797 done = true;
797 } 798 }
798 } 799 }
799 else 800 else
800 { 801 {
801 trail[i].setX( trail[i].x() - (2) ); 802 trail[i].setX( trail[i].x() - (2) );
802 } 803 }
803 } 804 }
804 805
805 if ( speed <= 3 ) 806 if ( speed <= 3 )
806 { 807 {
807 if ( press ) 808 if ( press )
808 thrust -= thrustUp; 809 thrust -= thrustUp;
809 else 810 else
810 thrust += noThrust; 811 thrust += noThrust;
811 812
812 if ( thrust > maxDownThrust ) 813 if ( thrust > maxDownThrust )
813 thrust = maxDownThrust; 814 thrust = maxDownThrust;
814 else if ( thrust < maxUpThrust ) 815 else if ( thrust < maxUpThrust )
815 thrust = maxUpThrust; 816 thrust = maxUpThrust;
816 } 817 }
817 else 818 else
818 { 819 {
819 if ( press ) 820 if ( press )
820 thrust -= 0.5; 821 thrust -= 0.5;
821 else 822 else
822 thrust += 0.8; 823 thrust += 0.8;
823 824
824 if ( thrust > 5.0 ) 825 if ( thrust > 5.0 )
825 thrust = 5.0; 826 thrust = 5.0;
826 else if ( thrust < -3.5 ) 827 else if ( thrust < -3.5 )
827 thrust = -3.5; 828 thrust = -3.5;
828 } 829 }
829 user.moveBy( 0, (int)thrust ); 830 user.moveBy( 0, (int)thrust );
830} 831}
831 832
832void SFCave :: keyPressEvent( QKeyEvent *e ) 833void SFCave :: keyPressEvent( QKeyEvent *e )
833{ 834{
834 if ( state == STATE_MENU ) 835 if ( state == STATE_MENU )
835 handleMenuKeys( e ); 836 handleMenuKeys( e );
836 else 837 else
837 { 838 {
838 switch( e->key() ) 839 switch( e->key() )
839 { 840 {
840 case Qt::Key_Up: 841 case Qt::Key_Up:
841 case Qt::Key_F9: 842 case Qt::Key_F9:
842 case Qt::Key_Space: 843 case Qt::Key_Space:
843 if ( state == STATE_RUNNING ) 844 if ( state == STATE_RUNNING )
844 { 845 {
845 if ( !replay && !press ) 846 if ( !replay && !press )
846 { 847 {
847 press = true; 848 press = true;
848 replayList.append( new int( nrFrames ) ); 849 replayList.append( new int( nrFrames ) );
849 } 850 }
850 } 851 }
851 else if ( state == STATE_CRASHED ) 852 else if ( state == STATE_CRASHED )
852 { 853 {
853 if ( e->key() == Key_Up ) 854 if ( e->key() == Key_Up )
854 state = STATE_NEWGAME; 855 state = STATE_NEWGAME;
855 } 856 }
856 857
857 break; 858 break;
858 case Qt::Key_M: 859 case Qt::Key_M:
859 case Qt::Key_Return: 860 case Qt::Key_Return:
860 case Qt::Key_Enter: 861 case Qt::Key_Enter:
861 if ( state == STATE_CRASHED ) 862 if ( state == STATE_CRASHED )
862 { 863 {
863 state = STATE_MENU; 864 state = STATE_MENU;
864 currentMenuNr = 0; 865 currentMenuNr = 0;
865 currentMenuOption[currentMenuNr] = 0; 866 currentMenuOption[currentMenuNr] = 0;
866 } 867 }
867 break; 868 break;
868 869
869 case Qt::Key_Z: 870 case Qt::Key_Z:
870 showScoreZones = !showScoreZones; 871 showScoreZones = !showScoreZones;
871 break; 872 break;
872 873
873 default: 874 default:
874 e->ignore(); 875 e->ignore();
875 break; 876 break;
876 } 877 }
877 } 878 }
878} 879}
879 880
880void SFCave :: keyReleaseEvent( QKeyEvent *e ) 881void SFCave :: keyReleaseEvent( QKeyEvent *e )
881{ 882{
882 if ( state == STATE_MENU ) 883 if ( state == STATE_MENU )
883 { 884 {
884 } 885 }
885 else 886 else
886 { 887 {
887 switch( e->key() ) 888 switch( e->key() )
888 { 889 {
889 case Qt::Key_F9: 890 case Qt::Key_F9:
890 case Qt::Key_Space: 891 case Qt::Key_Space:
891 case Qt::Key_Up: 892 case Qt::Key_Up:
892 if ( state == STATE_RUNNING ) 893 if ( state == STATE_RUNNING )
893 { 894 {
894 if ( !replay && press ) 895 if ( !replay && press )
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
@@ -1,131 +1,131 @@
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#define NR_MENUS 3 15#define NR_MENUS 3
16#define MAX_MENU_OPTIONS 8 16#define MAX_MENU_OPTIONS 8
17 17
18class SFCave : public QMainWindow 18class SFCave : public QMainWindow
19{ 19{
20Q_OBJECT 20Q_OBJECT
21 21
22public: 22public:
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 );
102 int nextInt( int range ); 102 int nextInt( int range );
103 void setUp(); 103 void setUp();
104 void handleGameSFCave(); 104 void handleGameSFCave();
105 void handleGameGates(); 105 void handleGameGates();
106 void handleGameFly(); 106 void handleGameFly();
107 bool checkFlyGameCollision(); 107 bool checkFlyGameCollision();
108 void moveFlyGameLandscape(); 108 void moveFlyGameLandscape();
109 void setFlyPoint( int point ); 109 void setFlyPoint( int point );
110 bool checkCollision(); 110 bool checkCollision();
111 void moveLandscape(); 111 void moveLandscape();
112 void addBlock(); 112 void addBlock();
113 void addGate(); 113 void addGate();
114 void setPoint( int point ); 114 void setPoint( int point );
115 void drawBoss(); 115 void drawBoss();
116 void draw(); 116 void draw();
117 void handleKeys(); 117 void handleKeys();
118 118
119 void handleMenuKeys( QKeyEvent * e ); 119 void handleMenuKeys( QKeyEvent * e );
120 void displayMenu(); 120 void displayMenu();
121 void dealWithMenuSelection(); 121 void dealWithMenuSelection();
122 122
123 void keyPressEvent( QKeyEvent *e ); 123 void keyPressEvent( QKeyEvent *e );
124 void keyReleaseEvent( QKeyEvent *e ); 124 void keyReleaseEvent( QKeyEvent *e );
125 void saveScore(); 125 void saveScore();
126 void saveReplay(); 126 void saveReplay();
127 void loadReplay(); 127 void loadReplay();
128 128
129private slots: 129private slots:
130 void run(); 130 void run();
131}; 131};