summaryrefslogtreecommitdiff
path: root/noncore/games/sfcave-sdl/game.cpp
Side-by-side diff
Diffstat (limited to 'noncore/games/sfcave-sdl/game.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/games/sfcave-sdl/game.cpp50
1 files changed, 23 insertions, 27 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
@@ -51,13 +51,13 @@ void Game :: init()
}
else
{
setSeed( -1 );
replayList.clear();
}
-
+
score = 0;
nrFrames = 0;
press = false;
// Load highscore
string key = getGameName() + "_" + getGameDifficultyText() + "_highscore";
@@ -73,68 +73,72 @@ void Game :: handleKeys( SDL_KeyboardEvent &key )
{
if ( key.type == SDL_KEYDOWN )
{
if ( !press )
replayList.push_back( nrFrames );
press = true;
-
-// if ( thrustChannel == -1 && parent->getState() == STATE_PLAYING )
-// thrustChannel = SoundHandler :: playSound( SND_THRUST, -1, -1, false );
}
else
{
if ( press )
replayList.push_back( nrFrames );
press = false;
- if ( thrustChannel != -1 )
- {
-// SoundHandler :: stopSound( thrustChannel, true, 300 );
-// thrustChannel = -1;
- }
}
}
}
-QString Game :: getGameDifficultyText()
+string Game :: getGameDifficultyText()
{
- QString ret;
+ string ret;
if ( difficulty == MENU_DIFFICULTY_EASY )
ret = "Easy";
else if ( difficulty == MENU_DIFFICULTY_NORMAL )
ret = "Medium";
else if ( difficulty == MENU_DIFFICULTY_HARD )
ret = "Hard";
+ else if ( difficulty == MENU_DIFFICULTY_CUSTOM )
+ ret = "Custom";
return ret;
}
void Game :: setDifficulty( string diff )
{
if ( diff == "Easy" )
difficulty = MENU_DIFFICULTY_EASY;
else if ( diff == "Medium" )
difficulty = MENU_DIFFICULTY_NORMAL;
else if ( diff == "Hard" )
difficulty = MENU_DIFFICULTY_HARD;
+ else if ( diff == "Custom" )
+ difficulty = MENU_DIFFICULTY_CUSTOM;
+
+ init();
+}
+
+void Game :: setDifficulty( int diff )
+{
+ difficulty = diff;
+ init();
}
void Game :: update( int state )
{
nrFrames ++;
if ( score > highScore )
highScore = score;
if ( state == STATE_PLAYING )
{
- if ( replay )
+ if ( replay )
{
while( replayIt != replayList.end() && (*replayIt) == nrFrames-1 )
{
press = !press;
replayIt ++;
}
@@ -163,20 +167,19 @@ void Game :: preDraw( SDL_Surface *screen )
{
}
void Game :: draw( SDL_Surface *screen )
{
char tmp[100];
- QString scoreText;
+ string scoreText;
sprintf( tmp, "Score: %06ld High Score: %06ld", score, highScore );
-// printf( "%s\n", (const char *)scoreText );
FontHandler::draw( screen, FONT_WHITE_TEXT, tmp, 3, 10 );
if ( parent->getState() == STATE_CRASHED )
{
- QString crashText;
+ string crashText;
crashText = "Game Over";
int x = (240 - FontHandler::TextWidth( FONT_WHITE_TEXT, (const char *)crashText.c_str() )) / 2;
FontHandler::draw( screen, FONT_WHITE_TEXT, (const char *)crashText.c_str(), x, 150 );
int fontHeight = FontHandler::FontHeight( FONT_WHITE_TEXT );
crashText = "Press Middle Button to play again";
@@ -220,26 +223,26 @@ void Game :: setSeed( int seed )
currentSeed = ((unsigned long) time((time_t *) NULL));
else
currentSeed = seed;
PutSeed( currentSeed );
}
-void Game :: saveReplay( QString file )
+void Game :: saveReplay( string file )
{
FILE *out;
out = fopen( file.c_str(), "w" );
if ( !out )
{
printf( "Couldn't write to /home/root/%s\n", file.c_str() );
parent->setMenuStatusText( "Couldn't save replay file" );
return;
}
// Build up string of values
// Format is:: <landscape seed> <game type> <difficulty> <framenr> <framenr>.......
- QString val;
+ string val;
char tmp[20];
sprintf( tmp, "%d %d ", currentSeed, difficulty );
val = tmp;
list<int>::iterator it = replayList.begin();
while( it != replayList.end() )
@@ -248,26 +251,23 @@ void Game :: saveReplay( QString file )
val += tmp;
it++;
}
val += "\n";
- QString line;
+ string line;
sprintf( tmp, "%d\n", val.length() );
line = tmp;
fwrite( line.c_str(), 1, line.length(), out );
fwrite( val.c_str(), 1, val.length(), out );
fclose( out );
-
- printf( "Replay saved to %s\n", (const char *)file.c_str() );
-
}
-void Game :: loadReplay( QString file )
+void Game :: loadReplay( string file )
{
FILE *in = fopen( (const char *)file.c_str(), "r" );
if ( in == 0 )
{
@@ -282,15 +282,14 @@ void Game :: loadReplay( QString file )
int length = -1;
sscanf( line, "%d", &length );
char *data = new char[length+1];
fread( data, 1, length, in );
-// printf( "data - %s", data );
- QString sep = " ";
+ string sep = " ";
StringTokenizer st( data, sep );
// print it out
vector<string>::iterator it = st.begin();
currentSeed = atoi( (*it).c_str() );
@@ -305,15 +304,12 @@ void Game :: loadReplay( QString file )
replayList.push_back( v );
}
delete data;
fclose( in );
-
- printf( "Replay loaded from %s\n", (const char *)file.c_str() );
-
}
Game *Game :: createGame( SFCave *p, int w, int h, string game, string difficulty )
{
Game *g;