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