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