author | andyq <andyq> | 2002-12-11 17:48:18 (UTC) |
---|---|---|
committer | andyq <andyq> | 2002-12-11 17:48:18 (UTC) |
commit | d3d49c3022d763157a3c8309ddc5b9ce4ecde61a (patch) (unidiff) | |
tree | 67a8aa13cb3c41560c09e7cc7ca9f8ed169e05fc | |
parent | 719acab56c57f283168b955582ab5b30b9809b02 (diff) | |
download | opie-d3d49c3022d763157a3c8309ddc5b9ce4ecde61a.zip opie-d3d49c3022d763157a3c8309ddc5b9ce4ecde61a.tar.gz opie-d3d49c3022d763157a3c8309ddc5b9ce4ecde61a.tar.bz2 |
Added save and load replays
-rw-r--r-- | noncore/games/sfcave/sfcave.cpp | 101 |
1 files changed, 97 insertions, 4 deletions
diff --git a/noncore/games/sfcave/sfcave.cpp b/noncore/games/sfcave/sfcave.cpp index b5bc736..93f5f82 100644 --- a/noncore/games/sfcave/sfcave.cpp +++ b/noncore/games/sfcave/sfcave.cpp | |||
@@ -1,234 +1,239 @@ | |||
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 | 13 | ||
13 | #include "helpwindow.h" | 14 | #include "helpwindow.h" |
14 | #include "sfcave.h" | 15 | #include "sfcave.h" |
15 | 16 | ||
16 | #define CAPTION "SFCave 1.8 by AndyQ" | 17 | #define CAPTION "SFCave 1.10 by AndyQ" |
17 | 18 | ||
18 | #define UP_THRUST 0.6 | 19 | #define UP_THRUST 0.6 |
19 | #define NO_THRUST 0.8 | 20 | #define NO_THRUST 0.8 |
20 | #define MAX_DOWN_THRUST 4.0 | 21 | #define MAX_DOWN_THRUST 4.0 |
21 | #define MAX_UP_THRUST -3.5 | 22 | #define MAX_UP_THRUST -3.5 |
22 | 23 | ||
23 | // States | 24 | // States |
24 | #define STATE_BOSS 0 | 25 | #define STATE_BOSS 0 |
25 | #define STATE_RUNNING 1 | 26 | #define STATE_RUNNING 1 |
26 | #define STATE_CRASHING 2 | 27 | #define STATE_CRASHING 2 |
27 | #define STATE_CRASHED 3 | 28 | #define STATE_CRASHED 3 |
28 | #define STATE_NEWGAME 4 | 29 | #define STATE_NEWGAME 4 |
29 | #define STATE_MENU 5 | 30 | #define STATE_MENU 5 |
30 | #define STATE_REPLAY 6 | 31 | #define STATE_REPLAY 6 |
31 | 32 | ||
32 | // Menus | 33 | // Menus |
33 | #define MENU_MAIN_MENU 0 | 34 | #define MENU_MAIN_MENU 0 |
34 | #define MENU_OPTIONS_MENU 1 | 35 | #define MENU_OPTIONS_MENU 1 |
35 | 36 | ||
36 | // Main Menu Options | 37 | // Main Menu Options |
37 | #define MENU_START_GAME 0 | 38 | #define MENU_START_GAME 0 |
38 | #define MENU_OPTIONS 1 | 39 | #define MENU_OPTIONS 1 |
39 | #define MENU_HELP 2 | 40 | #define MENU_HELP 2 |
40 | #define MENU_QUIT 3 | 41 | #define MENU_QUIT 3 |
41 | 42 | ||
42 | // Option Menu Options | 43 | // Option Menu Options |
43 | #define MENU_GAME_TYPE 0 | 44 | #define MENU_GAME_TYPE 0 |
44 | #define MENU_GAME_DIFFICULTY 1 | 45 | #define MENU_GAME_DIFFICULTY 1 |
45 | #define MENU_CLEAR_HIGHSCORES 2 | 46 | #define MENU_CLEAR_HIGHSCORES 2 |
46 | #define MENU_BACK 3 | 47 | #define MENU_BACK 3 |
47 | 48 | ||
48 | 49 | ||
49 | #define NR_GAME_DIFFICULTIES 3 | 50 | #define NR_GAME_DIFFICULTIES 3 |
50 | #define NR_GAME_TYPES 3 | 51 | #define NR_GAME_TYPES 3 |
51 | 52 | ||
52 | #define DIFICULTY_EASY 0 | 53 | #define DIFICULTY_EASY 0 |
53 | #define DIFICULTY_NORMAL 1 | 54 | #define DIFICULTY_NORMAL 1 |
54 | #define DIFICULTY_HARD 2 | 55 | #define DIFICULTY_HARD 2 |
55 | #define EASY "Easy" | 56 | #define EASY "Easy" |
56 | #define NORMAL "Normal" | 57 | #define NORMAL "Normal" |
57 | #define HARD "Hard" | 58 | #define HARD "Hard" |
58 | 59 | ||
59 | #define SFCAVE_GAME_TYPE 0 | 60 | #define SFCAVE_GAME_TYPE 0 |
60 | #define GATES_GAME_TYPE 1 | 61 | #define GATES_GAME_TYPE 1 |
61 | #define FLY_GAME_TYPE 2 | 62 | #define FLY_GAME_TYPE 2 |
62 | #define SFCAVE_GAME "SFCave" | 63 | #define SFCAVE_GAME "SFCave" |
63 | #define GATES_GAME "Gates" | 64 | #define GATES_GAME "Gates" |
64 | #define FLY_GAME "Fly" | 65 | #define FLY_GAME "Fly" |
65 | #define CURRENT_GAME_TYPE gameTypes[currentGameType] | 66 | #define CURRENT_GAME_TYPE gameTypes[currentGameType] |
66 | #define CURRENT_GAME_DIFFICULTY difficultyOption[currentGameDifficulty]; | 67 | #define CURRENT_GAME_DIFFICULTY difficultyOption[currentGameDifficulty]; |
67 | 68 | ||
68 | QString SFCave::dificultyOption[] = { EASY, NORMAL, HARD }; | 69 | QString SFCave::dificultyOption[] = { EASY, NORMAL, HARD }; |
69 | QString SFCave::gameTypes[] = { SFCAVE_GAME, GATES_GAME, FLY_GAME }; | 70 | QString SFCave::gameTypes[] = { SFCAVE_GAME, GATES_GAME, FLY_GAME }; |
70 | 71 | ||
71 | QString SFCave::menuOptions[2][5] = { { "Start Game", "Options", "Help", "Quit", "" }, | 72 | QString SFCave::menuOptions[2][5] = { { "Start Game", "Options", "Help", "Quit", "" }, |
72 | { "Game Type - %s", "Game Difficulty - %s", "Clear High Scores for this game", "Back", "" } }; | 73 | { "Game Type - %s", "Game Difficulty - %s", "Clear High Scores for this game", "Back", "" } }; |
73 | 74 | ||
74 | #define UP_THRUST 0.6 | 75 | #define UP_THRUST 0.6 |
75 | #define NO_THRUST 0.8 | 76 | #define NO_THRUST 0.8 |
76 | #define MAX_DOWN_THRUST 4.0 | 77 | #define MAX_DOWN_THRUST 4.0 |
77 | #define MAX_UP_THRUST -3.5 | 78 | #define MAX_UP_THRUST -3.5 |
78 | double SFCave::UpThrustVals[3][3] = {{ 0.6, 0.6, 0.6 }, // SFCave | 79 | double SFCave::UpThrustVals[3][3] = {{ 0.6, 0.6, 0.6 }, // SFCave |
79 | { 0.6, 0.6, 0.8 }, // Gates | 80 | { 0.6, 0.6, 0.8 }, // Gates |
80 | { 0.4, 0.7, 1.0 } }; // Fly | 81 | { 0.4, 0.7, 1.0 } }; // Fly |
81 | 82 | ||
82 | double SFCave::DownThrustVals[3][3] = {{ 0.8, 0.8, 0.8 }, // SFCave | 83 | double SFCave::DownThrustVals[3][3] = {{ 0.8, 0.8, 0.8 }, // SFCave |
83 | { 0.8, 0.8, 1.0 }, // Gates | 84 | { 0.8, 0.8, 1.0 }, // Gates |
84 | { 0.4, 0.7, 1.0 } }; // Fly | 85 | { 0.4, 0.7, 1.0 } }; // Fly |
85 | 86 | ||
86 | double SFCave::MaxUpThrustVals[3][3] = {{ -3.5, -3.5, -3.5 }, // SFCave | 87 | double SFCave::MaxUpThrustVals[3][3] = {{ -3.5, -3.5, -3.5 }, // SFCave |
87 | { -3.5, -4.0, -5.0 }, // Gates | 88 | { -3.5, -4.0, -5.0 }, // Gates |
88 | { -3.5, -4.0, -5.0 } }; // Fly | 89 | { -3.5, -4.0, -5.0 } }; // Fly |
89 | 90 | ||
90 | double SFCave::MaxDownThrustVals[3][3] = {{ 4.0, 4.0, 4.0 }, // SFCave | 91 | double SFCave::MaxDownThrustVals[3][3] = {{ 4.0, 4.0, 4.0 }, // SFCave |
91 | { 4.0, 5.0, 5.5 }, // Gates | 92 | { 4.0, 5.0, 5.5 }, // Gates |
92 | { 3.5, 4.0, 5.0 } }; // Fly | 93 | { 3.5, 4.0, 5.0 } }; // Fly |
93 | 94 | ||
94 | int SFCave::initialGateGaps[] = { 75, 50, 25 }; | 95 | int SFCave::initialGateGaps[] = { 75, 50, 25 }; |
95 | 96 | ||
96 | int SFCave::nrMenuOptions[2] = { 4, 4 }; | 97 | int SFCave::nrMenuOptions[2] = { 4, 4 }; |
97 | int SFCave ::currentMenuOption[2] = { 0, 0 }; | 98 | int SFCave ::currentMenuOption[2] = { 0, 0 }; |
98 | 99 | ||
99 | bool movel; | 100 | bool movel; |
100 | 101 | ||
101 | 102 | ||
102 | int main( int argc, char *argv[] ) | 103 | int main( int argc, char *argv[] ) |
103 | { | 104 | { |
104 | movel = true; | 105 | movel = true; |
105 | #ifdef QWS | 106 | #ifdef QWS |
106 | QPEApplication a( argc, argv ); | 107 | QPEApplication a( argc, argv ); |
107 | #else | 108 | #else |
108 | QApplication a( argc, argv ); | 109 | QApplication a( argc, argv ); |
109 | #endif | 110 | #endif |
110 | 111 | ||
111 | int speed = 3; | 112 | int speed = 3; |
112 | for ( int i = 0 ; i < argc ; ++i ) | 113 | for ( int i = 0 ; i < argc ; ++i ) |
113 | { | 114 | { |
114 | if ( strcmp( argv[i], "-s" ) == 0 ) | 115 | if ( strcmp( argv[i], "-s" ) == 0 ) |
115 | { | 116 | { |
116 | if ( i+1 < argc ) | 117 | if ( i+1 < argc ) |
117 | speed = atoi( argv[i+1] ); | 118 | speed = atoi( argv[i+1] ); |
118 | } | 119 | } |
119 | } | 120 | } |
120 | 121 | ||
121 | SFCave app( speed ); | 122 | SFCave app( speed ); |
122 | a.setMainWidget( &app ); | 123 | a.setMainWidget( &app ); |
123 | app.show(); | 124 | app.show(); |
124 | app.start(); | 125 | app.start(); |
125 | a.exec(); | 126 | a.exec(); |
126 | } | 127 | } |
127 | 128 | ||
128 | SFCave :: SFCave( int spd, QWidget *w, char *name ) | 129 | SFCave :: SFCave( int spd, QWidget *w, char *name ) |
129 | : QMainWindow( w, name ) | 130 | : QMainWindow( w, name ) |
130 | 131 | ||
131 | { | 132 | { |
132 | replayIt = 0; | 133 | replayIt = 0; |
133 | #ifdef QWS | 134 | #ifdef QWS |
134 | showMaximized(); | 135 | showMaximized(); |
135 | #else | 136 | #else |
136 | resize( 240, 284 ); | 137 | resize( 240, 284 ); |
137 | #endif | 138 | #endif |
138 | 139 | ||
140 | replayFile = QDir::home().path(); | ||
141 | replayFile += "/sfcave.replay"; | ||
142 | printf( "%s\n", (const char *)replayFile ); | ||
143 | |||
139 | sWidth = width(); | 144 | sWidth = width(); |
140 | sHeight = height(); | 145 | sHeight = height(); |
141 | segSize = sWidth/(MAPSIZE-1)+1; | 146 | segSize = sWidth/(MAPSIZE-1)+1; |
142 | 147 | ||
143 | currentMenuNr = 0; | 148 | currentMenuNr = 0; |
144 | currentGameType = 0; | 149 | currentGameType = 0; |
145 | currentGameDifficulty = 0; | 150 | currentGameDifficulty = 0; |
146 | 151 | ||
147 | setCaption( CAPTION ); | 152 | setCaption( CAPTION ); |
148 | showScoreZones = false; | 153 | showScoreZones = false; |
149 | 154 | ||
150 | #ifdef QWS | 155 | #ifdef QWS |
151 | Config cfg( "sfcave" ); | 156 | Config cfg( "sfcave" ); |
152 | cfg.setGroup( "settings" ); | 157 | cfg.setGroup( "settings" ); |
153 | QString key = "highScore_"; | 158 | QString key = "highScore_"; |
154 | 159 | ||
155 | for ( int i = 0 ; i < 3 ; ++i ) | 160 | for ( int i = 0 ; i < 3 ; ++i ) |
156 | { | 161 | { |
157 | for ( int j = 0 ; j < 3 ; ++j ) | 162 | for ( int j = 0 ; j < 3 ; ++j ) |
158 | highestScore[i][j] = cfg.readNumEntry( key + gameTypes[i] + "_" + dificultyOption[j], 0 ); | 163 | highestScore[i][j] = cfg.readNumEntry( key + gameTypes[i] + "_" + dificultyOption[j], 0 ); |
159 | } | 164 | } |
160 | 165 | ||
161 | currentGameType = cfg.readNumEntry( "gameType", 0 ); | 166 | currentGameType = cfg.readNumEntry( "gameType", 0 ); |
162 | currentGameDifficulty = cfg.readNumEntry( "difficulty", 0 ); | 167 | currentGameDifficulty = cfg.readNumEntry( "difficulty", 0 ); |
163 | #endif | 168 | #endif |
164 | speed = spd; // Change to 2 for PC | 169 | speed = spd; // Change to 2 for PC |
165 | press = false; | 170 | press = false; |
166 | 171 | ||
167 | offscreen = new QPixmap( sWidth, sHeight ); | 172 | offscreen = new QPixmap( sWidth, sHeight ); |
168 | offscreen->fill( Qt::black ); | 173 | offscreen->fill( Qt::black ); |
169 | 174 | ||
170 | // setUp(); | 175 | // setUp(); |
171 | crashLineLength = -1; | 176 | crashLineLength = -1; |
172 | state = STATE_MENU; | 177 | state = STATE_MENU; |
173 | prevState = STATE_MENU; | 178 | prevState = STATE_MENU; |
174 | 179 | ||
175 | gameTimer = new QTimer( this, "game timer" ); | 180 | gameTimer = new QTimer( this, "game timer" ); |
176 | connect( gameTimer, SIGNAL( timeout() ), | 181 | connect( gameTimer, SIGNAL( timeout() ), |
177 | this, SLOT( run() ) ); | 182 | this, SLOT( run() ) ); |
178 | } | 183 | } |
179 | 184 | ||
180 | SFCave :: ~SFCave() | 185 | SFCave :: ~SFCave() |
181 | { | 186 | { |
182 | } | 187 | } |
183 | 188 | ||
184 | void SFCave :: start() | 189 | void SFCave :: start() |
185 | { | 190 | { |
186 | gameTimer->start( 10 ); | 191 | gameTimer->start( 10 ); |
187 | 192 | ||
188 | } | 193 | } |
189 | 194 | ||
190 | void SFCave :: setSeed( int seed ) | 195 | void SFCave :: setSeed( int seed ) |
191 | { | 196 | { |
192 | if ( seed == -1 ) | 197 | if ( seed == -1 ) |
193 | currentSeed = ((unsigned long) time((time_t *) NULL)); | 198 | currentSeed = ((unsigned long) time((time_t *) NULL)); |
194 | else | 199 | else |
195 | currentSeed = seed; | 200 | currentSeed = seed; |
196 | PutSeed( currentSeed ); | 201 | PutSeed( currentSeed ); |
197 | } | 202 | } |
198 | 203 | ||
199 | int SFCave :: nextInt( int range ) | 204 | int SFCave :: nextInt( int range ) |
200 | { | 205 | { |
201 | int val = (int)(Random( ) * range); | 206 | int val = (int)(Random( ) * range); |
202 | 207 | ||
203 | return val; | 208 | return val; |
204 | 209 | ||
205 | } | 210 | } |
206 | 211 | ||
207 | void SFCave :: setUp() | 212 | void SFCave :: setUp() |
208 | { | 213 | { |
209 | score = 0; | 214 | score = 0; |
210 | offset = 0; | 215 | offset = 0; |
211 | nrFrames = 0; | 216 | nrFrames = 0; |
212 | dir = 1; | 217 | dir = 1; |
213 | thrust = 0; | 218 | thrust = 0; |
214 | 219 | ||
215 | if ( CURRENT_GAME_TYPE == SFCAVE_GAME ) | 220 | if ( CURRENT_GAME_TYPE == SFCAVE_GAME ) |
216 | { | 221 | { |
217 | thrustUp = UpThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];; | 222 | thrustUp = UpThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];; |
218 | noThrust = DownThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];; | 223 | noThrust = DownThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];; |
219 | maxUpThrust = MaxUpThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];; | 224 | maxUpThrust = MaxUpThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];; |
220 | maxDownThrust = MaxDownThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];; | 225 | maxDownThrust = MaxDownThrustVals[SFCAVE_GAME_TYPE][currentGameDifficulty];; |
221 | } | 226 | } |
222 | else if ( CURRENT_GAME_TYPE == GATES_GAME ) | 227 | else if ( CURRENT_GAME_TYPE == GATES_GAME ) |
223 | { | 228 | { |
224 | thrustUp = UpThrustVals[GATES_GAME_TYPE][currentGameDifficulty];; | 229 | thrustUp = UpThrustVals[GATES_GAME_TYPE][currentGameDifficulty];; |
225 | noThrust = DownThrustVals[GATES_GAME_TYPE][currentGameDifficulty];; | 230 | noThrust = DownThrustVals[GATES_GAME_TYPE][currentGameDifficulty];; |
226 | maxUpThrust = MaxUpThrustVals[GATES_GAME_TYPE][currentGameDifficulty];; | 231 | maxUpThrust = MaxUpThrustVals[GATES_GAME_TYPE][currentGameDifficulty];; |
227 | maxDownThrust = MaxDownThrustVals[GATES_GAME_TYPE][currentGameDifficulty];; | 232 | maxDownThrust = MaxDownThrustVals[GATES_GAME_TYPE][currentGameDifficulty];; |
228 | } | 233 | } |
229 | else | 234 | else |
230 | { | 235 | { |
231 | thrustUp = UpThrustVals[FLY_GAME_TYPE][currentGameDifficulty]; | 236 | thrustUp = UpThrustVals[FLY_GAME_TYPE][currentGameDifficulty]; |
232 | noThrust = DownThrustVals[FLY_GAME_TYPE][currentGameDifficulty]; | 237 | noThrust = DownThrustVals[FLY_GAME_TYPE][currentGameDifficulty]; |
233 | maxUpThrust = MaxUpThrustVals[FLY_GAME_TYPE][currentGameDifficulty]; | 238 | maxUpThrust = MaxUpThrustVals[FLY_GAME_TYPE][currentGameDifficulty]; |
234 | maxDownThrust = MaxDownThrustVals[FLY_GAME_TYPE][currentGameDifficulty]; | 239 | maxDownThrust = MaxDownThrustVals[FLY_GAME_TYPE][currentGameDifficulty]; |
@@ -590,414 +595,502 @@ void SFCave :: setPoint( int point ) | |||
590 | if ( mapTop[point] < 0 ) | 595 | if ( mapTop[point] < 0 ) |
591 | { | 596 | { |
592 | mapTop[point] = 0; | 597 | mapTop[point] = 0; |
593 | dir *= -1; | 598 | dir *= -1; |
594 | } | 599 | } |
595 | else if ( mapTop[point] >= maxHeight ) | 600 | else if ( mapTop[point] >= maxHeight ) |
596 | { | 601 | { |
597 | mapTop[point] = maxHeight; | 602 | mapTop[point] = maxHeight; |
598 | dir *= -1; | 603 | dir *= -1; |
599 | } | 604 | } |
600 | 605 | ||
601 | // mapBottom[point] = sHeight - (maxHeight - mapBottom[point]); | 606 | // mapBottom[point] = sHeight - (maxHeight - mapBottom[point]); |
602 | mapBottom[point] = sHeight - (maxHeight - mapTop[point]); | 607 | mapBottom[point] = sHeight - (maxHeight - mapTop[point]); |
603 | } | 608 | } |
604 | 609 | ||
605 | void SFCave :: drawBoss() | 610 | void SFCave :: drawBoss() |
606 | { | 611 | { |
607 | offscreen->fill( Qt::black ); | 612 | offscreen->fill( Qt::black ); |
608 | 613 | ||
609 | bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true ); | 614 | bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true ); |
610 | } | 615 | } |
611 | 616 | ||
612 | void SFCave :: draw() | 617 | void SFCave :: draw() |
613 | { | 618 | { |
614 | //printf( "Paint\n" ); | 619 | //printf( "Paint\n" ); |
615 | offscreen->fill( Qt::black ); | 620 | offscreen->fill( Qt::black ); |
616 | 621 | ||
617 | QPainter p( offscreen ); | 622 | QPainter p( offscreen ); |
618 | QFontMetrics fm = p.fontMetrics(); | 623 | QFontMetrics fm = p.fontMetrics(); |
619 | p.setPen( Qt::white ); | 624 | p.setPen( Qt::white ); |
620 | 625 | ||
621 | for ( int i = 0 ; i < MAPSIZE -3; ++i ) | 626 | for ( int i = 0 ; i < MAPSIZE -3; ++i ) |
622 | { | 627 | { |
623 | // Only display top landscape if not running FLY_GAME | 628 | // Only display top landscape if not running FLY_GAME |
624 | if ( CURRENT_GAME_TYPE != FLY_GAME ) | 629 | if ( CURRENT_GAME_TYPE != FLY_GAME ) |
625 | p.drawLine( (i*segSize) - (offset*speed), mapTop[i], ((i+1)*segSize)-(offset*speed), mapTop[i+1] ); | 630 | p.drawLine( (i*segSize) - (offset*speed), mapTop[i], ((i+1)*segSize)-(offset*speed), mapTop[i+1] ); |
626 | 631 | ||
627 | p.drawLine( (i*segSize) - (offset*speed), mapBottom[i], ((i+1)*segSize)-(offset*speed), mapBottom[i+1] ); | 632 | p.drawLine( (i*segSize) - (offset*speed), mapBottom[i], ((i+1)*segSize)-(offset*speed), mapBottom[i+1] ); |
628 | 633 | ||
629 | if ( CURRENT_GAME_TYPE == FLY_GAME && showScoreZones ) | 634 | if ( CURRENT_GAME_TYPE == FLY_GAME && showScoreZones ) |
630 | { | 635 | { |
631 | p.setPen( Qt::red ); | 636 | p.setPen( Qt::red ); |
632 | p.drawLine( (i*segSize) - (offset*speed), mapBottom[i]-10, ((i+1)*segSize)-(offset*speed), mapBottom[i+1]-10 ); | 637 | p.drawLine( (i*segSize) - (offset*speed), mapBottom[i]-10, ((i+1)*segSize)-(offset*speed), mapBottom[i+1]-10 ); |
633 | p.drawLine( (i*segSize) - (offset*speed), mapBottom[i]-20, ((i+1)*segSize)-(offset*speed), mapBottom[i+1]-20 ); | 638 | p.drawLine( (i*segSize) - (offset*speed), mapBottom[i]-20, ((i+1)*segSize)-(offset*speed), mapBottom[i+1]-20 ); |
634 | p.drawLine( (i*segSize) - (offset*speed), mapBottom[i]-30, ((i+1)*segSize)-(offset*speed), mapBottom[i+1]-30 ); | 639 | p.drawLine( (i*segSize) - (offset*speed), mapBottom[i]-30, ((i+1)*segSize)-(offset*speed), mapBottom[i+1]-30 ); |
635 | p.drawLine( (i*segSize) - (offset*speed), mapBottom[i]-40, ((i+1)*segSize)-(offset*speed), mapBottom[i+1]-40 ); | 640 | p.drawLine( (i*segSize) - (offset*speed), mapBottom[i]-40, ((i+1)*segSize)-(offset*speed), mapBottom[i+1]-40 ); |
636 | p.setPen( Qt::white ); | 641 | p.setPen( Qt::white ); |
637 | } | 642 | } |
638 | } | 643 | } |
639 | 644 | ||
640 | // Uncomment this to show user segment (usful for checking collision boundary with landscape | 645 | // Uncomment this to show user segment (usful for checking collision boundary with landscape |
641 | // p.setPen( Qt::red ); | 646 | // p.setPen( Qt::red ); |
642 | // p.drawLine( (11*segSize) - (offset*speed), 0, ((11)*segSize)-(offset*speed), sHeight ); | 647 | // p.drawLine( (11*segSize) - (offset*speed), 0, ((11)*segSize)-(offset*speed), sHeight ); |
643 | // p.setPen( Qt::white ); | 648 | // p.setPen( Qt::white ); |
644 | 649 | ||
645 | // Draw user | 650 | // Draw user |
646 | p.drawRect( user ); | 651 | p.drawRect( user ); |
647 | 652 | ||
648 | // Draw trails | 653 | // Draw trails |
649 | for ( int i = 0 ; i < TRAILSIZE ; ++i ) | 654 | for ( int i = 0 ; i < TRAILSIZE ; ++i ) |
650 | if ( trail[i].x() >= 0 ) | 655 | if ( trail[i].x() >= 0 ) |
651 | p.drawRect( trail[i].x(), trail[i].y(), 2, 2 ); | 656 | p.drawRect( trail[i].x(), trail[i].y(), 2, 2 ); |
652 | 657 | ||
653 | // Draw blocks | 658 | // Draw blocks |
654 | for ( int i = 0 ; i < BLOCKSIZE ; ++i ) | 659 | for ( int i = 0 ; i < BLOCKSIZE ; ++i ) |
655 | if ( blocks[i].y() != -1 ) | 660 | if ( blocks[i].y() != -1 ) |
656 | { | 661 | { |
657 | p.fillRect( blocks[i], Qt::black ); | 662 | p.fillRect( blocks[i], Qt::black ); |
658 | p.drawRect( blocks[i] ); | 663 | p.drawRect( blocks[i] ); |
659 | } | 664 | } |
660 | 665 | ||
661 | // draw score | 666 | // draw score |
662 | QString s; | 667 | QString s; |
663 | s.sprintf( "score %06d high score %06d", score, highestScore[currentGameType][currentGameDifficulty] ); | 668 | s.sprintf( "score %06d high score %06d", score, highestScore[currentGameType][currentGameDifficulty] ); |
664 | p.drawText( 5, 10, s ); | 669 | p.drawText( 5, 10, s ); |
665 | 670 | ||
666 | 671 | ||
667 | if ( state == STATE_CRASHING || state == STATE_CRASHED ) | 672 | if ( state == STATE_CRASHING || state == STATE_CRASHED ) |
668 | { | 673 | { |
669 | // add next crash line | 674 | // add next crash line |
670 | 675 | ||
671 | if ( crashLineLength != -1 ) | 676 | if ( crashLineLength != -1 ) |
672 | { | 677 | { |
673 | for ( int i = 0 ; i < 36 ; ++i ) | 678 | for ( int i = 0 ; i < 36 ; ++i ) |
674 | { | 679 | { |
675 | int x = (int)(user.x() + (crashLineLength+nextInt(10)) * cos( (M_PI/180) * (10.0 * i) ) ); | 680 | int x = (int)(user.x() + (crashLineLength+nextInt(10)) * cos( (M_PI/180) * (10.0 * i) ) ); |
676 | int y = (int)(user.y() + (crashLineLength+nextInt(10)) * sin( (M_PI/180) * (10.0 * i) ) ); p.drawLine( user.x(), user.y(), x, y ); | 681 | int y = (int)(user.y() + (crashLineLength+nextInt(10)) * sin( (M_PI/180) * (10.0 * i) ) ); p.drawLine( user.x(), user.y(), x, y ); |
677 | } | 682 | } |
678 | } | 683 | } |
679 | 684 | ||
680 | if ( state == STATE_CRASHING && crashLineLength >= 15 ) //|| crashLineLength == -1) ) | 685 | if ( state == STATE_CRASHING && crashLineLength >= 15 ) //|| crashLineLength == -1) ) |
681 | state = STATE_CRASHED; | 686 | state = STATE_CRASHED; |
682 | 687 | ||
683 | if ( state == STATE_CRASHED ) | 688 | if ( state == STATE_CRASHED ) |
684 | { | 689 | { |
685 | QString text = "Press up or down to start"; | 690 | QString text = "Press up or down to start"; |
686 | p.drawText( (sWidth/2) - (fm.width( text )/2), 140, text ); | 691 | p.drawText( (sWidth/2) - (fm.width( text )/2), 120, text ); |
692 | |||
693 | text = "Press OK for menu"; | ||
694 | p.drawText( (sWidth/2) - (fm.width( text )/2), 135, text ); | ||
687 | 695 | ||
688 | text = "or press OK for menu"; | 696 | text = "Press r to replay"; |
689 | p.drawText( (sWidth/2) - (fm.width( text )/2), 155, text ); | 697 | p.drawText( (sWidth/2) - (fm.width( text )/2), 150, text ); |
698 | |||
699 | text = "Press s to save the replay"; | ||
700 | p.drawText( (sWidth/2) - (fm.width( text )/2), 165, text ); | ||
701 | |||
702 | text = "Press r to load a saved replay"; | ||
703 | p.drawText( (sWidth/2) - (fm.width( text )/2), 180, text ); | ||
690 | } | 704 | } |
691 | else | 705 | else |
692 | crashLineLength ++; | 706 | crashLineLength ++; |
693 | } | 707 | } |
694 | 708 | ||
695 | p.end(); | 709 | p.end(); |
696 | bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true ); | 710 | bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true ); |
697 | //printf( "endpaint\n" ); | 711 | //printf( "endpaint\n" ); |
698 | } | 712 | } |
699 | 713 | ||
700 | void SFCave :: handleKeys() | 714 | void SFCave :: handleKeys() |
701 | { | 715 | { |
702 | // Find enpty trail and move others | 716 | // Find enpty trail and move others |
703 | bool done = false; | 717 | bool done = false; |
704 | for ( int i = 0 ; i < TRAILSIZE ; ++i ) | 718 | for ( int i = 0 ; i < TRAILSIZE ; ++i ) |
705 | { | 719 | { |
706 | if ( trail[i].x() < 0 ) | 720 | if ( trail[i].x() < 0 ) |
707 | { | 721 | { |
708 | if ( !done ) | 722 | if ( !done ) |
709 | { | 723 | { |
710 | trail[i].setX( user.x() - 5 ); | 724 | trail[i].setX( user.x() - 5 ); |
711 | trail[i].setY( user.y() ); | 725 | trail[i].setY( user.y() ); |
712 | done = true; | 726 | done = true; |
713 | } | 727 | } |
714 | } | 728 | } |
715 | else | 729 | else |
716 | { | 730 | { |
717 | trail[i].setX( trail[i].x() - (2) ); | 731 | trail[i].setX( trail[i].x() - (2) ); |
718 | } | 732 | } |
719 | } | 733 | } |
720 | 734 | ||
721 | if ( speed <= 3 ) | 735 | if ( speed <= 3 ) |
722 | { | 736 | { |
723 | if ( press ) | 737 | if ( press ) |
724 | thrust -= thrustUp; | 738 | thrust -= thrustUp; |
725 | else | 739 | else |
726 | thrust += noThrust; | 740 | thrust += noThrust; |
727 | 741 | ||
728 | if ( thrust > maxDownThrust ) | 742 | if ( thrust > maxDownThrust ) |
729 | thrust = maxDownThrust; | 743 | thrust = maxDownThrust; |
730 | else if ( thrust < maxUpThrust ) | 744 | else if ( thrust < maxUpThrust ) |
731 | thrust = maxUpThrust; | 745 | thrust = maxUpThrust; |
732 | } | 746 | } |
733 | else | 747 | else |
734 | { | 748 | { |
735 | if ( press ) | 749 | if ( press ) |
736 | thrust -= 0.5; | 750 | thrust -= 0.5; |
737 | else | 751 | else |
738 | thrust += 0.8; | 752 | thrust += 0.8; |
739 | 753 | ||
740 | if ( thrust > 5.0 ) | 754 | if ( thrust > 5.0 ) |
741 | thrust = 5.0; | 755 | thrust = 5.0; |
742 | else if ( thrust < -3.5 ) | 756 | else if ( thrust < -3.5 ) |
743 | thrust = -3.5; | 757 | thrust = -3.5; |
744 | } | 758 | } |
745 | user.moveBy( 0, (int)thrust ); | 759 | user.moveBy( 0, (int)thrust ); |
746 | } | 760 | } |
747 | 761 | ||
748 | void SFCave :: keyPressEvent( QKeyEvent *e ) | 762 | void SFCave :: keyPressEvent( QKeyEvent *e ) |
749 | { | 763 | { |
750 | if ( state == STATE_MENU ) | 764 | if ( state == STATE_MENU ) |
751 | { | 765 | { |
752 | switch( e->key() ) | 766 | switch( e->key() ) |
753 | { | 767 | { |
754 | case Qt::Key_Down: | 768 | case Qt::Key_Down: |
755 | currentMenuOption[currentMenuNr] ++; | 769 | currentMenuOption[currentMenuNr] ++; |
756 | if ( menuOptions[currentMenuNr][currentMenuOption[currentMenuNr]] == "" ) | 770 | if ( menuOptions[currentMenuNr][currentMenuOption[currentMenuNr]] == "" ) |
757 | currentMenuOption[currentMenuNr] = 0; | 771 | currentMenuOption[currentMenuNr] = 0; |
758 | break; | 772 | break; |
759 | case Qt::Key_Up: | 773 | case Qt::Key_Up: |
760 | currentMenuOption[currentMenuNr] --; | 774 | currentMenuOption[currentMenuNr] --; |
761 | if ( currentMenuOption[currentMenuNr] < 0 ) | 775 | if ( currentMenuOption[currentMenuNr] < 0 ) |
762 | currentMenuOption[currentMenuNr] = nrMenuOptions[currentMenuNr]-1; | 776 | currentMenuOption[currentMenuNr] = nrMenuOptions[currentMenuNr]-1; |
763 | break; | 777 | break; |
764 | 778 | ||
765 | case Qt::Key_Left: | 779 | case Qt::Key_Left: |
766 | if ( currentMenuNr == MENU_OPTIONS_MENU ) | 780 | if ( currentMenuNr == MENU_OPTIONS_MENU ) |
767 | { | 781 | { |
768 | if ( currentMenuOption[currentMenuNr] == MENU_GAME_TYPE ) | 782 | if ( currentMenuOption[currentMenuNr] == MENU_GAME_TYPE ) |
769 | { | 783 | { |
770 | currentGameType --; | 784 | currentGameType --; |
771 | if ( currentGameType < 0 ) | 785 | if ( currentGameType < 0 ) |
772 | currentGameType = NR_GAME_TYPES - 1; | 786 | currentGameType = NR_GAME_TYPES - 1; |
773 | } | 787 | } |
774 | else if ( currentMenuOption[currentMenuNr] == MENU_GAME_DIFFICULTY ) | 788 | else if ( currentMenuOption[currentMenuNr] == MENU_GAME_DIFFICULTY ) |
775 | { | 789 | { |
776 | currentGameDifficulty --; | 790 | currentGameDifficulty --; |
777 | if ( currentGameDifficulty < 0 ) | 791 | if ( currentGameDifficulty < 0 ) |
778 | currentGameDifficulty = NR_GAME_DIFFICULTIES - 1; | 792 | currentGameDifficulty = NR_GAME_DIFFICULTIES - 1; |
779 | } | 793 | } |
780 | } | 794 | } |
781 | break; | 795 | break; |
782 | 796 | ||
783 | case Qt::Key_Right: | 797 | case Qt::Key_Right: |
784 | if ( currentMenuNr == MENU_OPTIONS_MENU ) | 798 | if ( currentMenuNr == MENU_OPTIONS_MENU ) |
785 | { | 799 | { |
786 | if ( currentMenuOption[currentMenuNr] == MENU_GAME_TYPE ) | 800 | if ( currentMenuOption[currentMenuNr] == MENU_GAME_TYPE ) |
787 | { | 801 | { |
788 | currentGameType ++; | 802 | currentGameType ++; |
789 | if ( currentGameType == NR_GAME_TYPES ) | 803 | if ( currentGameType == NR_GAME_TYPES ) |
790 | currentGameType = 0; | 804 | currentGameType = 0; |
791 | } | 805 | } |
792 | else if ( currentMenuOption[currentMenuNr] == MENU_GAME_DIFFICULTY ) | 806 | else if ( currentMenuOption[currentMenuNr] == MENU_GAME_DIFFICULTY ) |
793 | { | 807 | { |
794 | currentGameDifficulty ++; | 808 | currentGameDifficulty ++; |
795 | if ( currentGameDifficulty == NR_GAME_DIFFICULTIES ) | 809 | if ( currentGameDifficulty == NR_GAME_DIFFICULTIES ) |
796 | currentGameDifficulty = 0; | 810 | currentGameDifficulty = 0; |
797 | } | 811 | } |
798 | } | 812 | } |
799 | break; | 813 | break; |
800 | 814 | ||
801 | case Qt::Key_Space: | 815 | case Qt::Key_Space: |
802 | case Qt::Key_Return: | 816 | case Qt::Key_Return: |
803 | case Qt::Key_Enter: | 817 | case Qt::Key_Enter: |
804 | dealWithMenuSelection(); | 818 | dealWithMenuSelection(); |
805 | break; | 819 | break; |
806 | } | 820 | } |
807 | } | 821 | } |
808 | else | 822 | else |
809 | { | 823 | { |
810 | switch( e->key() ) | 824 | switch( e->key() ) |
811 | { | 825 | { |
812 | case Qt::Key_Up: | 826 | case Qt::Key_Up: |
813 | case Qt::Key_F9: | 827 | case Qt::Key_F9: |
814 | case Qt::Key_Space: | 828 | case Qt::Key_Space: |
815 | if ( !press ) | 829 | if ( !press ) |
816 | { | 830 | { |
817 | press = true; | 831 | press = true; |
818 | replayList.append( new int( nrFrames ) ); | 832 | replayList.append( new int( nrFrames ) ); |
819 | } | 833 | } |
820 | break; | 834 | break; |
821 | case Qt::Key_M: | 835 | case Qt::Key_M: |
822 | case Qt::Key_Return: | 836 | case Qt::Key_Return: |
823 | case Qt::Key_Enter: | 837 | case Qt::Key_Enter: |
824 | if ( state == STATE_CRASHED ) | 838 | if ( state == STATE_CRASHED ) |
825 | state = STATE_MENU; | 839 | state = STATE_MENU; |
826 | break; | 840 | break; |
827 | 841 | ||
828 | case Qt::Key_Z: | 842 | case Qt::Key_Z: |
829 | showScoreZones = !showScoreZones; | 843 | showScoreZones = !showScoreZones; |
830 | break; | 844 | break; |
831 | 845 | ||
832 | default: | 846 | default: |
833 | e->ignore(); | 847 | e->ignore(); |
834 | break; | 848 | break; |
835 | } | 849 | } |
836 | } | 850 | } |
837 | } | 851 | } |
838 | 852 | ||
839 | void SFCave :: keyReleaseEvent( QKeyEvent *e ) | 853 | void SFCave :: keyReleaseEvent( QKeyEvent *e ) |
840 | { | 854 | { |
841 | if ( state == STATE_MENU ) | 855 | if ( state == STATE_MENU ) |
842 | { | 856 | { |
843 | } | 857 | } |
844 | else | 858 | else |
845 | { | 859 | { |
846 | switch( e->key() ) | 860 | switch( e->key() ) |
847 | { | 861 | { |
848 | case Qt::Key_F9: | 862 | case Qt::Key_F9: |
849 | case Qt::Key_Space: | 863 | case Qt::Key_Space: |
850 | case Qt::Key_Up: | 864 | case Qt::Key_Up: |
851 | if ( press ) | 865 | if ( press ) |
852 | { | 866 | { |
853 | press = false; | 867 | press = false; |
854 | 868 | ||
855 | replayList.append( new int( nrFrames ) ); | 869 | replayList.append( new int( nrFrames ) ); |
856 | } | 870 | } |
857 | break; | 871 | break; |
858 | 872 | ||
859 | case Qt::Key_R: | 873 | case Qt::Key_R: |
860 | if ( state == STATE_CRASHED ) | 874 | if ( state == STATE_CRASHED ) |
861 | { | 875 | { |
862 | state = STATE_REPLAY; | 876 | state = STATE_REPLAY; |
863 | } | 877 | } |
864 | break; | 878 | break; |
865 | 879 | ||
866 | case Qt::Key_Down: | 880 | case Qt::Key_Down: |
867 | if ( state == STATE_CRASHED ) | 881 | if ( state == STATE_CRASHED ) |
868 | state = STATE_NEWGAME; | 882 | state = STATE_NEWGAME; |
869 | break; | 883 | break; |
884 | |||
885 | case Qt::Key_S: | ||
886 | saveReplay(); | ||
887 | break; | ||
888 | |||
889 | case Qt::Key_L: | ||
890 | loadReplay(); | ||
891 | break; | ||
870 | default: | 892 | default: |
871 | e->ignore(); | 893 | e->ignore(); |
872 | break; | 894 | break; |
873 | } | 895 | } |
874 | } | 896 | } |
875 | 897 | ||
876 | } | 898 | } |
877 | 899 | ||
878 | void SFCave :: displayMenu() | 900 | void SFCave :: displayMenu() |
879 | { | 901 | { |
880 | offscreen->fill( Qt::black ); | 902 | offscreen->fill( Qt::black ); |
881 | 903 | ||
882 | QPainter p( offscreen ); | 904 | QPainter p( offscreen ); |
883 | p.setPen( Qt::white ); | 905 | p.setPen( Qt::white ); |
884 | 906 | ||
885 | QFont f( "Helvetica", 16 ); | 907 | QFont f( "Helvetica", 16 ); |
886 | p.setFont( f ); | 908 | p.setFont( f ); |
887 | 909 | ||
888 | QFontMetrics fm = p.fontMetrics(); | 910 | QFontMetrics fm = p.fontMetrics(); |
889 | 911 | ||
890 | QString text = "SFCave"; | 912 | QString text = "SFCave"; |
891 | p.drawText( (sWidth/2) - (fm.width( text )/2), 60, text ); | 913 | p.drawText( (sWidth/2) - (fm.width( text )/2), 60, text ); |
892 | 914 | ||
893 | text = "Written by Andy Qua"; | 915 | text = "Written by Andy Qua"; |
894 | p.drawText( (sWidth/2) - (fm.width( text )/2), 85, text ); | 916 | p.drawText( (sWidth/2) - (fm.width( text )/2), 85, text ); |
895 | 917 | ||
896 | // Draw options | 918 | // Draw options |
897 | int pos = 170; | 919 | int pos = 170; |
898 | for ( int i = 0 ; menuOptions[currentMenuNr][i] != "" ; ++i, pos += 25 ) | 920 | for ( int i = 0 ; menuOptions[currentMenuNr][i] != "" ; ++i, pos += 25 ) |
899 | { | 921 | { |
900 | if ( currentMenuOption[currentMenuNr] == i ) | 922 | if ( currentMenuOption[currentMenuNr] == i ) |
901 | p.setPen( Qt::yellow ); | 923 | p.setPen( Qt::yellow ); |
902 | else | 924 | else |
903 | p.setPen( Qt::white ); | 925 | p.setPen( Qt::white ); |
904 | 926 | ||
905 | QString text; | 927 | QString text; |
906 | if ( menuOptions[currentMenuNr][i].find( "%s" ) != -1 ) | 928 | if ( menuOptions[currentMenuNr][i].find( "%s" ) != -1 ) |
907 | { | 929 | { |
908 | QString val; | 930 | QString val; |
909 | if ( i == MENU_GAME_TYPE ) | 931 | if ( i == MENU_GAME_TYPE ) |
910 | val = gameTypes[currentGameType]; | 932 | val = gameTypes[currentGameType]; |
911 | else | 933 | else |
912 | val = dificultyOption[currentGameDifficulty]; | 934 | val = dificultyOption[currentGameDifficulty]; |
913 | 935 | ||
914 | text.sprintf( (const char *)menuOptions[currentMenuNr][i], (const char *)val ); | 936 | text.sprintf( (const char *)menuOptions[currentMenuNr][i], (const char *)val ); |
915 | } | 937 | } |
916 | else | 938 | else |
917 | text = menuOptions[currentMenuNr][i]; | 939 | text = menuOptions[currentMenuNr][i]; |
918 | 940 | ||
919 | p.drawText( (sWidth/2) - (fm.width( text )/2), pos, text ); | 941 | p.drawText( (sWidth/2) - (fm.width( text )/2), pos, text ); |
920 | } | 942 | } |
921 | 943 | ||
922 | p.end(); | 944 | p.end(); |
923 | bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true ); | 945 | bitBlt( this, 0, 0, offscreen, 0, 0, sWidth, sHeight, Qt::CopyROP, true ); |
924 | } | 946 | } |
925 | 947 | ||
926 | void SFCave :: dealWithMenuSelection() | 948 | void SFCave :: dealWithMenuSelection() |
927 | { | 949 | { |
928 | switch( currentMenuNr ) | 950 | switch( currentMenuNr ) |
929 | { | 951 | { |
930 | case MENU_MAIN_MENU: | 952 | case MENU_MAIN_MENU: |
931 | { | 953 | { |
932 | switch( currentMenuOption[currentMenuNr] ) | 954 | switch( currentMenuOption[currentMenuNr] ) |
933 | { | 955 | { |
934 | case MENU_START_GAME: | 956 | case MENU_START_GAME: |
935 | state = STATE_NEWGAME; | 957 | state = STATE_NEWGAME; |
936 | break; | 958 | break; |
937 | 959 | ||
938 | case MENU_OPTIONS: | 960 | case MENU_OPTIONS: |
939 | currentMenuNr = MENU_OPTIONS_MENU; | 961 | currentMenuNr = MENU_OPTIONS_MENU; |
940 | currentMenuOption[currentMenuNr] = 0; | 962 | currentMenuOption[currentMenuNr] = 0; |
941 | break; | 963 | break; |
942 | 964 | ||
943 | case MENU_HELP: | 965 | case MENU_HELP: |
944 | { | 966 | { |
945 | // Display Help Menu | 967 | // Display Help Menu |
946 | HelpWindow *dlg = new HelpWindow( this ); | 968 | HelpWindow *dlg = new HelpWindow( this ); |
947 | dlg->exec(); | 969 | dlg->exec(); |
948 | delete dlg; | 970 | delete dlg; |
949 | break; | 971 | break; |
950 | } | 972 | } |
951 | 973 | ||
952 | case MENU_QUIT: | 974 | case MENU_QUIT: |
953 | QApplication::exit(); | 975 | QApplication::exit(); |
954 | break; | 976 | break; |
955 | } | 977 | } |
956 | 978 | ||
957 | break; | 979 | break; |
958 | } | 980 | } |
959 | 981 | ||
960 | case MENU_OPTIONS_MENU: | 982 | case MENU_OPTIONS_MENU: |
961 | { | 983 | { |
962 | switch( currentMenuOption[currentMenuNr] ) | 984 | switch( currentMenuOption[currentMenuNr] ) |
963 | { | 985 | { |
964 | case MENU_GAME_TYPE: | 986 | case MENU_GAME_TYPE: |
965 | break; | 987 | break; |
966 | 988 | ||
967 | case MENU_GAME_DIFFICULTY: | 989 | case MENU_GAME_DIFFICULTY: |
968 | break; | 990 | break; |
969 | 991 | ||
970 | case MENU_CLEAR_HIGHSCORES: | 992 | case MENU_CLEAR_HIGHSCORES: |
971 | for ( int i = 0 ; i < 3 ; ++i ) | 993 | for ( int i = 0 ; i < 3 ; ++i ) |
972 | highestScore[currentGameType][i] = 0; | 994 | highestScore[currentGameType][i] = 0; |
973 | break; | 995 | break; |
974 | 996 | ||
975 | case MENU_BACK: | 997 | case MENU_BACK: |
976 | currentMenuNr = MENU_MAIN_MENU; | 998 | currentMenuNr = MENU_MAIN_MENU; |
977 | 999 | ||
978 | #ifdef QWS | 1000 | #ifdef QWS |
979 | Config cfg( "sfcave" ); | 1001 | Config cfg( "sfcave" ); |
980 | cfg.setGroup( "settings" ); | 1002 | cfg.setGroup( "settings" ); |
981 | cfg.writeEntry( "difficulty", currentGameDifficulty ); | 1003 | cfg.writeEntry( "difficulty", currentGameDifficulty ); |
982 | cfg.writeEntry( "gameType", currentGameType ); | 1004 | cfg.writeEntry( "gameType", currentGameType ); |
983 | #endif | 1005 | #endif |
984 | break; | 1006 | break; |
985 | } | 1007 | } |
986 | 1008 | ||
987 | break; | 1009 | break; |
988 | } | 1010 | } |
989 | } | 1011 | } |
990 | } | 1012 | } |
991 | 1013 | ||
992 | void SFCave :: saveScore() | 1014 | void SFCave :: saveScore() |
993 | { | 1015 | { |
994 | #ifdef QWS | 1016 | #ifdef QWS |
995 | Config cfg( "sfcave" ); | 1017 | Config cfg( "sfcave" ); |
996 | cfg.setGroup( "settings" ); | 1018 | cfg.setGroup( "settings" ); |
997 | QString key = "highScore_"; | 1019 | QString key = "highScore_"; |
998 | 1020 | ||
999 | cfg.writeEntry( key + gameTypes[currentGameType] + "_" + dificultyOption[currentGameDifficulty], highestScore[currentGameType][currentGameDifficulty] ); | 1021 | cfg.writeEntry( key + gameTypes[currentGameType] + "_" + dificultyOption[currentGameDifficulty], highestScore[currentGameType][currentGameDifficulty] ); |
1000 | key += CURRENT_GAME_TYPE; | 1022 | key += CURRENT_GAME_TYPE; |
1001 | cfg.writeEntry( key, highestScore[currentGameType] ); | 1023 | cfg.writeEntry( key, highestScore[currentGameType] ); |
1002 | #endif | 1024 | #endif |
1003 | } | 1025 | } |
1026 | |||
1027 | void SFCave :: saveReplay() | ||
1028 | { | ||
1029 | FILE *out; | ||
1030 | out = fopen( (const char *)replayFile, "w" ); | ||
1031 | if ( !out ) | ||
1032 | { | ||
1033 | printf( "Couldn't write to /home/root/sfcave.replay\n" ); | ||
1034 | return; | ||
1035 | } | ||
1036 | |||
1037 | // Build up string of values | ||
1038 | // Format is:: <landscape seed> <framenr> <framenr>....... | ||
1039 | QString val; | ||
1040 | val.sprintf( "%d ", currentSeed ); | ||
1041 | |||
1042 | QListIterator<int> it( replayList ); | ||
1043 | while( it.current() ) | ||
1044 | { | ||
1045 | QString tmp; | ||
1046 | tmp.sprintf( "%d ", (*it.current()) ); | ||
1047 | val += tmp; | ||
1048 | |||
1049 | ++it; | ||
1050 | } | ||
1051 | val += "\n"; | ||
1052 | |||
1053 | QString line; | ||
1054 | line.sprintf( "%d\n", val.length() ); | ||
1055 | fwrite( (const char *)line, 1, line.length(), out ); | ||
1056 | fwrite( (const char *)val, 1, val.length(), out ); | ||
1057 | |||
1058 | fclose( out ); | ||
1059 | |||
1060 | printf( "Replay saved to %s\n", (const char *)replayFile ); | ||
1061 | |||
1062 | } | ||
1063 | |||
1064 | void SFCave :: loadReplay() | ||
1065 | { | ||
1066 | FILE *in = fopen( (const char *)replayFile, "r" ); | ||
1067 | |||
1068 | // Read size of next line | ||
1069 | char line[10+1]; | ||
1070 | fgets( line, 10, in ); | ||
1071 | |||
1072 | int length = -1; | ||
1073 | sscanf( line, "%d", &length ); | ||
1074 | char *data = new char[length+1]; | ||
1075 | |||
1076 | fread( data, 1, length, in ); | ||
1077 | |||
1078 | QString sep = " "; | ||
1079 | QStringList list = QStringList::split( sep, QString( data ) ); | ||
1080 | |||
1081 | // print it out | ||
1082 | QStringList::Iterator it = list.begin(); | ||
1083 | currentSeed = (*it).toInt(); | ||
1084 | ++it; | ||
1085 | |||
1086 | replayList.clear(); | ||
1087 | for ( ; it != list.end(); ++it ) | ||
1088 | { | ||
1089 | int v = (*it).toInt(); | ||
1090 | replayList.append( new int( v ) ); | ||
1091 | } | ||
1092 | |||
1093 | delete data; | ||
1094 | |||
1095 | fclose( in ); | ||
1096 | } \ No newline at end of file | ||