Diffstat (limited to 'noncore/games/sfcave-sdl/game.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/games/sfcave-sdl/game.cpp | 46 |
1 files changed, 21 insertions, 25 deletions
diff --git a/noncore/games/sfcave-sdl/game.cpp b/noncore/games/sfcave-sdl/game.cpp index a644696..e41e510 100644 --- a/noncore/games/sfcave-sdl/game.cpp +++ b/noncore/games/sfcave-sdl/game.cpp | |||
@@ -76,9 +76,6 @@ void Game :: handleKeys( SDL_KeyboardEvent &key ) | |||
76 | if ( !press ) | 76 | if ( !press ) |
77 | replayList.push_back( nrFrames ); | 77 | replayList.push_back( nrFrames ); |
78 | press = true; | 78 | press = true; |
79 | |||
80 | // if ( thrustChannel == -1 && parent->getState() == STATE_PLAYING ) | ||
81 | // thrustChannel = SoundHandler :: playSound( SND_THRUST, -1, -1, false ); | ||
82 | } | 79 | } |
83 | else | 80 | else |
84 | { | 81 | { |
@@ -86,20 +83,15 @@ void Game :: handleKeys( SDL_KeyboardEvent &key ) | |||
86 | replayList.push_back( nrFrames ); | 83 | replayList.push_back( nrFrames ); |
87 | press = false; | 84 | press = false; |
88 | 85 | ||
89 | if ( thrustChannel != -1 ) | ||
90 | { | ||
91 | // SoundHandler :: stopSound( thrustChannel, true, 300 ); | ||
92 | // thrustChannel = -1; | ||
93 | } | ||
94 | } | 86 | } |
95 | } | 87 | } |
96 | } | 88 | } |
97 | 89 | ||
98 | 90 | ||
99 | 91 | ||
100 | QString Game :: getGameDifficultyText() | 92 | string Game :: getGameDifficultyText() |
101 | { | 93 | { |
102 | QString ret; | 94 | string ret; |
103 | 95 | ||
104 | if ( difficulty == MENU_DIFFICULTY_EASY ) | 96 | if ( difficulty == MENU_DIFFICULTY_EASY ) |
105 | ret = "Easy"; | 97 | ret = "Easy"; |
@@ -107,6 +99,8 @@ QString Game :: getGameDifficultyText() | |||
107 | ret = "Medium"; | 99 | ret = "Medium"; |
108 | else if ( difficulty == MENU_DIFFICULTY_HARD ) | 100 | else if ( difficulty == MENU_DIFFICULTY_HARD ) |
109 | ret = "Hard"; | 101 | ret = "Hard"; |
102 | else if ( difficulty == MENU_DIFFICULTY_CUSTOM ) | ||
103 | ret = "Custom"; | ||
110 | 104 | ||
111 | return ret; | 105 | return ret; |
112 | } | 106 | } |
@@ -119,6 +113,16 @@ void Game :: setDifficulty( string diff ) | |||
119 | difficulty = MENU_DIFFICULTY_NORMAL; | 113 | difficulty = MENU_DIFFICULTY_NORMAL; |
120 | else if ( diff == "Hard" ) | 114 | else if ( diff == "Hard" ) |
121 | difficulty = MENU_DIFFICULTY_HARD; | 115 | difficulty = MENU_DIFFICULTY_HARD; |
116 | else if ( diff == "Custom" ) | ||
117 | difficulty = MENU_DIFFICULTY_CUSTOM; | ||
118 | |||
119 | init(); | ||
120 | } | ||
121 | |||
122 | void Game :: setDifficulty( int diff ) | ||
123 | { | ||
124 | difficulty = diff; | ||
125 | init(); | ||
122 | } | 126 | } |
123 | 127 | ||
124 | void Game :: update( int state ) | 128 | void Game :: update( int state ) |
@@ -166,14 +170,13 @@ void Game :: preDraw( SDL_Surface *screen ) | |||
166 | void Game :: draw( SDL_Surface *screen ) | 170 | void Game :: draw( SDL_Surface *screen ) |
167 | { | 171 | { |
168 | char tmp[100]; | 172 | char tmp[100]; |
169 | QString scoreText; | 173 | string scoreText; |
170 | sprintf( tmp, "Score: %06ld High Score: %06ld", score, highScore ); | 174 | sprintf( tmp, "Score: %06ld High Score: %06ld", score, highScore ); |
171 | //printf( "%s\n", (const char *)scoreText ); | ||
172 | FontHandler::draw( screen, FONT_WHITE_TEXT, tmp, 3, 10 ); | 175 | FontHandler::draw( screen, FONT_WHITE_TEXT, tmp, 3, 10 ); |
173 | 176 | ||
174 | if ( parent->getState() == STATE_CRASHED ) | 177 | if ( parent->getState() == STATE_CRASHED ) |
175 | { | 178 | { |
176 | QString crashText; | 179 | string crashText; |
177 | crashText = "Game Over"; | 180 | crashText = "Game Over"; |
178 | int x = (240 - FontHandler::TextWidth( FONT_WHITE_TEXT, (const char *)crashText.c_str() )) / 2; | 181 | int x = (240 - FontHandler::TextWidth( FONT_WHITE_TEXT, (const char *)crashText.c_str() )) / 2; |
179 | FontHandler::draw( screen, FONT_WHITE_TEXT, (const char *)crashText.c_str(), x, 150 ); | 182 | FontHandler::draw( screen, FONT_WHITE_TEXT, (const char *)crashText.c_str(), x, 150 ); |
@@ -223,7 +226,7 @@ void Game :: setSeed( int seed ) | |||
223 | PutSeed( currentSeed ); | 226 | PutSeed( currentSeed ); |
224 | } | 227 | } |
225 | 228 | ||
226 | void Game :: saveReplay( QString file ) | 229 | void Game :: saveReplay( string file ) |
227 | { | 230 | { |
228 | FILE *out; | 231 | FILE *out; |
229 | out = fopen( file.c_str(), "w" ); | 232 | out = fopen( file.c_str(), "w" ); |
@@ -236,7 +239,7 @@ void Game :: saveReplay( QString file ) | |||
236 | 239 | ||
237 | // Build up string of values | 240 | // Build up string of values |
238 | // Format is:: <landscape seed> <game type> <difficulty> <framenr> <framenr>....... | 241 | // Format is:: <landscape seed> <game type> <difficulty> <framenr> <framenr>....... |
239 | QString val; | 242 | string val; |
240 | char tmp[20]; | 243 | char tmp[20]; |
241 | sprintf( tmp, "%d %d ", currentSeed, difficulty ); | 244 | sprintf( tmp, "%d %d ", currentSeed, difficulty ); |
242 | val = tmp; | 245 | val = tmp; |
@@ -251,7 +254,7 @@ void Game :: saveReplay( QString file ) | |||
251 | } | 254 | } |
252 | val += "\n"; | 255 | val += "\n"; |
253 | 256 | ||
254 | QString line; | 257 | string line; |
255 | sprintf( tmp, "%d\n", val.length() ); | 258 | sprintf( tmp, "%d\n", val.length() ); |
256 | line = tmp; | 259 | line = tmp; |
257 | fwrite( line.c_str(), 1, line.length(), out ); | 260 | fwrite( line.c_str(), 1, line.length(), out ); |
@@ -259,12 +262,9 @@ void Game :: saveReplay( QString file ) | |||
259 | fwrite( val.c_str(), 1, val.length(), out ); | 262 | fwrite( val.c_str(), 1, val.length(), out ); |
260 | 263 | ||
261 | fclose( out ); | 264 | fclose( out ); |
262 | |||
263 | printf( "Replay saved to %s\n", (const char *)file.c_str() ); | ||
264 | |||
265 | } | 265 | } |
266 | 266 | ||
267 | void Game :: loadReplay( QString file ) | 267 | void Game :: loadReplay( string file ) |
268 | { | 268 | { |
269 | 269 | ||
270 | FILE *in = fopen( (const char *)file.c_str(), "r" ); | 270 | FILE *in = fopen( (const char *)file.c_str(), "r" ); |
@@ -285,9 +285,8 @@ void Game :: loadReplay( QString file ) | |||
285 | char *data = new char[length+1]; | 285 | char *data = new char[length+1]; |
286 | 286 | ||
287 | fread( data, 1, length, in ); | 287 | fread( data, 1, length, in ); |
288 | // printf( "data - %s", data ); | ||
289 | 288 | ||
290 | QString sep = " "; | 289 | string sep = " "; |
291 | 290 | ||
292 | StringTokenizer st( data, sep ); | 291 | StringTokenizer st( data, sep ); |
293 | 292 | ||
@@ -308,9 +307,6 @@ void Game :: loadReplay( QString file ) | |||
308 | delete data; | 307 | delete data; |
309 | 308 | ||
310 | fclose( in ); | 309 | fclose( in ); |
311 | |||
312 | printf( "Replay loaded from %s\n", (const char *)file.c_str() ); | ||
313 | |||
314 | } | 310 | } |
315 | 311 | ||
316 | 312 | ||