author | andyq <andyq> | 2003-01-21 20:37:00 (UTC) |
---|---|---|
committer | andyq <andyq> | 2003-01-21 20:37:00 (UTC) |
commit | 0a6563fcc2f49857c581d9def24407a3a4ef526c (patch) (unidiff) | |
tree | f1b82a4bd7582ef2cb722cffb87eecff1e1f96e6 | |
parent | 50b5915b48fc5cbacf23e4d2b75d7a266f141a4a (diff) | |
download | opie-0a6563fcc2f49857c581d9def24407a3a4ef526c.zip opie-0a6563fcc2f49857c581d9def24407a3a4ef526c.tar.gz opie-0a6563fcc2f49857c581d9def24407a3a4ef526c.tar.bz2 |
Clean up of code - fixed memory leaks (most of them) and added new custom config menu
25 files changed, 682 insertions, 300 deletions
diff --git a/noncore/games/sfcave-sdl/animatedimage.cpp b/noncore/games/sfcave-sdl/animatedimage.cpp index d9d6ff6..441c647 100644 --- a/noncore/games/sfcave-sdl/animatedimage.cpp +++ b/noncore/games/sfcave-sdl/animatedimage.cpp | |||
@@ -5,5 +5,5 @@ | |||
5 | #include "animatedimage.h" | 5 | #include "animatedimage.h" |
6 | 6 | ||
7 | AnimatedImage :: AnimatedImage( QString file, int nFrames ) | 7 | AnimatedImage :: AnimatedImage( string file, int nFrames ) |
8 | { | 8 | { |
9 | nrFrames = nFrames; | 9 | nrFrames = nFrames; |
@@ -20,7 +20,4 @@ AnimatedImage :: AnimatedImage( QString file, int nFrames ) | |||
20 | 20 | ||
21 | SDL_SetColorKey(image, SDL_SRCCOLORKEY | SDL_RLEACCEL, SDL_MapRGB( image->format, 0, 0, 0 ) ); | 21 | SDL_SetColorKey(image, SDL_SRCCOLORKEY | SDL_RLEACCEL, SDL_MapRGB( image->format, 0, 0, 0 ) ); |
22 | //image = SDL_DisplayFormat( tmp ); | ||
23 | |||
24 | //SDL_FreeSurface( tmp ); | ||
25 | frameWidth = image->w/nrFrames; | 22 | frameWidth = image->w/nrFrames; |
26 | frameHeight = image->h; | 23 | frameHeight = image->h; |
@@ -48,4 +45,7 @@ bool AnimatedImage :: nextFrame() | |||
48 | void AnimatedImage :: draw( SDL_Surface *screen, int x, int y ) | 45 | void AnimatedImage :: draw( SDL_Surface *screen, int x, int y ) |
49 | { | 46 | { |
47 | if ( !image ) | ||
48 | return; | ||
49 | |||
50 | SDL_Rect dst; | 50 | SDL_Rect dst; |
51 | dst.x = currentFrame * frameWidth; | 51 | dst.x = currentFrame * frameWidth; |
diff --git a/noncore/games/sfcave-sdl/animatedimage.h b/noncore/games/sfcave-sdl/animatedimage.h index 1b38e6d..3c03f52 100644 --- a/noncore/games/sfcave-sdl/animatedimage.h +++ b/noncore/games/sfcave-sdl/animatedimage.h | |||
@@ -7,5 +7,5 @@ class AnimatedImage | |||
7 | { | 7 | { |
8 | public: | 8 | public: |
9 | AnimatedImage( QString file, int nFrames ); | 9 | AnimatedImage( string file, int nFrames ); |
10 | ~AnimatedImage(); | 10 | ~AnimatedImage(); |
11 | 11 | ||
diff --git a/noncore/games/sfcave-sdl/bfont.cpp b/noncore/games/sfcave-sdl/bfont.cpp index 0f29104..7dec8f5 100644 --- a/noncore/games/sfcave-sdl/bfont.cpp +++ b/noncore/games/sfcave-sdl/bfont.cpp | |||
@@ -74,8 +74,4 @@ void BFont::LoadFont (const char *filename) | |||
74 | } | 74 | } |
75 | } | 75 | } |
76 | else | ||
77 | { | ||
78 | cerr << "Error! The font has not been loaded!" << endl; | ||
79 | } | ||
80 | } | 76 | } |
81 | 77 | ||
@@ -114,5 +110,4 @@ BFont * BFont :: SetFontColor(Uint8 r, Uint8 g, Uint8 b) | |||
114 | color_key = xGetPixel(Surface, 0, Surface->h-1); | 110 | color_key = xGetPixel(Surface, 0, Surface->h-1); |
115 | 111 | ||
116 | printf("looking...\n"); | ||
117 | for( x=0; x < Surface->w; x++) { | 112 | for( x=0; x < Surface->w; x++) { |
118 | for( y=0; y < Surface->h; y++) { | 113 | for( y=0; y < Surface->h; y++) { |
@@ -132,5 +127,5 @@ BFont * BFont :: SetFontColor(Uint8 r, Uint8 g, Uint8 b) | |||
132 | } | 127 | } |
133 | } | 128 | } |
134 | printf("unlooking...\n"); | 129 | |
135 | if (SDL_MUSTLOCK(surface)) SDL_UnlockSurface(surface); | 130 | if (SDL_MUSTLOCK(surface)) SDL_UnlockSurface(surface); |
136 | if (SDL_MUSTLOCK(Surface)) SDL_UnlockSurface(Surface); | 131 | if (SDL_MUSTLOCK(Surface)) SDL_UnlockSurface(Surface); |
diff --git a/noncore/games/sfcave-sdl/constants.h b/noncore/games/sfcave-sdl/constants.h index 8fadae4..f10764e 100644 --- a/noncore/games/sfcave-sdl/constants.h +++ b/noncore/games/sfcave-sdl/constants.h | |||
@@ -4,5 +4,4 @@ | |||
4 | #include <string> | 4 | #include <string> |
5 | using namespace std; | 5 | using namespace std; |
6 | #define QString string | ||
7 | 6 | ||
8 | #ifdef QWS | 7 | #ifdef QWS |
@@ -56,12 +55,30 @@ using namespace std; | |||
56 | #define MENU_DIFFICULTY_NORMAL17 | 55 | #define MENU_DIFFICULTY_NORMAL17 |
57 | #define MENU_DIFFICULTY_HARD18 | 56 | #define MENU_DIFFICULTY_HARD18 |
58 | #define MENU_SOUNDS 19 | 57 | #define MENU_DIFFICULTY_HARD18 |
59 | #define MENU_SOUND_ON 20 | 58 | #define MENU_DIFFICULTY_CUSTOM19 |
60 | #define MENU_SOUND_OFF 21 | 59 | #define MENU_SOUNDS 20 |
61 | #define MENU_MUSIC_ON 22 | 60 | #define MENU_SOUND_ON 21 |
62 | #define MENU_MUSIC_OFF 23 | 61 | #define MENU_SOUND_OFF 22 |
62 | #define MENU_MUSIC_ON 23 | ||
63 | #define MENU_MUSIC_OFF 24 | ||
64 | #define MENU_CUSTOM_THRUST 25 | ||
65 | #define MENU_CUSTOM_GRAVITY 26 | ||
66 | #define MENU_CUSTOM_MAXSPEEDUP 27 | ||
67 | #define MENU_CUSTOM_MAXSPEEDDOWN 28 | ||
68 | #define MENU_CUSTOM_INCREASE 29 | ||
69 | #define MENU_CUSTOM_DECREASE 30 | ||
70 | #define MENU_CUSTOM_SAVE 31 | ||
71 | #define MENU_CUSTOM_CANCEL 32 | ||
63 | 72 | ||
64 | // Sounds | 73 | // Sounds |
65 | #define SND_EXPLOSION 0 | 74 | #define SND_EXPLOSION 0 |
66 | #define SND_THRUST 1 | 75 | #define SND_THRUST 1 |
76 | #define INGAME_MUSIC SOUND_PATH "ingame.mod" | ||
77 | |||
78 | // Constants for player values | ||
79 | #define PLAYER_THRUST 0 | ||
80 | #define PLAYER_GRAVITY 1 | ||
81 | #define PLAYER_MAX_SPEED_UP 2 | ||
82 | #define PLAYER_MAX_SPEED_DOWN 3 | ||
83 | |||
67 | #endif | 84 | #endif |
diff --git a/noncore/games/sfcave-sdl/fly_game.cpp b/noncore/games/sfcave-sdl/fly_game.cpp index f5ab401..7605c3f 100644 --- a/noncore/games/sfcave-sdl/fly_game.cpp +++ b/noncore/games/sfcave-sdl/fly_game.cpp | |||
@@ -18,4 +18,5 @@ FlyGame :: FlyGame( SFCave *p, int w, int h, int diff ) | |||
18 | FlyGame :: ~FlyGame() | 18 | FlyGame :: ~FlyGame() |
19 | { | 19 | { |
20 | // terrain and player get deleted by parent class | ||
20 | } | 21 | } |
21 | 22 | ||
@@ -35,4 +36,13 @@ void FlyGame :: init() | |||
35 | player->setMovementInfo( 0.4, 0.6, 4, 5 ); | 36 | player->setMovementInfo( 0.4, 0.6, 4, 5 ); |
36 | break; | 37 | break; |
38 | case MENU_DIFFICULTY_CUSTOM: | ||
39 | { | ||
40 | double thrust = parent->loadDoubleSetting( "Fly_custom_player_thrust", 0.3 ); | ||
41 | double gravity = parent->loadDoubleSetting( "Fly_custom_player_gravity", 0.2 ); | ||
42 | double maxUp = parent->loadDoubleSetting( "Fly_custom_player_maxupspeed", 1.5 ); | ||
43 | double maxDown = parent->loadDoubleSetting( "Fly_custom_player_maxdownspeed", 1.5 ); | ||
44 | player->setMovementInfo( thrust, gravity, maxUp, maxDown ); | ||
45 | break; | ||
46 | } | ||
37 | } | 47 | } |
38 | 48 | ||
@@ -51,5 +61,5 @@ void FlyGame :: update( int state ) | |||
51 | int diff = terrain->getMapBottom( 10 ) - player->getY(); | 61 | int diff = terrain->getMapBottom( 10 ) - player->getY(); |
52 | int tmpScore = ((FlyTerrain *)terrain)->getScore( 1, diff ); | 62 | int tmpScore = ((FlyTerrain *)terrain)->getScore( 1, diff ); |
53 | // printf( "diff - %d score - %d\n", diff, tmpScore ); | 63 | |
54 | if ( !startScoring ) | 64 | if ( !startScoring ) |
55 | { | 65 | { |
@@ -70,5 +80,4 @@ void FlyGame :: update( int state ) | |||
70 | if ( checkCollisions() ) | 80 | if ( checkCollisions() ) |
71 | { | 81 | { |
72 | // printf( "Crashed!\n" ); | ||
73 | parent->changeState( STATE_CRASHING ); | 82 | parent->changeState( STATE_CRASHING ); |
74 | return; | 83 | return; |
diff --git a/noncore/games/sfcave-sdl/font.cpp b/noncore/games/sfcave-sdl/font.cpp index 2976d48..1988252 100644 --- a/noncore/games/sfcave-sdl/font.cpp +++ b/noncore/games/sfcave-sdl/font.cpp | |||
@@ -9,5 +9,5 @@ BFont *FontHandler :: colouredFont; | |||
9 | BFont *FontHandler :: helpFont; | 9 | BFont *FontHandler :: helpFont; |
10 | 10 | ||
11 | void FontHandler :: init() | 11 | bool FontHandler :: init() |
12 | { | 12 | { |
13 | // Load font images | 13 | // Load font images |
@@ -18,13 +18,25 @@ void FontHandler :: init() | |||
18 | helpFont = new BFont( IMAGES_PATH "help_font.bmp" ); | 18 | helpFont = new BFont( IMAGES_PATH "help_font.bmp" ); |
19 | colouredFont = 0; | 19 | colouredFont = 0; |
20 | |||
21 | // Check if we are installed correctly (we need fonts to function) | ||
22 | if ( menuSelFont == 0 || menuUnSelFont == 0 || whiteFont == 0 || helpFont == 0 ) | ||
23 | { | ||
24 | printf( "One or more fonts are not installed correctly\n" ); | ||
25 | return false; | ||
26 | } | ||
27 | |||
28 | return true; | ||
20 | } | 29 | } |
21 | 30 | ||
22 | void FontHandler :: cleanUp() | 31 | void FontHandler :: cleanUp() |
23 | { | 32 | { |
33 | if ( menuSelFont ) | ||
24 | delete menuSelFont; | 34 | delete menuSelFont; |
35 | if ( menuUnSelFont ) | ||
25 | delete menuUnSelFont; | 36 | delete menuUnSelFont; |
37 | if ( whiteFont ) | ||
26 | delete whiteFont; | 38 | delete whiteFont; |
39 | if ( helpFont ) | ||
27 | delete helpFont; | 40 | delete helpFont; |
28 | |||
29 | if ( colouredFont ) | 41 | if ( colouredFont ) |
30 | delete colouredFont; | 42 | delete colouredFont; |
diff --git a/noncore/games/sfcave-sdl/font.h b/noncore/games/sfcave-sdl/font.h index e5bb707..5f0674a 100644 --- a/noncore/games/sfcave-sdl/font.h +++ b/noncore/games/sfcave-sdl/font.h | |||
@@ -14,5 +14,5 @@ class FontHandler | |||
14 | { | 14 | { |
15 | public: | 15 | public: |
16 | static void init(); | 16 | static bool init(); |
17 | static void cleanUp(); | 17 | static void cleanUp(); |
18 | 18 | ||
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 | |||
@@ -77,7 +77,4 @@ void Game :: handleKeys( SDL_KeyboardEvent &key ) | |||
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 |
@@ -87,9 +84,4 @@ void Game :: handleKeys( SDL_KeyboardEvent &key ) | |||
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 | } |
@@ -98,7 +90,7 @@ void Game :: handleKeys( SDL_KeyboardEvent &key ) | |||
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 ) |
@@ -108,4 +100,6 @@ QString Game :: getGameDifficultyText() | |||
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; |
@@ -120,4 +114,14 @@ void Game :: setDifficulty( string diff ) | |||
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 | ||
@@ -167,12 +171,11 @@ 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; |
@@ -224,5 +227,5 @@ void Game :: setSeed( int seed ) | |||
224 | } | 227 | } |
225 | 228 | ||
226 | void Game :: saveReplay( QString file ) | 229 | void Game :: saveReplay( string file ) |
227 | { | 230 | { |
228 | FILE *out; | 231 | FILE *out; |
@@ -237,5 +240,5 @@ void Game :: saveReplay( QString file ) | |||
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 ); |
@@ -252,5 +255,5 @@ void Game :: saveReplay( QString file ) | |||
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; |
@@ -260,10 +263,7 @@ void Game :: saveReplay( QString file ) | |||
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 | ||
@@ -286,7 +286,6 @@ void Game :: loadReplay( QString file ) | |||
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 ); |
@@ -309,7 +308,4 @@ void Game :: loadReplay( QString file ) | |||
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 | ||
diff --git a/noncore/games/sfcave-sdl/game.h b/noncore/games/sfcave-sdl/game.h index 56fa6a1..087f848 100644 --- a/noncore/games/sfcave-sdl/game.h +++ b/noncore/games/sfcave-sdl/game.h | |||
@@ -26,8 +26,8 @@ public: | |||
26 | 26 | ||
27 | void handleKeys( SDL_KeyboardEvent &key ); | 27 | void handleKeys( SDL_KeyboardEvent &key ); |
28 | QString getGameName() { return gameName; } | 28 | string getGameName() { return gameName; } |
29 | int getDifficulty() { return difficulty; } | 29 | int getDifficulty() { return difficulty; } |
30 | QString getGameDifficultyText(); | 30 | string getGameDifficultyText(); |
31 | void setDifficulty( int diff ) { difficulty = diff; } | 31 | void setDifficulty( int diff ); |
32 | void setDifficulty( string diff ); | 32 | void setDifficulty( string diff ); |
33 | 33 | ||
@@ -40,13 +40,14 @@ public: | |||
40 | 40 | ||
41 | Terrain *getTerrain() { return terrain; } | 41 | Terrain *getTerrain() { return terrain; } |
42 | Player *getPlayer() { return player; } | ||
42 | 43 | ||
43 | void setSeed( int seed ); | 44 | void setSeed( int seed ); |
44 | void loadReplay( QString file ); | 45 | void loadReplay( string file ); |
45 | void saveReplay( QString file ); | 46 | void saveReplay( string file ); |
46 | 47 | ||
47 | static Game *createGame( SFCave *p, int w, int h, string game, string difficulty ); | 48 | static Game *createGame( SFCave *p, int w, int h, string game, string difficulty ); |
48 | 49 | ||
49 | protected: | 50 | protected: |
50 | QString gameName; | 51 | string gameName; |
51 | 52 | ||
52 | int thrustChannel; | 53 | int thrustChannel; |
@@ -70,10 +71,8 @@ protected: | |||
70 | int currentSeed; | 71 | int currentSeed; |
71 | 72 | ||
72 | // QListIterator<int> *replayIt; | ||
73 | list<int> replayList; | 73 | list<int> replayList; |
74 | list<int>::iterator replayIt; | 74 | list<int>::iterator replayIt; |
75 | //QList<int> replayList; | ||
76 | bool replay; | 75 | bool replay; |
77 | QString replayFile; | 76 | string replayFile; |
78 | 77 | ||
79 | private: | 78 | private: |
diff --git a/noncore/games/sfcave-sdl/gates_game.cpp b/noncore/games/sfcave-sdl/gates_game.cpp index 1a9bc89..762801d 100644 --- a/noncore/games/sfcave-sdl/gates_game.cpp +++ b/noncore/games/sfcave-sdl/gates_game.cpp | |||
@@ -19,4 +19,5 @@ GatesGame :: GatesGame( SFCave *p, int w, int h, int diff ) | |||
19 | GatesGame :: ~GatesGame() | 19 | GatesGame :: ~GatesGame() |
20 | { | 20 | { |
21 | // terrain and player get deleted by parent class | ||
21 | } | 22 | } |
22 | 23 | ||
@@ -47,4 +48,17 @@ void GatesGame :: init() | |||
47 | player->setMovementInfo( 0.6, 0.8, 6, 7 ); | 48 | player->setMovementInfo( 0.6, 0.8, 6, 7 ); |
48 | break; | 49 | break; |
50 | case MENU_DIFFICULTY_CUSTOM: | ||
51 | { | ||
52 | // Read custom difficulty settings for this game | ||
53 | gapHeight = parent->loadIntSetting( "Gates_custom_gapHeight", 75 ); | ||
54 | |||
55 | double thrust = parent->loadDoubleSetting( "Gates_custom_player_thrust", 0.4 ); | ||
56 | double gravity = parent->loadDoubleSetting( "Gates_custom_player_gravity", 0.6 ); | ||
57 | double maxUp = parent->loadDoubleSetting( "Gates_custom_player_maxupspeed", 4.0 ); | ||
58 | double maxDown = parent->loadDoubleSetting( "Gates_custom_player_maxdownspeed", 5.0 ); | ||
59 | player->setMovementInfo( thrust, gravity, maxUp, maxDown ); | ||
60 | |||
61 | break; | ||
62 | } | ||
49 | } | 63 | } |
50 | 64 | ||
@@ -78,5 +92,4 @@ void GatesGame :: update( int state ) | |||
78 | if ( checkCollisions() ) | 92 | if ( checkCollisions() ) |
79 | { | 93 | { |
80 | // printf( "Crashed!\n" ); | ||
81 | parent->changeState( STATE_CRASHING ); | 94 | parent->changeState( STATE_CRASHING ); |
82 | return; | 95 | return; |
diff --git a/noncore/games/sfcave-sdl/help.cpp b/noncore/games/sfcave-sdl/help.cpp index 91c62da..f1728f6 100644 --- a/noncore/games/sfcave-sdl/help.cpp +++ b/noncore/games/sfcave-sdl/help.cpp | |||
@@ -58,5 +58,4 @@ void Help :: draw( SDL_Surface *screen ) | |||
58 | stars->draw( screen ); | 58 | stars->draw( screen ); |
59 | 59 | ||
60 | |||
61 | list<string>::iterator it = textList.begin(); | 60 | list<string>::iterator it = textList.begin(); |
62 | 61 | ||
diff --git a/noncore/games/sfcave-sdl/menu.cpp b/noncore/games/sfcave-sdl/menu.cpp index 0a7366f..a4a4216 100644 --- a/noncore/games/sfcave-sdl/menu.cpp +++ b/noncore/games/sfcave-sdl/menu.cpp | |||
@@ -9,5 +9,5 @@ | |||
9 | #include "starfield.h" | 9 | #include "starfield.h" |
10 | 10 | ||
11 | MenuOption :: MenuOption( QString text, int id ) | 11 | MenuOption :: MenuOption( string text, int id ) |
12 | { | 12 | { |
13 | menuText = text; | 13 | menuText = text; |
@@ -116,4 +116,5 @@ Menu :: Menu( SFCave *p ) | |||
116 | 116 | ||
117 | // Game Difficulty menu | 117 | // Game Difficulty menu |
118 | MenuOption *customMenu = 0; | ||
118 | Menu *gameDifficulty = new Menu( options ); | 119 | Menu *gameDifficulty = new Menu( options ); |
119 | item = gameDifficulty->addMenuOption( "Easy", MENU_DIFFICULTY_EASY ); | 120 | item = gameDifficulty->addMenuOption( "Easy", MENU_DIFFICULTY_EASY ); |
@@ -123,4 +124,5 @@ Menu :: Menu( SFCave *p ) | |||
123 | item = gameDifficulty->addMenuOption( "Hard", MENU_DIFFICULTY_HARD ); | 124 | item = gameDifficulty->addMenuOption( "Hard", MENU_DIFFICULTY_HARD ); |
124 | item->setNextMenu( options, false ); | 125 | item->setNextMenu( options, false ); |
126 | customMenu = gameDifficulty->addMenuOption( "Custom", MENU_DIFFICULTY_CUSTOM ); | ||
125 | item = gameDifficulty->addMenuOption( "Back", MENU_BACK ); | 127 | item = gameDifficulty->addMenuOption( "Back", MENU_BACK ); |
126 | item->setNextMenu( options, false ); | 128 | item->setNextMenu( options, false ); |
@@ -137,4 +139,27 @@ Menu :: Menu( SFCave *p ) | |||
137 | soundsMenu->setNextMenu( sounds ); | 139 | soundsMenu->setNextMenu( sounds ); |
138 | 140 | ||
141 | // Custom Menu | ||
142 | Menu *custom = new Menu( gameDifficulty ); | ||
143 | Menu *updown = new Menu( custom ); | ||
144 | item = custom->addMenuOption( "Thrust", MENU_CUSTOM_THRUST ); | ||
145 | item->setNextMenu( updown ); | ||
146 | item = custom->addMenuOption( "Gravity", MENU_CUSTOM_GRAVITY ); | ||
147 | item->setNextMenu( updown ); | ||
148 | item = custom->addMenuOption( "Max Speed Up", MENU_CUSTOM_MAXSPEEDUP ); | ||
149 | item->setNextMenu( updown ); | ||
150 | item = custom->addMenuOption( "Max Speed Down", MENU_CUSTOM_MAXSPEEDDOWN ); | ||
151 | item->setNextMenu( updown ); | ||
152 | item = custom->addMenuOption( "Back", MENU_BACK ); | ||
153 | item->setNextMenu( gameDifficulty, false ); | ||
154 | customMenu->setNextMenu( custom ); | ||
155 | |||
156 | // Up down menu | ||
157 | item = updown->addMenuOption( "Increase", MENU_CUSTOM_INCREASE ); | ||
158 | item = updown->addMenuOption( "Decrease", MENU_CUSTOM_DECREASE ); | ||
159 | item = updown->addMenuOption( "Save", MENU_CUSTOM_SAVE ); | ||
160 | item->setNextMenu( custom, false ); | ||
161 | item = updown->addMenuOption( "Cancel", MENU_CUSTOM_CANCEL ); | ||
162 | item->setNextMenu( custom, false ); | ||
163 | |||
139 | // Set static variables for menu selection up | 164 | // Set static variables for menu selection up |
140 | mainMenu = this; | 165 | mainMenu = this; |
@@ -216,5 +241,4 @@ int Menu :: handleKeys( SDL_KeyboardEvent &key ) | |||
216 | return -1; | 241 | return -1; |
217 | 242 | ||
218 | statusText = ""; | ||
219 | switch( key.keysym.sym ) | 243 | switch( key.keysym.sym ) |
220 | { | 244 | { |
@@ -277,6 +301,6 @@ int Menu :: handleKeys( SDL_KeyboardEvent &key ) | |||
277 | if ( currentMenu->parentMenu != 0 ) | 301 | if ( currentMenu->parentMenu != 0 ) |
278 | { | 302 | { |
303 | statusText = ""; | ||
279 | currentMenu = currentMenu->parentMenu; | 304 | currentMenu = currentMenu->parentMenu; |
280 | printf( "HERE\n" ); | ||
281 | 305 | ||
282 | return -1; | 306 | return -1; |
@@ -287,7 +311,9 @@ int Menu :: handleKeys( SDL_KeyboardEvent &key ) | |||
287 | case SDLK_SPACE: | 311 | case SDLK_SPACE: |
288 | { | 312 | { |
313 | statusText = ""; | ||
289 | // select menu item | 314 | // select menu item |
290 | int id = currentMenu->currentMenuOption->getMenuId(); | 315 | int id = currentMenu->currentMenuOption->getMenuId(); |
291 | // // if the current item has a child menu then move to that menu | 316 | |
317 | // if the current item has a child menu then move to that menu | ||
292 | Menu *next = currentMenu->currentMenuOption->getNextMenu(); | 318 | Menu *next = currentMenu->currentMenuOption->getNextMenu(); |
293 | if ( next != 0 ) | 319 | if ( next != 0 ) |
@@ -297,10 +323,7 @@ int Menu :: handleKeys( SDL_KeyboardEvent &key ) | |||
297 | if ( down ) | 323 | if ( down ) |
298 | initCurrentMenu(); | 324 | initCurrentMenu(); |
299 | // return -1; | ||
300 | } | 325 | } |
301 | // else | 326 | |
302 | { | ||
303 | return id; | 327 | return id; |
304 | } | ||
305 | 328 | ||
306 | break; | 329 | break; |
@@ -314,5 +337,5 @@ int Menu :: handleKeys( SDL_KeyboardEvent &key ) | |||
314 | } | 337 | } |
315 | 338 | ||
316 | MenuOption *Menu :: addMenuOption( QString text, int id ) | 339 | MenuOption *Menu :: addMenuOption( string text, int id ) |
317 | { | 340 | { |
318 | MenuOption *item = new MenuOption( text, id ); | 341 | MenuOption *item = new MenuOption( text, id ); |
diff --git a/noncore/games/sfcave-sdl/menu.h b/noncore/games/sfcave-sdl/menu.h index 08f7528..6a5ef40 100644 --- a/noncore/games/sfcave-sdl/menu.h +++ b/noncore/games/sfcave-sdl/menu.h | |||
@@ -14,5 +14,5 @@ class MenuOption | |||
14 | { | 14 | { |
15 | public: | 15 | public: |
16 | MenuOption( QString text, int id ); | 16 | MenuOption( string text, int id ); |
17 | ~MenuOption(); | 17 | ~MenuOption(); |
18 | 18 | ||
@@ -26,5 +26,5 @@ public: | |||
26 | private: | 26 | private: |
27 | int menuId; | 27 | int menuId; |
28 | QString menuText; | 28 | string menuText; |
29 | bool highlighted; | 29 | bool highlighted; |
30 | bool downMenuTree; | 30 | bool downMenuTree; |
@@ -41,9 +41,9 @@ public: | |||
41 | void draw( SDL_Surface *screen ); | 41 | void draw( SDL_Surface *screen ); |
42 | int handleKeys( SDL_KeyboardEvent & ); | 42 | int handleKeys( SDL_KeyboardEvent & ); |
43 | MenuOption *addMenuOption( QString text, int id ); | 43 | MenuOption *addMenuOption( string text, int id ); |
44 | void resetToTopMenu(); | 44 | void resetToTopMenu(); |
45 | void initCurrentMenu(); | 45 | void initCurrentMenu(); |
46 | 46 | ||
47 | void setStatusText( QString text ) { statusText = text; } | 47 | void setStatusText( string text ) { statusText = text; } |
48 | 48 | ||
49 | protected: | 49 | protected: |
@@ -59,5 +59,5 @@ private: | |||
59 | StarField *stars; | 59 | StarField *stars; |
60 | 60 | ||
61 | QString statusText; | 61 | string statusText; |
62 | 62 | ||
63 | SFCave *parent; | 63 | SFCave *parent; |
diff --git a/noncore/games/sfcave-sdl/player.cpp b/noncore/games/sfcave-sdl/player.cpp index 830ee78..2d52ae2 100644 --- a/noncore/games/sfcave-sdl/player.cpp +++ b/noncore/games/sfcave-sdl/player.cpp | |||
@@ -12,6 +12,6 @@ Player :: Player( int w, int h ) | |||
12 | sHeight = h; | 12 | sHeight = h; |
13 | 13 | ||
14 | thrustUp = 0.4; | 14 | thrust = 0.4; |
15 | thrustDown = 0.6; | 15 | gravity = 0.6; |
16 | maxUpSpeed = 4.0; | 16 | maxUpSpeed = 4.0; |
17 | maxDownSpeed = 5.0; | 17 | maxDownSpeed = 5.0; |
@@ -81,8 +81,5 @@ void Player :: drawTrails( SDL_Surface *screen ) | |||
81 | if ( trail[i].x() >= 0 ) | 81 | if ( trail[i].x() >= 0 ) |
82 | { | 82 | { |
83 | // int r = (int) ((255.0/pos.x()) * (trail[i].x)); | ||
84 | // int g = (int) ((150.0/pos.x()) * (trail[i].x)); | ||
85 | int c = (int)((150.0/50) * (50.0 - (pos.x() - trail[i].x() ) )); | 83 | int c = (int)((150.0/50) * (50.0 - (pos.x() - trail[i].x() ) )); |
86 | // SDL_FillRect( screen, &trail[i], SDL_MapRGBA( screen->format, r, g, 0, 0 ) ); //(int)(1.5*c), 0, 255 ) ); | ||
87 | boxRGBA( screen, trail[i].x(), trail[i].y(), trail[i].x() + 2, trail[i].y() + 2, 255, (int)(1.5*c), 0, c ); | 84 | boxRGBA( screen, trail[i].x(), trail[i].y(), trail[i].x() + 2, trail[i].y() + 2, 255, (int)(1.5*c), 0, c ); |
88 | } | 85 | } |
@@ -96,14 +93,14 @@ void Player :: move( bool up ) | |||
96 | 93 | ||
97 | if ( up ) | 94 | if ( up ) |
98 | thrust -= thrustUp; | 95 | currentThrust -= thrust; |
99 | else | 96 | else |
100 | thrust += thrustDown; | 97 | currentThrust += gravity; |
101 | 98 | ||
102 | if ( thrust > maxDownSpeed ) | 99 | if ( currentThrust > maxDownSpeed ) |
103 | thrust = maxDownSpeed; | 100 | currentThrust = maxDownSpeed; |
104 | else if ( thrust < -maxUpSpeed ) | 101 | else if ( currentThrust < -maxUpSpeed ) |
105 | thrust = -maxUpSpeed; | 102 | currentThrust = -maxUpSpeed; |
106 | 103 | ||
107 | pos.moveBy( 0, (int)(thrust) ); | 104 | pos.moveBy( 0, (int)(currentThrust) ); |
108 | } | 105 | } |
109 | 106 | ||
@@ -153,10 +150,135 @@ bool Player :: updateCrashing() | |||
153 | } | 150 | } |
154 | 151 | ||
155 | void Player :: setMovementInfo( double up, double down, double maxUp, double maxDown ) | 152 | void Player :: setMovementInfo( double up, double grav, double maxUp, double maxDown ) |
156 | { | 153 | { |
157 | thrustUp = up; | 154 | thrust = up; |
158 | thrustDown = down; | 155 | gravity = grav; |
159 | maxUpSpeed = maxUp; | 156 | maxUpSpeed = maxUp; |
160 | maxDownSpeed = maxDown; | 157 | maxDownSpeed = maxDown; |
161 | } | 158 | } |
162 | 159 | ||
160 | |||
161 | void Player :: incValue( int valueType ) | ||
162 | { | ||
163 | switch( valueType ) | ||
164 | { | ||
165 | case PLAYER_THRUST: | ||
166 | thrust += 0.1; | ||
167 | break; | ||
168 | case PLAYER_GRAVITY: | ||
169 | gravity += 0.1; | ||
170 | break; | ||
171 | case PLAYER_MAX_SPEED_UP: | ||
172 | maxUpSpeed += 0.1; | ||
173 | break; | ||
174 | case PLAYER_MAX_SPEED_DOWN: | ||
175 | maxDownSpeed += 0.1; | ||
176 | break; | ||
177 | } | ||
178 | } | ||
179 | |||
180 | void Player :: decValue( int valueType ) | ||
181 | { | ||
182 | switch( valueType ) | ||
183 | { | ||
184 | case PLAYER_THRUST: | ||
185 | thrust -= 0.1; | ||
186 | break; | ||
187 | case PLAYER_GRAVITY: | ||
188 | gravity -= 0.1; | ||
189 | break; | ||
190 | case PLAYER_MAX_SPEED_UP: | ||
191 | maxUpSpeed -= 0.1; | ||
192 | break; | ||
193 | case PLAYER_MAX_SPEED_DOWN: | ||
194 | maxDownSpeed -= 0.1; | ||
195 | break; | ||
196 | } | ||
197 | } | ||
198 | |||
199 | void Player :: setValue( int valueType, double val ) | ||
200 | { | ||
201 | switch( valueType ) | ||
202 | { | ||
203 | case PLAYER_THRUST: | ||
204 | thrust = val; | ||
205 | break; | ||
206 | case PLAYER_GRAVITY: | ||
207 | gravity = val; | ||
208 | break; | ||
209 | case PLAYER_MAX_SPEED_UP: | ||
210 | maxUpSpeed = val; | ||
211 | break; | ||
212 | case PLAYER_MAX_SPEED_DOWN: | ||
213 | maxDownSpeed = val; | ||
214 | break; | ||
215 | } | ||
216 | } | ||
217 | |||
218 | double Player :: getValue( int valueType ) | ||
219 | { | ||
220 | double val; | ||
221 | switch( valueType ) | ||
222 | { | ||
223 | case PLAYER_THRUST: | ||
224 | val = thrust; | ||
225 | break; | ||
226 | case PLAYER_GRAVITY: | ||
227 | val = gravity; | ||
228 | break; | ||
229 | case PLAYER_MAX_SPEED_UP: | ||
230 | val = maxUpSpeed; | ||
231 | break; | ||
232 | case PLAYER_MAX_SPEED_DOWN: | ||
233 | val = maxDownSpeed; | ||
234 | break; | ||
235 | } | ||
236 | |||
237 | return val; | ||
238 | } | ||
239 | |||
240 | string Player :: getValueTypeString( int valueType ) | ||
241 | { | ||
242 | string val; | ||
243 | switch( valueType ) | ||
244 | { | ||
245 | case PLAYER_THRUST: | ||
246 | val = "thrust"; | ||
247 | break; | ||
248 | case PLAYER_GRAVITY: | ||
249 | val = "gravity"; | ||
250 | break; | ||
251 | case PLAYER_MAX_SPEED_UP: | ||
252 | val = "maxupspeed"; | ||
253 | break; | ||
254 | case PLAYER_MAX_SPEED_DOWN: | ||
255 | val = "maxdownspeed"; | ||
256 | break; | ||
257 | } | ||
258 | |||
259 | return val; | ||
260 | } | ||
261 | |||
262 | string Player :: getValueString( int valueType ) | ||
263 | { | ||
264 | char val[50]; | ||
265 | switch( valueType ) | ||
266 | { | ||
267 | case PLAYER_THRUST: | ||
268 | sprintf( val, "Thrust - %lf", thrust ); | ||
269 | break; | ||
270 | case PLAYER_GRAVITY: | ||
271 | sprintf( val, "Gravity - %lf", gravity ); | ||
272 | break; | ||
273 | case PLAYER_MAX_SPEED_UP: | ||
274 | sprintf( val, "Max Speed Up - %lf", maxUpSpeed ); | ||
275 | break; | ||
276 | case PLAYER_MAX_SPEED_DOWN: | ||
277 | sprintf( val, "Max Speed Down - %lf", maxDownSpeed ); | ||
278 | break; | ||
279 | } | ||
280 | |||
281 | string ret = val; | ||
282 | return ret; | ||
283 | } | ||
284 | |||
diff --git a/noncore/games/sfcave-sdl/player.h b/noncore/games/sfcave-sdl/player.h index e4c904a..595c25b 100644 --- a/noncore/games/sfcave-sdl/player.h +++ b/noncore/games/sfcave-sdl/player.h | |||
@@ -23,5 +23,11 @@ public: | |||
23 | int getHeight() { return pos.h(); } | 23 | int getHeight() { return pos.h(); } |
24 | bool updateCrashing(); | 24 | bool updateCrashing(); |
25 | void setMovementInfo( double up, double down, double maxUp, double maxDown ); | 25 | void setMovementInfo( double up, double grav, double maxUp, double maxDown ); |
26 | void incValue( int valType ); | ||
27 | void decValue( int valType ); | ||
28 | double getValue( int valueType ); | ||
29 | string getValueString( int valueType ); | ||
30 | string getValueTypeString( int valueType ); | ||
31 | void setValue( int valueType, double val ); | ||
26 | 32 | ||
27 | private: | 33 | private: |
@@ -37,8 +43,8 @@ private: | |||
37 | int crashLineLength; | 43 | int crashLineLength; |
38 | Rect pos; | 44 | Rect pos; |
39 | double thrust; | 45 | double currentThrust; |
40 | 46 | ||
41 | double thrustUp; | 47 | double thrust; |
42 | double thrustDown; | 48 | double gravity; |
43 | double maxUpSpeed; | 49 | double maxUpSpeed; |
44 | double maxDownSpeed; | 50 | double maxDownSpeed; |
diff --git a/noncore/games/sfcave-sdl/settings.cpp b/noncore/games/sfcave-sdl/settings.cpp index 914c4ec..20cce4f 100644 --- a/noncore/games/sfcave-sdl/settings.cpp +++ b/noncore/games/sfcave-sdl/settings.cpp | |||
@@ -6,4 +6,6 @@ | |||
6 | #include "settings.h" | 6 | #include "settings.h" |
7 | 7 | ||
8 | // Defined in util.h | ||
9 | string getHomeDir(); | ||
8 | 10 | ||
9 | #define DEFAULT_DIR "." | 11 | #define DEFAULT_DIR "." |
@@ -17,13 +19,6 @@ Settings::Settings( char * env_file, char * env_dir ) | |||
17 | if (env_dir == NULL) | 19 | if (env_dir == NULL) |
18 | { | 20 | { |
19 | char * homeDir = getenv( "HOME" );; | 21 | envFile = getHomeDir(); |
20 | |||
21 | if ( homeDir ) | ||
22 | { | ||
23 | envFile.append(homeDir); | ||
24 | envFile.append("/"); | 22 | envFile.append("/"); |
25 | } | ||
26 | else | ||
27 | printf( "Environment var HOME not set!\n" ); | ||
28 | 23 | ||
29 | envFile.append(DEFAULT_DIR); | 24 | envFile.append(DEFAULT_DIR); |
@@ -43,13 +38,6 @@ Settings::Settings( char * env_file, char * env_dir ) | |||
43 | Settings::Settings() | 38 | Settings::Settings() |
44 | { | 39 | { |
45 | char * homeDir = getenv("HOME"); | 40 | envFile = getHomeDir(); |
46 | |||
47 | if ( homeDir) | ||
48 | { | ||
49 | envFile.append(homeDir); | ||
50 | envFile.append("/"); | 41 | envFile.append("/"); |
51 | } | ||
52 | else | ||
53 | printf( "Environment var HOME not set!\n" ); | ||
54 | 42 | ||
55 | envFile.append(DEFAULT_DIR); | 43 | envFile.append(DEFAULT_DIR); |
@@ -111,4 +99,16 @@ bool Settings::readSetting(const string key_str,unsigned long& result) | |||
111 | } | 99 | } |
112 | 100 | ||
101 | bool Settings::readSetting(const string key_str,double& result) | ||
102 | { | ||
103 | string Buffer; | ||
104 | if (readSetting(key_str,Buffer)) | ||
105 | { | ||
106 | result = atof( Buffer.c_str() ); | ||
107 | return true; | ||
108 | } | ||
109 | else | ||
110 | return false; | ||
111 | } | ||
112 | |||
113 | bool Settings::readSetting(const string key_str,bool& result) | 113 | bool Settings::readSetting(const string key_str,bool& result) |
114 | { | 114 | { |
@@ -160,4 +160,12 @@ void Settings::writeSetting(const string key_str,const bool value) | |||
160 | } | 160 | } |
161 | 161 | ||
162 | void Settings::writeSetting(const string key_str,const double value) | ||
163 | { | ||
164 | char Buffer[30]; | ||
165 | |||
166 | sprintf(Buffer,"%lf",value); | ||
167 | writeSetting(key_str,string(Buffer)); | ||
168 | } | ||
169 | |||
162 | void Settings::writeSetting(const string key_str,const int value) | 170 | void Settings::writeSetting(const string key_str,const int value) |
163 | { | 171 | { |
@@ -196,39 +204,32 @@ void Settings::writeSetting(const string key_str,const string value) | |||
196 | // This function will write a value for the key key_str. If the key_str | 204 | // This function will write a value for the key key_str. If the key_str |
197 | // already exists then it will be overwritten. | 205 | // already exists then it will be overwritten. |
198 | |||
199 | std::vector<string> FileEntries; | ||
200 | FILE *fd=NULL,*ftemp=NULL; | 206 | FILE *fd=NULL,*ftemp=NULL; |
201 | char * dir_str; | ||
202 | char * dir_ptr; | ||
203 | char buf[MAX_LINE_SIZE]; | 207 | char buf[MAX_LINE_SIZE]; |
204 | char tempname[12]; | ||
205 | |||
206 | dir_str = strdup(envFile.c_str()); | ||
207 | printf( "dir = %s, file - %s\n", dir_str, envFile.c_str() ); | ||
208 | if (dir_str) | ||
209 | { | ||
210 | // remove file from the directory string | ||
211 | dir_ptr = strrchr(dir_str, (int)'/'); | ||
212 | if (dir_ptr) | ||
213 | { | ||
214 | *dir_ptr = 0; | ||
215 | 208 | ||
216 | // make the directory path if it does not exist | 209 | string tmp = getHomeDir() + "/tmpsfcave.dat"; |
217 | // mkdir(dir_str, 777 ); | ||
218 | 210 | ||
219 | // if file exists we need to save contents | 211 | // if file exists we need to save contents |
220 | if ((fd = fopen(envFile.c_str(), "r")) != NULL) | 212 | fd = fopen( envFile.c_str(), "r" ); |
213 | ftemp = fopen( tmp.c_str(), "w" ); | ||
214 | if ( fd != NULL && ftemp != NULL ) | ||
221 | { | 215 | { |
222 | while (fgets(buf, MAX_LINE_SIZE-1, fd)) | 216 | while (fgets(buf, MAX_LINE_SIZE-1, fd)) |
223 | FileEntries.push_back(string(buf)); | 217 | { |
218 | if ( strncmp( buf, key_str.c_str(), key_str.size() ) != 0 ) | ||
219 | fprintf( ftemp, "%s", buf ); | ||
220 | } | ||
224 | fclose(fd); | 221 | fclose(fd); |
225 | } | 222 | } |
226 | 223 | ||
227 | char *home = getenv( "HOME" ); | 224 | if ( ftemp != NULL ) |
228 | string tmp; | 225 | { |
229 | if ( home ) | 226 | fprintf(ftemp, "%s\t%s\n", key_str.c_str(),value.c_str()); |
230 | tmp = home + string( "/" ) + "tmpsfcave.dat"; | 227 | fclose( ftemp ); |
231 | else | 228 | |
232 | tmp = "./tmpsfcave.dat"; | 229 | remove(envFile.c_str()); |
230 | rename( tmp.c_str(), envFile.c_str() ); | ||
231 | } | ||
232 | /* | ||
233 | string tmp = getHomeDir() + "/tmpsfcave.dat"; | ||
233 | strcpy(tempname,tmp.c_str() ); | 234 | strcpy(tempname,tmp.c_str() ); |
234 | printf( "tmp - %s\n", tempname ); | 235 | printf( "tmp - %s\n", tempname ); |
@@ -255,8 +256,4 @@ void Settings::writeSetting(const string key_str,const string value) | |||
255 | fflush(ftemp); | 256 | fflush(ftemp); |
256 | fclose(ftemp); | 257 | fclose(ftemp); |
257 | |||
258 | remove(envFile.c_str()); | ||
259 | |||
260 | rename( tempname, envFile.c_str() ); | ||
261 | } | 258 | } |
262 | else | 259 | else |
@@ -266,4 +263,5 @@ void Settings::writeSetting(const string key_str,const string value) | |||
266 | delete dir_str; | 263 | delete dir_str; |
267 | } | 264 | } |
265 | */ | ||
268 | } | 266 | } |
269 | 267 | ||
diff --git a/noncore/games/sfcave-sdl/settings.h b/noncore/games/sfcave-sdl/settings.h index 5e828ed..a3af999 100644 --- a/noncore/games/sfcave-sdl/settings.h +++ b/noncore/games/sfcave-sdl/settings.h | |||
@@ -33,4 +33,5 @@ public: | |||
33 | bool readSetting(const string key_str,long int& result); | 33 | bool readSetting(const string key_str,long int& result); |
34 | bool readSetting(const string key_str,unsigned long& result); | 34 | bool readSetting(const string key_str,unsigned long& result); |
35 | bool readSetting(const string key_str,double & result); | ||
35 | bool readSetting(const string key_str,bool& result); | 36 | bool readSetting(const string key_str,bool& result); |
36 | 37 | ||
@@ -40,4 +41,5 @@ public: | |||
40 | void writeSetting(const string key_str,const long int result); | 41 | void writeSetting(const string key_str,const long int result); |
41 | void writeSetting(const string key_str,const unsigned long result); | 42 | void writeSetting(const string key_str,const unsigned long result); |
43 | void writeSetting(const string key_str,const double value); | ||
42 | void writeSetting(const string key_str,const bool value); | 44 | void writeSetting(const string key_str,const bool value); |
43 | 45 | ||
diff --git a/noncore/games/sfcave-sdl/sfcave.cpp b/noncore/games/sfcave-sdl/sfcave.cpp index 8d376a1..dbd788c 100644 --- a/noncore/games/sfcave-sdl/sfcave.cpp +++ b/noncore/games/sfcave-sdl/sfcave.cpp | |||
@@ -27,7 +27,7 @@ | |||
27 | void start( int argc, char *argv[] ) | 27 | void start( int argc, char *argv[] ) |
28 | { | 28 | { |
29 | FontHandler::init(); | 29 | SFCave *app = new SFCave( argc, argv ); |
30 | SFCave app( argc, argv ); | 30 | app->mainEventLoop(); |
31 | FontHandler::cleanUp(); | 31 | delete app; |
32 | } | 32 | } |
33 | 33 | ||
@@ -44,33 +44,49 @@ int main(int argc, char *argv[]) | |||
44 | SFCave :: SFCave( int argc, char *argv[] ) | 44 | SFCave :: SFCave( int argc, char *argv[] ) |
45 | { | 45 | { |
46 | setupOK = false; | ||
47 | |||
48 | // Load settings | ||
46 | string diff = loadSetting( "GameDifficulty", "Easy" ); | 49 | string diff = loadSetting( "GameDifficulty", "Easy" ); |
47 | string game = loadSetting( "GameType", "SFCave" ); | 50 | string game = loadSetting( "GameType", "SFCave" ); |
48 | musicPath = loadSetting( "MusicPath", SOUND_PATH ); | 51 | musicPath = loadSetting( "MusicPath", SOUND_PATH ); |
49 | printf( "musicPath %s\n", musicPath.c_str() ); | ||
50 | musicType = loadSetting( "MusicType", "mod,ogg" ); | 52 | musicType = loadSetting( "MusicType", "mod,ogg" ); |
53 | bool soundOn = loadBoolSetting( "SoundOn", true ); | ||
54 | bool musicOn = loadBoolSetting( "MusicOn", true ); | ||
51 | if ( musicPath[musicPath.size()-1] != '/' ) | 55 | if ( musicPath[musicPath.size()-1] != '/' ) |
52 | musicPath += "/"; | 56 | musicPath += "/"; |
57 | printf( "musicPath %s\n", musicPath.c_str() ); | ||
53 | 58 | ||
54 | // Init main SDL Library | 59 | // Init main SDL Library |
55 | initSDL( argc, argv ); | 60 | initSDL( argc, argv ); |
56 | 61 | ||
62 | // Init font handler | ||
63 | if ( !FontHandler::init() ) | ||
64 | { | ||
65 | printf( "Unable to initialise fonts!\n" ); | ||
66 | return; | ||
67 | } | ||
68 | |||
57 | // Init SoundHandler | 69 | // Init SoundHandler |
58 | if ( !SoundHandler :: init() ) | 70 | if ( !SoundHandler :: init() ) |
59 | printf("Unable to open audio!\n"); | 71 | printf("Unable to open audio!\n"); |
60 | 72 | ||
73 | SoundHandler :: setSoundsOn( soundOn ); | ||
74 | SoundHandler :: setMusicOn( musicOn ); | ||
75 | |||
61 | currentGame = Game::createGame( this, WIDTH, HEIGHT, game, diff ); | 76 | currentGame = Game::createGame( this, WIDTH, HEIGHT, game, diff ); |
62 | if ( !currentGame ) | 77 | if ( !currentGame ) |
63 | currentGame = new SFCaveGame( this, WIDTH, HEIGHT, 0 ); | 78 | currentGame = new SFCaveGame( this, WIDTH, HEIGHT, 0 ); |
64 | currentGame->setSeed(-1); | 79 | currentGame->setSeed(-1); |
80 | |||
81 | // Create menu | ||
65 | menu = new Menu( this ); | 82 | menu = new Menu( this ); |
66 | 83 | ||
84 | // Create help screen | ||
67 | help = new Help( this ); | 85 | help = new Help( this ); |
68 | 86 | ||
69 | maxFPS = 50; | 87 | maxFPS = 50; |
70 | showFps = false; | 88 | showFps = false; |
71 | mainEventLoop(); | ||
72 | 89 | ||
73 | SoundHandler :: cleanUp(); | 90 | setupOK = true; |
74 | SDL_Quit(); | ||
75 | } | 91 | } |
76 | 92 | ||
@@ -83,14 +99,15 @@ SFCave :: ~SFCave() | |||
83 | delete menu; | 99 | delete menu; |
84 | 100 | ||
85 | SDL_FreeSurface( screen ); | 101 | if ( help ) |
86 | } | 102 | delete help; |
87 | |||
88 | 103 | ||
89 | void SFCave :: drawGameScreen( ) | 104 | SDL_FreeSurface( screen ); |
90 | { | 105 | FontHandler::cleanUp(); |
91 | //ClearScreen(screen, "Titletext"); | 106 | SoundHandler :: cleanUp(); |
92 | 107 | ||
108 | SDL_Quit(); | ||
93 | } | 109 | } |
94 | 110 | ||
111 | |||
95 | void SFCave :: initSDL( int argc, char *argv[] ) | 112 | void SFCave :: initSDL( int argc, char *argv[] ) |
96 | { | 113 | { |
@@ -99,35 +116,38 @@ void SFCave :: initSDL( int argc, char *argv[] ) | |||
99 | Uint32 videoflags; | 116 | Uint32 videoflags; |
100 | 117 | ||
101 | 118 | // Initialize SDL | |
102 | |||
103 | /* Initialize SDL */ | ||
104 | if ( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0 ) { | 119 | if ( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0 ) { |
105 | fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); | 120 | fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); |
106 | exit(1); | 121 | exit(1); |
107 | } | 122 | } |
108 | atexit(SDL_Quit); | ||
109 | 123 | ||
110 | /* Alpha blending doesn't work well at 8-bit color */ | ||
111 | video_bpp = 16; | 124 | video_bpp = 16; |
112 | 125 | ||
113 | if ( !SDL_VideoModeOK(WIDTH, HEIGHT, 16, SDL_DOUBLEBUF) ) | 126 | if ( !SDL_VideoModeOK(WIDTH, HEIGHT, video_bpp, SDL_DOUBLEBUF) ) |
114 | printf( "No double buffering\n" ); | 127 | printf( "No double buffering\n" ); |
115 | 128 | ||
116 | videoflags = SDL_HWSURFACE | SDL_SRCALPHA;//|| SDL_DOUBLEBUF;// | SDL_SRCALPHA | SDL_RESIZABLE; | 129 | videoflags = SDL_HWSURFACE | SDL_SRCALPHA; |
117 | while ( argc > 1 ) { | 130 | while ( argc > 1 ) |
131 | { | ||
118 | --argc; | 132 | --argc; |
119 | if ( strcmp(argv[argc-1], "-bpp") == 0 ) { | 133 | if ( strcmp(argv[argc-1], "-bpp") == 0 ) |
134 | { | ||
120 | video_bpp = atoi(argv[argc]); | 135 | video_bpp = atoi(argv[argc]); |
121 | --argc; | 136 | --argc; |
122 | } else | 137 | } |
123 | if ( strcmp(argv[argc], "-hw") == 0 ) { | 138 | else if ( strcmp(argv[argc], "-hw") == 0 ) |
139 | { | ||
124 | videoflags |= SDL_HWSURFACE; | 140 | videoflags |= SDL_HWSURFACE; |
125 | } else | 141 | } |
126 | if ( strcmp(argv[argc], "-warp") == 0 ) { | 142 | else if ( strcmp(argv[argc], "-warp") == 0 ) |
143 | { | ||
127 | videoflags |= SDL_HWPALETTE; | 144 | videoflags |= SDL_HWPALETTE; |
128 | } else | 145 | } |
129 | if ( strcmp(argv[argc], "-fullscreen") == 0 ) { | 146 | else if ( strcmp(argv[argc], "-fullscreen") == 0 ) |
147 | { | ||
130 | videoflags |= SDL_FULLSCREEN; | 148 | videoflags |= SDL_FULLSCREEN; |
131 | } else { | 149 | } |
150 | else if ( strcmp(argv[argc], "-h") == 0 ) | ||
151 | { | ||
132 | fprintf(stderr, | 152 | fprintf(stderr, |
133 | "Usage: %s [-bpp N] [-warp] [-hw] [-fullscreen]\n", | 153 | "Usage: %s [-bpp N] [-warp] [-hw] [-fullscreen]\n", |
@@ -137,14 +157,15 @@ void SFCave :: initSDL( int argc, char *argv[] ) | |||
137 | } | 157 | } |
138 | 158 | ||
139 | /* Set 240x320 video mode */ | 159 | // Set 240x320 video mode |
140 | if ( (screen=SDL_SetVideoMode(WIDTH,HEIGHT,video_bpp,videoflags)) == NULL ) { | 160 | if ( (screen = SDL_SetVideoMode( WIDTH,HEIGHT,video_bpp,videoflags )) == NULL ) |
141 | fprintf(stderr, "Couldn't set %ix%i video mode: %s\n",WIDTH,HEIGHT,SDL_GetError()); | 161 | { |
162 | printf( "Couldn't set %ix%i video mode: %s\n",WIDTH,HEIGHT,SDL_GetError() ); | ||
142 | exit(2); | 163 | exit(2); |
143 | } | 164 | } |
144 | 165 | ||
145 | /* Use alpha blending */ | 166 | // Use alpha blending |
146 | SDL_SetAlpha(screen, SDL_RLEACCEL, 0); | 167 | //SDL_SetAlpha(screen, SDL_RLEACCEL, 0); |
147 | 168 | ||
148 | /* Set title for window */ | 169 | // Set title for window |
149 | SDL_WM_SetCaption("SFCave","SFCave"); | 170 | SDL_WM_SetCaption("SFCave","SFCave"); |
150 | } | 171 | } |
@@ -152,38 +173,41 @@ void SFCave :: initSDL( int argc, char *argv[] ) | |||
152 | void SFCave :: mainEventLoop() | 173 | void SFCave :: mainEventLoop() |
153 | { | 174 | { |
154 | SDL_Event event; | 175 | if ( !setupOK ) |
155 | int done; | 176 | return; |
156 | 177 | ||
157 | /* Wait for a keystroke */ | 178 | // Wait for a keystroke |
158 | done = 0; | 179 | finish = false; |
159 | state = 0; | 180 | state = 0; |
160 | state = STATE_CRASHED; | 181 | state = STATE_CRASHED; |
161 | changeState( STATE_MENU ); | 182 | changeState( STATE_MENU ); |
162 | 183 | ||
163 | int FPS = 0; | 184 | FPS = 0; |
164 | bool limitFPS = true; | ||
165 | actualFPS = 0; | 185 | actualFPS = 0; |
166 | long time1 = 0; | 186 | time1 = 0; |
167 | long start; | 187 | |
168 | long end; | 188 | limitFPS = true; |
169 | //long nrTimes = 0; | 189 | while ( !finish ) |
170 | struct timeb tp; | ||
171 | while ( !done ) | ||
172 | { | 190 | { |
173 | // calc FPS | 191 | // calc FPS |
174 | ftime( &tp ); | 192 | calcFPS(); |
175 | start =(tp.time%10000)*10000 + tp.millitm; | ||
176 | // printf( "start = %ld, time1 - %d, st-tm - %d, tp.time - %ld\n", start, time1, start-time1, (tp.time%1000)*1000 ); | ||
177 | if ( start - time1 >= 1000 ) | ||
178 | { | ||
179 | actualFPS = FPS; | ||
180 | // printf( "%d FPS = %d\n", nrTimes++, actualFPS ); | ||
181 | FPS = 0; | ||
182 | time1 = start; | ||
183 | } | ||
184 | else | ||
185 | FPS ++; | ||
186 | 193 | ||
187 | SDL_FillRect( screen, 0, 0 ); | 194 | SDL_FillRect( screen, 0, 0 ); |
195 | |||
196 | handleGameState( ); | ||
197 | |||
198 | SDL_Flip( screen ); | ||
199 | |||
200 | if ( limitFPS ) | ||
201 | FPSDelay(); | ||
202 | else | ||
203 | SDL_Delay( 5 ); | ||
204 | |||
205 | handleEvents(); | ||
206 | } | ||
207 | } | ||
208 | |||
209 | |||
210 | void SFCave :: handleGameState() | ||
211 | { | ||
188 | switch( state ) | 212 | switch( state ) |
189 | { | 213 | { |
@@ -198,5 +222,4 @@ void SFCave :: mainEventLoop() | |||
198 | break; | 222 | break; |
199 | case STATE_NEWGAME: | 223 | case STATE_NEWGAME: |
200 | printf( "STATE_NEWGAME\n" ); | ||
201 | currentGame->setReplay( false ); | 224 | currentGame->setReplay( false ); |
202 | currentGame->init(); | 225 | currentGame->init(); |
@@ -205,5 +228,4 @@ void SFCave :: mainEventLoop() | |||
205 | 228 | ||
206 | case STATE_REPLAY: | 229 | case STATE_REPLAY: |
207 | printf( "STATE_NEWGAME\n" ); | ||
208 | currentGame->setReplay( true ); | 230 | currentGame->setReplay( true ); |
209 | currentGame->init(); | 231 | currentGame->init(); |
@@ -213,47 +235,20 @@ void SFCave :: mainEventLoop() | |||
213 | case STATE_PLAYING: | 235 | case STATE_PLAYING: |
214 | case STATE_CRASHING: | 236 | case STATE_CRASHING: |
215 | currentGame->update( state ); | ||
216 | currentGame->draw( screen ); | ||
217 | break; | ||
218 | |||
219 | case STATE_CRASHED: | 237 | case STATE_CRASHED: |
220 | currentGame->update( state ); | 238 | currentGame->update( state ); |
221 | currentGame->draw( screen ); | 239 | currentGame->draw( screen ); |
222 | |||
223 | // Display Game Over message | ||
224 | break; | 240 | break; |
225 | 241 | ||
226 | case STATE_QUIT: | 242 | case STATE_QUIT: |
227 | done = 1; | 243 | finish = true; |
228 | break; | 244 | break; |
229 | } | 245 | } |
246 | } | ||
230 | 247 | ||
231 | /* Show */ | 248 | void SFCave :: handleEvents() |
232 | // if ( state != STATE_CRASHED ) | ||
233 | SDL_Flip( screen ); | ||
234 | // SDL_UpdateRect(screen, 0, 0, 0, 0); | ||
235 | |||
236 | if ( limitFPS ) | ||
237 | { | 249 | { |
238 | /* Slow down polling - limit to x FPS*/ | 250 | SDL_Event event; |
239 | ftime( &tp ); | ||
240 | end = abs((tp.time%10000)*10000 + tp.millitm); | ||
241 | if ( end-start < (1000/maxFPS) ) | ||
242 | { | ||
243 | // printf( "end - %ld, timetaken for frame = %ld, sleeping for %ld %d\n", end, end-start, (1000/maxFPS)-(end-start), actualFPS ); | ||
244 | if ( (1000/maxFPS)-(end-start) > 500 ) | ||
245 | { | ||
246 | // Should never happen but in case it does sleep for 5 seconds | ||
247 | printf( "WARNING WILL ROBINSON! delay = %ld - start %ld, end %ld\n", (1000/maxFPS)-(end-start), start, end ); | ||
248 | SDL_Delay( 5 ); | ||
249 | } | ||
250 | else | ||
251 | SDL_Delay((1000/maxFPS)-(end-start) ); | ||
252 | } | ||
253 | } | ||
254 | else | ||
255 | SDL_Delay( 5 ); | ||
256 | 251 | ||
257 | /* Check for events */ | 252 | // Check for events |
258 | while ( SDL_PollEvent(&event) ) | 253 | while ( SDL_PollEvent(&event) ) |
259 | { | 254 | { |
@@ -262,8 +257,11 @@ void SFCave :: mainEventLoop() | |||
262 | case SDL_KEYDOWN: | 257 | case SDL_KEYDOWN: |
263 | case SDL_KEYUP: | 258 | case SDL_KEYUP: |
259 | { | ||
264 | // Escape keypress quits the app | 260 | // Escape keypress quits the app |
265 | if ( event.key.keysym.sym != SDLK_ESCAPE ) | 261 | if ( event.key.keysym.sym == SDLK_ESCAPE ) |
266 | { | 262 | { |
267 | // printf( "Key Pressed was %d %s\n", event.key.keysym.sym, SDL_GetKeyName( event.key.keysym.sym ) ); | 263 | finish = true; |
264 | break; | ||
265 | } | ||
268 | 266 | ||
269 | if ( state == STATE_MENU ) | 267 | if ( state == STATE_MENU ) |
@@ -305,5 +303,4 @@ void SFCave :: mainEventLoop() | |||
305 | { | 303 | { |
306 | case SDLK_f: | 304 | case SDLK_f: |
307 | printf( "showFPS - %d\n", showFps ); | ||
308 | if ( event.type == SDL_KEYDOWN ) | 305 | if ( event.type == SDL_KEYDOWN ) |
309 | showFps = !showFps; | 306 | showFps = !showFps; |
@@ -314,24 +311,4 @@ void SFCave :: mainEventLoop() | |||
314 | break; | 311 | break; |
315 | 312 | ||
316 | case SDLK_p: | ||
317 | if ( event.type == SDL_KEYDOWN ) | ||
318 | { | ||
319 | maxFPS ++; | ||
320 | printf( "maxFPS - %d\n", maxFPS ); | ||
321 | } | ||
322 | break; | ||
323 | |||
324 | case SDLK_o: | ||
325 | if ( event.type == SDL_KEYDOWN ) | ||
326 | { | ||
327 | maxFPS --; | ||
328 | printf( "maxFPS - %d\n", maxFPS ); | ||
329 | } | ||
330 | break; | ||
331 | |||
332 | case SDLK_n: | ||
333 | currentGame->getTerrain()->offset++; | ||
334 | break; | ||
335 | |||
336 | default: | 313 | default: |
337 | currentGame->handleKeys( event.key ); | 314 | currentGame->handleKeys( event.key ); |
@@ -343,7 +320,6 @@ void SFCave :: mainEventLoop() | |||
343 | } | 320 | } |
344 | 321 | ||
345 | |||
346 | case SDL_QUIT: | 322 | case SDL_QUIT: |
347 | done = 1; | 323 | finish = true; |
348 | break; | 324 | break; |
349 | default: | 325 | default: |
@@ -352,5 +328,4 @@ void SFCave :: mainEventLoop() | |||
352 | } | 328 | } |
353 | } | 329 | } |
354 | } | ||
355 | 330 | ||
356 | void SFCave :: changeState( int s ) | 331 | void SFCave :: changeState( int s ) |
@@ -366,5 +341,4 @@ void SFCave :: changeState( int s ) | |||
366 | 341 | ||
367 | string musicFile = chooseRandomFile( musicPath, musicType ); | 342 | string musicFile = chooseRandomFile( musicPath, musicType ); |
368 | printf("playing music %s\n", musicFile.c_str() ); | ||
369 | SoundHandler :: setMusicVolume( 128 ); | 343 | SoundHandler :: setMusicVolume( 128 ); |
370 | SoundHandler :: playMusic( musicFile ); | 344 | SoundHandler :: playMusic( musicFile ); |
@@ -375,5 +349,5 @@ void SFCave :: changeState( int s ) | |||
375 | 349 | ||
376 | // Start the in game music | 350 | // Start the in game music |
377 | string musicFile = SOUND_PATH "ingame.mod"; | 351 | string musicFile = INGAME_MUSIC; |
378 | SoundHandler :: playMusic( musicFile ); | 352 | SoundHandler :: playMusic( musicFile ); |
379 | SoundHandler :: setMusicVolume( 25 ); | 353 | SoundHandler :: setMusicVolume( 25 ); |
@@ -409,10 +383,5 @@ void SFCave :: handleMenuSelect( int menuId ) | |||
409 | case MENU_LOAD_REPLAY: | 383 | case MENU_LOAD_REPLAY: |
410 | { | 384 | { |
411 | #ifdef QWS | 385 | string replayFile = getHomeDir() + "/" + currentGame->getGameName() + ".replay"; |
412 | QString replayFile = getenv( "HOME" ); | ||
413 | #else | ||
414 | QString replayFile = "."; | ||
415 | #endif | ||
416 | replayFile += string( "/" ) + currentGame->getGameName() + ".replay"; | ||
417 | 386 | ||
418 | currentGame->loadReplay( replayFile ); | 387 | currentGame->loadReplay( replayFile ); |
@@ -426,10 +395,5 @@ void SFCave :: handleMenuSelect( int menuId ) | |||
426 | if ( currentGame->isReplayAvailable() ) | 395 | if ( currentGame->isReplayAvailable() ) |
427 | { | 396 | { |
428 | #ifdef QWS | 397 | string replayFile = getHomeDir() + "/" + currentGame->getGameName() + ".replay"; |
429 | QString replayFile = getenv( "HOME" ); | ||
430 | #else | ||
431 | QString replayFile = "."; | ||
432 | #endif | ||
433 | replayFile += string( "/" ) + currentGame->getGameName() + ".replay"; | ||
434 | 398 | ||
435 | currentGame->saveReplay( replayFile ); | 399 | currentGame->saveReplay( replayFile ); |
@@ -495,18 +459,67 @@ void SFCave :: handleMenuSelect( int menuId ) | |||
495 | break; | 459 | break; |
496 | 460 | ||
461 | case MENU_DIFFICULTY_CUSTOM: | ||
462 | currentGame->setDifficulty( MENU_DIFFICULTY_CUSTOM ); | ||
463 | saveSetting( "GameDifficulty", "Custom" ); | ||
464 | break; | ||
465 | |||
497 | case MENU_SOUND_ON: | 466 | case MENU_SOUND_ON: |
498 | SoundHandler :: setSoundsOn( true ); | 467 | SoundHandler :: setSoundsOn( true ); |
468 | saveSetting( "SoundOn", "true" ); | ||
499 | break; | 469 | break; |
500 | 470 | ||
501 | case MENU_SOUND_OFF: | 471 | case MENU_SOUND_OFF: |
502 | SoundHandler :: setSoundsOn( false ); | 472 | SoundHandler :: setSoundsOn( false ); |
473 | saveSetting( "SoundOn", "false" ); | ||
503 | break; | 474 | break; |
504 | 475 | ||
505 | case MENU_MUSIC_ON: | 476 | case MENU_MUSIC_ON: |
506 | SoundHandler :: setMusicOn( true ); | 477 | SoundHandler :: setMusicOn( true ); |
478 | saveSetting( "MusicOn", "true" ); | ||
507 | break; | 479 | break; |
508 | 480 | ||
509 | case MENU_MUSIC_OFF: | 481 | case MENU_MUSIC_OFF: |
510 | SoundHandler :: setMusicOn( false ); | 482 | SoundHandler :: setMusicOn( false ); |
483 | saveSetting( "MusicOn", "false" ); | ||
484 | break; | ||
485 | |||
486 | case MENU_CUSTOM_THRUST: | ||
487 | customPlayerMenuVal = PLAYER_THRUST; | ||
488 | origValue = currentGame->getPlayer()->getValue( customPlayerMenuVal ); | ||
489 | setMenuStatusText( currentGame->getPlayer()->getValueString( customPlayerMenuVal ) ); | ||
490 | break; | ||
491 | case MENU_CUSTOM_GRAVITY: | ||
492 | customPlayerMenuVal = PLAYER_GRAVITY; | ||
493 | origValue = currentGame->getPlayer()->getValue( customPlayerMenuVal ); | ||
494 | setMenuStatusText( currentGame->getPlayer()->getValueString( customPlayerMenuVal ) ); | ||
495 | break; | ||
496 | case MENU_CUSTOM_MAXSPEEDUP: | ||
497 | customPlayerMenuVal = PLAYER_MAX_SPEED_UP; | ||
498 | origValue = currentGame->getPlayer()->getValue( customPlayerMenuVal ); | ||
499 | setMenuStatusText( currentGame->getPlayer()->getValueString( customPlayerMenuVal ) ); | ||
500 | break; | ||
501 | case MENU_CUSTOM_MAXSPEEDDOWN: | ||
502 | customPlayerMenuVal = PLAYER_MAX_SPEED_DOWN; | ||
503 | origValue = currentGame->getPlayer()->getValue( customPlayerMenuVal ); | ||
504 | setMenuStatusText( currentGame->getPlayer()->getValueString( customPlayerMenuVal ) ); | ||
505 | break; | ||
506 | case MENU_CUSTOM_INCREASE: | ||
507 | currentGame->getPlayer()->incValue( customPlayerMenuVal ); | ||
508 | setMenuStatusText( currentGame->getPlayer()->getValueString( customPlayerMenuVal ) ); | ||
509 | break; | ||
510 | case MENU_CUSTOM_DECREASE: | ||
511 | currentGame->getPlayer()->decValue( customPlayerMenuVal ); | ||
512 | setMenuStatusText( currentGame->getPlayer()->getValueString( customPlayerMenuVal ) ); | ||
513 | break; | ||
514 | case MENU_CUSTOM_SAVE: | ||
515 | { | ||
516 | // save settings | ||
517 | string key = currentGame->getGameName() + "_custom_player_" + currentGame->getPlayer()->getValueTypeString( customPlayerMenuVal ); | ||
518 | saveSetting( key, currentGame->getPlayer()->getValue( customPlayerMenuVal ) ); | ||
519 | |||
520 | break; | ||
521 | } | ||
522 | case MENU_CUSTOM_CANCEL: | ||
523 | currentGame->getPlayer()->setValue( customPlayerMenuVal, origValue ); | ||
511 | break; | 524 | break; |
512 | 525 | ||
@@ -534,4 +547,16 @@ void SFCave :: saveSetting( string key, int val ) | |||
534 | } | 547 | } |
535 | 548 | ||
549 | void SFCave :: saveSetting( string key, long val ) | ||
550 | { | ||
551 | Settings cfg( "sfcave-sdl" ); | ||
552 | cfg.writeSetting( key, val ); | ||
553 | } | ||
554 | |||
555 | void SFCave :: saveSetting( string key, double val ) | ||
556 | { | ||
557 | Settings cfg( "sfcave-sdl" ); | ||
558 | cfg.writeSetting( key, val ); | ||
559 | } | ||
560 | |||
536 | string SFCave :: loadSetting( string key, string defaultVal ) | 561 | string SFCave :: loadSetting( string key, string defaultVal ) |
537 | { | 562 | { |
@@ -545,2 +570,64 @@ string SFCave :: loadSetting( string key, string defaultVal ) | |||
545 | return val; | 570 | return val; |
546 | } | 571 | } |
572 | |||
573 | bool SFCave :: loadBoolSetting( string key, bool defaultVal ) | ||
574 | { | ||
575 | bool val = defaultVal; | ||
576 | Settings cfg( "sfcave-sdl" ); | ||
577 | cfg.readSetting( key, val ); | ||
578 | |||
579 | return val; | ||
580 | } | ||
581 | |||
582 | int SFCave :: loadIntSetting( string key, int defaultVal ) | ||
583 | { | ||
584 | int val = defaultVal; | ||
585 | Settings cfg( "sfcave-sdl" ); | ||
586 | cfg.readSetting( key, val ); | ||
587 | |||
588 | return val; | ||
589 | } | ||
590 | |||
591 | double SFCave :: loadDoubleSetting( string key, double defaultVal ) | ||
592 | { | ||
593 | double val = defaultVal; | ||
594 | Settings cfg( "sfcave-sdl" ); | ||
595 | cfg.readSetting( key, val ); | ||
596 | |||
597 | return val; | ||
598 | } | ||
599 | |||
600 | |||
601 | void SFCave :: calcFPS() | ||
602 | { | ||
603 | struct timeb tp; | ||
604 | ftime( &tp ); | ||
605 | start =(tp.time%10000)*10000 + tp.millitm; | ||
606 | if ( start - time1 >= 1000 ) | ||
607 | { | ||
608 | actualFPS = FPS; | ||
609 | FPS = 0; | ||
610 | time1 = start; | ||
611 | } | ||
612 | else | ||
613 | FPS ++; | ||
614 | } | ||
615 | |||
616 | void SFCave :: FPSDelay() | ||
617 | { | ||
618 | struct timeb tp; | ||
619 | // Slow down polling - limit to x FPS | ||
620 | ftime( &tp ); | ||
621 | end = abs((tp.time%10000)*10000 + tp.millitm); | ||
622 | if ( end-start < (1000/maxFPS) ) | ||
623 | { | ||
624 | if ( (1000/maxFPS)-(end-start) > 500 ) | ||
625 | { | ||
626 | // Should never happen but in case it does sleep for 5 seconds | ||
627 | printf( "WARNING WILL ROBINSON! delay = %ld - start %ld, end %ld\n", (1000/maxFPS)-(end-start), start, end ); | ||
628 | SDL_Delay( 5 ); | ||
629 | } | ||
630 | else | ||
631 | SDL_Delay((1000/maxFPS)-(end-start) ); | ||
632 | } | ||
633 | } | ||
diff --git a/noncore/games/sfcave-sdl/sfcave.h b/noncore/games/sfcave-sdl/sfcave.h index 96c2334..c707919 100644 --- a/noncore/games/sfcave-sdl/sfcave.h +++ b/noncore/games/sfcave-sdl/sfcave.h | |||
@@ -16,5 +16,4 @@ public: | |||
16 | ~SFCave(); | 16 | ~SFCave(); |
17 | 17 | ||
18 | void drawGameScreen(); | ||
19 | void initSDL( int argc, char *argv[] ); | 18 | void initSDL( int argc, char *argv[] ); |
20 | void mainEventLoop(); | 19 | void mainEventLoop(); |
@@ -31,7 +30,14 @@ public: | |||
31 | void saveSetting( string key, string val ); | 30 | void saveSetting( string key, string val ); |
32 | void saveSetting( string key, int val ); | 31 | void saveSetting( string key, int val ); |
32 | void saveSetting( string key, long val ); | ||
33 | void saveSetting( string key, double val ); | ||
33 | string loadSetting( string key, string defaultVal = "" ); | 34 | string loadSetting( string key, string defaultVal = "" ); |
35 | bool loadBoolSetting( string key, bool defaultVal); | ||
36 | int loadIntSetting( string key, int defaultVal ); | ||
37 | double loadDoubleSetting( string key, double defaultVal ); | ||
38 | |||
34 | private: | 39 | private: |
35 | SDL_Surface *screen; | 40 | SDL_Surface *screen; |
41 | bool setupOK; | ||
36 | 42 | ||
37 | Game *currentGame; | 43 | Game *currentGame; |
@@ -39,11 +45,27 @@ private: | |||
39 | Help *help; | 45 | Help *help; |
40 | int state; | 46 | int state; |
41 | int maxFPS; | ||
42 | int actualFPS; | ||
43 | bool showFps; | 47 | bool showFps; |
44 | string musicPath; | 48 | string musicPath; |
45 | string musicType; | 49 | string musicType; |
50 | bool finish; | ||
51 | |||
52 | bool limitFPS; | ||
53 | int maxFPS; | ||
54 | int actualFPS; | ||
55 | int FPS; | ||
56 | long time1; | ||
57 | long start; | ||
58 | long end; | ||
59 | |||
60 | // This is used when the user is setting the custom | ||
61 | // values in the menu | ||
62 | int customPlayerMenuVal; | ||
63 | double origValue; | ||
46 | 64 | ||
47 | void handleMenuSelect( int menuId ); | 65 | void handleMenuSelect( int menuId ); |
66 | void handleGameState(); | ||
67 | void handleEvents(); | ||
68 | void calcFPS(); | ||
69 | void FPSDelay(); | ||
48 | }; | 70 | }; |
49 | 71 | ||
diff --git a/noncore/games/sfcave-sdl/sfcave_game.cpp b/noncore/games/sfcave-sdl/sfcave_game.cpp index 72c5ce3..1b00e14 100644 --- a/noncore/games/sfcave-sdl/sfcave_game.cpp +++ b/noncore/games/sfcave-sdl/sfcave_game.cpp | |||
@@ -40,4 +40,17 @@ void SFCaveGame :: init() | |||
40 | blockDistance = 30; | 40 | blockDistance = 30; |
41 | break; | 41 | break; |
42 | case MENU_DIFFICULTY_CUSTOM: | ||
43 | { | ||
44 | // Read custom difficulty settings for this game | ||
45 | blockDistance = parent->loadIntSetting( "SFCave_custom_blockdistance", 50 ); | ||
46 | |||
47 | double thrust = parent->loadDoubleSetting( "SFCave_custom_player_thrust", 0.4 ); | ||
48 | double gravity = parent->loadDoubleSetting( "SFCave_custom_player_gravity", 0.6 ); | ||
49 | double maxUp = parent->loadDoubleSetting( "SFCave_custom_player_maxupspeed", 4.0 ); | ||
50 | double maxDown = parent->loadDoubleSetting( "SFCave_custom_player_maxdownspeed", 5.0 ); | ||
51 | player->setMovementInfo( thrust, gravity, maxUp, maxDown ); | ||
52 | |||
53 | break; | ||
54 | } | ||
42 | } | 55 | } |
43 | 56 | ||
@@ -69,5 +82,4 @@ void SFCaveGame :: update( int state ) | |||
69 | if ( checkCollisions() ) | 82 | if ( checkCollisions() ) |
70 | { | 83 | { |
71 | // printf( "Crashed!\n" ); | ||
72 | parent->changeState( STATE_CRASHING ); | 84 | parent->changeState( STATE_CRASHING ); |
73 | return; | 85 | return; |
diff --git a/noncore/games/sfcave-sdl/sound.cpp b/noncore/games/sfcave-sdl/sound.cpp index 5fda859..855f2e6 100644 --- a/noncore/games/sfcave-sdl/sound.cpp +++ b/noncore/games/sfcave-sdl/sound.cpp | |||
@@ -32,4 +32,5 @@ bool SoundHandler :: init( ) | |||
32 | 32 | ||
33 | soundOn = true; | 33 | soundOn = true; |
34 | musicOn = true; | ||
34 | 35 | ||
35 | return true; | 36 | return true; |
@@ -39,5 +40,7 @@ void SoundHandler :: cleanUp() | |||
39 | { | 40 | { |
40 | // Free audio sounds | 41 | // Free audio sounds |
42 | if ( sounds[SND_EXPLOSION] ) | ||
41 | Mix_FreeChunk( sounds[SND_EXPLOSION] ); | 43 | Mix_FreeChunk( sounds[SND_EXPLOSION] ); |
44 | if ( sounds[SND_THRUST] ) | ||
42 | Mix_FreeChunk( sounds[SND_THRUST] ); | 45 | Mix_FreeChunk( sounds[SND_THRUST] ); |
43 | 46 | ||
@@ -53,5 +56,5 @@ int SoundHandler :: playSound( int soundNr, int channel, int nrLoops, int playBe | |||
53 | return -1; | 56 | return -1; |
54 | 57 | ||
55 | if ( soundNr >= NR_SOUNDS ) | 58 | if ( soundNr >= NR_SOUNDS || !sounds[soundNr] ) |
56 | return -1; | 59 | return -1; |
57 | 60 | ||
@@ -102,5 +105,5 @@ void SoundHandler :: playMusic( string musicFile ) | |||
102 | void SoundHandler :: playMusic( bool fade ) | 105 | void SoundHandler :: playMusic( bool fade ) |
103 | { | 106 | { |
104 | if ( !soundOn ) | 107 | if ( !musicOn ) |
105 | return; | 108 | return; |
106 | 109 | ||
diff --git a/noncore/games/sfcave-sdl/starfield.cpp b/noncore/games/sfcave-sdl/starfield.cpp index c1f2d73..82edfc1 100644 --- a/noncore/games/sfcave-sdl/starfield.cpp +++ b/noncore/games/sfcave-sdl/starfield.cpp | |||
@@ -222,2 +222,74 @@ void StarField :: draw( SDL_Surface *screen, int w, int h ) | |||
222 | } | 222 | } |
223 | } | 223 | } |
224 | |||
225 | |||
226 | |||
227 | // Test | ||
228 | #ifdef DEBUG_STARS | ||
229 | SDL_Surface *screen; | ||
230 | StarField *stars; | ||
231 | |||
232 | void go() | ||
233 | { | ||
234 | /* Initialize SDL */ | ||
235 | if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) | ||
236 | { | ||
237 | fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); | ||
238 | exit(1); | ||
239 | } | ||
240 | atexit(SDL_Quit); | ||
241 | |||
242 | int videoflags = SDL_SWSURFACE ; | ||
243 | |||
244 | if ( (screen=SDL_SetVideoMode(240, 320,32,videoflags)) == NULL ) | ||
245 | { | ||
246 | fprintf(stderr, "Couldn't set %ix%i video mode: %s\n",240,320,SDL_GetError()); | ||
247 | exit(2); | ||
248 | } | ||
249 | |||
250 | stars = new StarField( false, 200 ); | ||
251 | |||
252 | bool done = false; | ||
253 | while ( !done ) | ||
254 | { | ||
255 | SDL_FillRect( screen, 0, 0 ); | ||
256 | stars->draw( screen ); | ||
257 | stars->move( ); | ||
258 | |||
259 | SDL_Flip( screen ); | ||
260 | |||
261 | SDL_Delay( 10 ); | ||
262 | |||
263 | SDL_Event event; | ||
264 | while ( SDL_PollEvent(&event) ) | ||
265 | { | ||
266 | switch (event.type) | ||
267 | { | ||
268 | case SDL_KEYDOWN: | ||
269 | // Escape keypress quits the app | ||
270 | if ( event.key.keysym.sym != SDLK_ESCAPE ) | ||
271 | { | ||
272 | break; | ||
273 | } | ||
274 | case SDL_QUIT: | ||
275 | done = 1; | ||
276 | break; | ||
277 | default: | ||
278 | break; | ||
279 | } | ||
280 | } | ||
281 | } | ||
282 | } | ||
283 | |||
284 | |||
285 | |||
286 | |||
287 | #ifdef __cplusplus | ||
288 | extern "C" | ||
289 | #endif | ||
290 | int main( int argc, char *argv[] ) | ||
291 | { | ||
292 | go(); | ||
293 | } | ||
294 | |||
295 | #endif | ||
diff --git a/noncore/games/sfcave-sdl/terrain.cpp b/noncore/games/sfcave-sdl/terrain.cpp index c001a56..b243f45 100644 --- a/noncore/games/sfcave-sdl/terrain.cpp +++ b/noncore/games/sfcave-sdl/terrain.cpp | |||
@@ -48,4 +48,5 @@ void Terrain :: initTerrain() | |||
48 | 48 | ||
49 | SDL_FillRect( terrainSurface, 0, 0 ); | 49 | SDL_FillRect( terrainSurface, 0, 0 ); |
50 | |||
50 | // Draw Terrain into surface | 51 | // Draw Terrain into surface |
51 | Sint16 px[5]; | 52 | Sint16 px[5]; |
@@ -92,5 +93,4 @@ void Terrain :: moveTerrain( int amountToMove ) | |||
92 | speed = offset/segSize; | 93 | speed = offset/segSize; |
93 | 94 | ||
94 | //printf( "offset - %d, speed - %d\n", offset, speed ); | ||
95 | if ( offset >= segSize ) | 95 | if ( offset >= segSize ) |
96 | { | 96 | { |
@@ -196,5 +196,4 @@ void Terrain :: drawTerrain( SDL_Surface *screen ) | |||
196 | dst.w = sWidth; | 196 | dst.w = sWidth; |
197 | dst.h = sHeight; | 197 | dst.h = sHeight; |
198 | //dst.h = maxHeight; | ||
199 | 198 | ||
200 | SDL_Rect dst2; | 199 | SDL_Rect dst2; |
@@ -205,20 +204,4 @@ void Terrain :: drawTerrain( SDL_Surface *screen ) | |||
205 | 204 | ||
206 | stars->draw( screen ); | 205 | stars->draw( screen ); |
207 | |||
208 | //dst.y = sHeight - maxHeight; | ||
209 | //dst2.y = sHeight - maxHeight; | ||
210 | //SDL_BlitSurface(terrainSurface, &dst, screen, &dst2 ); | ||
211 | |||
212 | /* | ||
213 | for ( int i = 0 ; i < MAPSIZE ; ++i ) | ||
214 | { | ||
215 | int x1 = (i*segSize) - (offset*speed); | ||
216 | int x2 = ((i+1)*segSize)-(offset*speed); | ||
217 | if ( x2 >= sWidth ) | ||
218 | x2 = sWidth-1; | ||
219 | aalineRGBA( screen, x1, mapTop[i], x2, mapTop[i+1], 0, 220, 0, 255 ); | ||
220 | aalineRGBA( screen, x1, mapBottom[i], x2, mapBottom[i+1], 0, 220, 0, 255 ); | ||
221 | } | ||
222 | */ | ||
223 | } | 206 | } |
224 | 207 | ||
@@ -227,4 +210,5 @@ bool Terrain :: checkCollision( int x, int y, int h ) | |||
227 | if ( y < 0 || y > sHeight ) | 210 | if ( y < 0 || y > sHeight ) |
228 | return true; | 211 | return true; |
212 | |||
229 | // First get segment that matches x | 213 | // First get segment that matches x |
230 | SDL_LockSurface( terrainSurface ); | 214 | SDL_LockSurface( terrainSurface ); |
@@ -248,5 +232,5 @@ Terrain *terrain; | |||
248 | void go() | 232 | void go() |
249 | { | 233 | { |
250 | /* Initialize SDL */ | 234 | // Initialize SDL |
251 | if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) | 235 | if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) |
252 | { | 236 | { |
diff --git a/noncore/games/sfcave-sdl/util.cpp b/noncore/games/sfcave-sdl/util.cpp index 86738ad..f73e256 100644 --- a/noncore/games/sfcave-sdl/util.cpp +++ b/noncore/games/sfcave-sdl/util.cpp | |||
@@ -36,5 +36,5 @@ Uint32 getpixel(SDL_Surface *surface, int x, int y) | |||
36 | } | 36 | } |
37 | 37 | ||
38 | const char *chooseRandomFile( string path, string fileType ) | 38 | string chooseRandomFile( string path, string fileType ) |
39 | { | 39 | { |
40 | vector<string> files; | 40 | vector<string> files; |
@@ -51,8 +51,6 @@ const char *chooseRandomFile( string path, string fileType ) | |||
51 | int pos = file.find( ".", 1 ) + 1; | 51 | int pos = file.find( ".", 1 ) + 1; |
52 | string tmp = file.substr( pos ); | 52 | string tmp = file.substr( pos ); |
53 | printf( "pos = %d, tmp =%s\n", pos, tmp.c_str() ); | ||
54 | if ( tmp.size() > 0 && fileType.find( tmp ) != -1 ) | 53 | if ( tmp.size() > 0 && fileType.find( tmp ) != -1 ) |
55 | { | 54 | { |
56 | printf( "Matching <%s> - %s with <%s>\n", file.substr( pos ).c_str(), file.c_str(), fileType.c_str() ); | ||
57 | files.push_back( file ); | 55 | files.push_back( file ); |
58 | } | 56 | } |
@@ -61,4 +59,17 @@ const char *chooseRandomFile( string path, string fileType ) | |||
61 | 59 | ||
62 | closedir( d ); | 60 | closedir( d ); |
63 | return files[nextInt( files.size() )].c_str(); | 61 | return files[nextInt( files.size() )]; |
62 | } | ||
63 | |||
64 | |||
65 | string getHomeDir() | ||
66 | { | ||
67 | string home; | ||
68 | #ifdef QWS | ||
69 | home = getenv( "HOME" ); | ||
70 | #else | ||
71 | home = "."; | ||
72 | #endif | ||
73 | |||
74 | return home; | ||
64 | } | 75 | } |
diff --git a/noncore/games/sfcave-sdl/util.h b/noncore/games/sfcave-sdl/util.h index fe3e9c0..e3aa31a 100644 --- a/noncore/games/sfcave-sdl/util.h +++ b/noncore/games/sfcave-sdl/util.h | |||
@@ -6,5 +6,5 @@ using namespace std; | |||
6 | 6 | ||
7 | Uint32 getpixel(SDL_Surface *surface, int x, int y); | 7 | Uint32 getpixel(SDL_Surface *surface, int x, int y); |
8 | const char *chooseRandomFile( string path, string fileType ); | 8 | string chooseRandomFile( string path, string fileType ); |
9 | 9 | string getHomeDir(); | |
10 | #endif | 10 | #endif |