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 @@ -6,3 +6,3 @@ -AnimatedImage :: AnimatedImage( QString file, int nFrames ) +AnimatedImage :: AnimatedImage( string file, int nFrames ) { @@ -21,5 +21,2 @@ AnimatedImage :: AnimatedImage( QString file, int nFrames ) SDL_SetColorKey(image, SDL_SRCCOLORKEY | SDL_RLEACCEL, SDL_MapRGB( image->format, 0, 0, 0 ) ); -// image = SDL_DisplayFormat( tmp ); - -// SDL_FreeSurface( tmp ); frameWidth = image->w/nrFrames; @@ -49,2 +46,5 @@ void AnimatedImage :: draw( SDL_Surface *screen, int x, int y ) { + if ( !image ) + return; + SDL_Rect dst; 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 @@ -8,3 +8,3 @@ class AnimatedImage public: - AnimatedImage( QString file, int nFrames ); + AnimatedImage( string file, int nFrames ); ~AnimatedImage(); 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 @@ -75,6 +75,2 @@ void BFont::LoadFont (const char *filename) } - else - { - cerr << "Error! The font has not been loaded!" << endl; - } } @@ -115,3 +111,2 @@ BFont * BFont :: SetFontColor(Uint8 r, Uint8 g, Uint8 b) - printf("looking...\n"); for( x=0; x < Surface->w; x++) { @@ -133,3 +128,3 @@ BFont * BFont :: SetFontColor(Uint8 r, Uint8 g, Uint8 b) } - printf("unlooking...\n"); + 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 @@ -5,3 +5,2 @@ using namespace std; -#define QString string @@ -57,7 +56,17 @@ using namespace std; #define MENU_DIFFICULTY_HARD 18 -#define MENU_SOUNDS 19 -#define MENU_SOUND_ON 20 -#define MENU_SOUND_OFF 21 -#define MENU_MUSIC_ON 22 -#define MENU_MUSIC_OFF 23 +#define MENU_DIFFICULTY_HARD 18 +#define MENU_DIFFICULTY_CUSTOM 19 +#define MENU_SOUNDS 20 +#define MENU_SOUND_ON 21 +#define MENU_SOUND_OFF 22 +#define MENU_MUSIC_ON 23 +#define MENU_MUSIC_OFF 24 +#define MENU_CUSTOM_THRUST 25 +#define MENU_CUSTOM_GRAVITY 26 +#define MENU_CUSTOM_MAXSPEEDUP 27 +#define MENU_CUSTOM_MAXSPEEDDOWN 28 +#define MENU_CUSTOM_INCREASE 29 +#define MENU_CUSTOM_DECREASE 30 +#define MENU_CUSTOM_SAVE 31 +#define MENU_CUSTOM_CANCEL 32 @@ -66,2 +75,10 @@ using namespace std; #define SND_THRUST 1 +#define INGAME_MUSIC SOUND_PATH "ingame.mod" + +// Constants for player values +#define PLAYER_THRUST 0 +#define PLAYER_GRAVITY 1 +#define PLAYER_MAX_SPEED_UP 2 +#define PLAYER_MAX_SPEED_DOWN 3 + #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 @@ -19,2 +19,3 @@ FlyGame :: ~FlyGame() { + // terrain and player get deleted by parent class } @@ -36,2 +37,11 @@ void FlyGame :: init() break; + case MENU_DIFFICULTY_CUSTOM: + { + double thrust = parent->loadDoubleSetting( "Fly_custom_player_thrust", 0.3 ); + double gravity = parent->loadDoubleSetting( "Fly_custom_player_gravity", 0.2 ); + double maxUp = parent->loadDoubleSetting( "Fly_custom_player_maxupspeed", 1.5 ); + double maxDown = parent->loadDoubleSetting( "Fly_custom_player_maxdownspeed", 1.5 ); + player->setMovementInfo( thrust, gravity, maxUp, maxDown ); + break; + } } @@ -52,3 +62,3 @@ void FlyGame :: update( int state ) int tmpScore = ((FlyTerrain *)terrain)->getScore( 1, diff ); -// printf( "diff - %d score - %d\n", diff, tmpScore ); + if ( !startScoring ) @@ -71,3 +81,2 @@ void FlyGame :: update( int state ) { -// printf( "Crashed!\n" ); parent->changeState( STATE_CRASHING ); 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 @@ -10,3 +10,3 @@ BFont *FontHandler :: helpFont; -void FontHandler :: init() +bool FontHandler :: init() { @@ -19,2 +19,11 @@ void FontHandler :: init() colouredFont = 0; + + // Check if we are installed correctly (we need fonts to function) + if ( menuSelFont == 0 || menuUnSelFont == 0 || whiteFont == 0 || helpFont == 0 ) + { + printf( "One or more fonts are not installed correctly\n" ); + return false; + } + + return true; } @@ -23,7 +32,10 @@ void FontHandler :: cleanUp() { + if ( menuSelFont ) delete menuSelFont; + if ( menuUnSelFont ) delete menuUnSelFont; + if ( whiteFont ) delete whiteFont; + if ( helpFont ) delete helpFont; - if ( 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 @@ -15,3 +15,3 @@ class FontHandler public: - static void init(); + static bool init(); static void cleanUp(); 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 @@ -78,5 +78,2 @@ void Game :: handleKeys( SDL_KeyboardEvent &key ) press = true; - -// if ( thrustChannel == -1 && parent->getState() == STATE_PLAYING ) -// thrustChannel = SoundHandler :: playSound( SND_THRUST, -1, -1, false ); } @@ -88,7 +85,2 @@ void Game :: handleKeys( SDL_KeyboardEvent &key ) - if ( thrustChannel != -1 ) - { -// SoundHandler :: stopSound( thrustChannel, true, 300 ); -// thrustChannel = -1; - } } @@ -99,5 +91,5 @@ void Game :: handleKeys( SDL_KeyboardEvent &key ) -QString Game :: getGameDifficultyText() +string Game :: getGameDifficultyText() { - QString ret; + string ret; @@ -109,2 +101,4 @@ QString Game :: getGameDifficultyText() ret = "Hard"; + else if ( difficulty == MENU_DIFFICULTY_CUSTOM ) + ret = "Custom"; @@ -121,2 +115,12 @@ void Game :: setDifficulty( string diff ) difficulty = MENU_DIFFICULTY_HARD; + else if ( diff == "Custom" ) + difficulty = MENU_DIFFICULTY_CUSTOM; + + init(); +} + +void Game :: setDifficulty( int diff ) +{ + difficulty = diff; + init(); } @@ -168,5 +172,4 @@ 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 ); @@ -175,3 +178,3 @@ void Game :: draw( SDL_Surface *screen ) { - QString crashText; + string crashText; crashText = "Game Over"; @@ -225,3 +228,3 @@ void Game :: setSeed( int seed ) -void Game :: saveReplay( QString file ) +void Game :: saveReplay( string file ) { @@ -238,3 +241,3 @@ void Game :: saveReplay( QString file ) // Format is:: <landscape seed> <game type> <difficulty> <framenr> <framenr>....... - QString val; + string val; char tmp[20]; @@ -253,3 +256,3 @@ void Game :: saveReplay( QString file ) - QString line; + string line; sprintf( tmp, "%d\n", val.length() ); @@ -261,8 +264,5 @@ void Game :: saveReplay( QString file ) fclose( out ); - - printf( "Replay saved to %s\n", (const char *)file.c_str() ); - } -void Game :: loadReplay( QString file ) +void Game :: loadReplay( string file ) { @@ -287,5 +287,4 @@ void Game :: loadReplay( QString file ) fread( data, 1, length, in ); -// printf( "data - %s", data ); - QString sep = " "; + string sep = " "; @@ -310,5 +309,2 @@ void Game :: loadReplay( QString file ) fclose( in ); - - printf( "Replay loaded from %s\n", (const char *)file.c_str() ); - } 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 @@ -27,6 +27,6 @@ public: void handleKeys( SDL_KeyboardEvent &key ); - QString getGameName() { return gameName; } + string getGameName() { return gameName; } int getDifficulty() { return difficulty; } - QString getGameDifficultyText(); - void setDifficulty( int diff ) { difficulty = diff; } + string getGameDifficultyText(); + void setDifficulty( int diff ); void setDifficulty( string diff ); @@ -41,6 +41,7 @@ public: Terrain *getTerrain() { return terrain; } + Player *getPlayer() { return player; } void setSeed( int seed ); - void loadReplay( QString file ); - void saveReplay( QString file ); + void loadReplay( string file ); + void saveReplay( string file ); @@ -49,3 +50,3 @@ public: protected: - QString gameName; + string gameName; @@ -71,8 +72,6 @@ protected: -// QListIterator<int> *replayIt; list<int> replayList; list<int>::iterator replayIt; -// QList<int> replayList; bool replay; - QString replayFile; + string replayFile; 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 @@ -20,2 +20,3 @@ GatesGame :: ~GatesGame() { + // terrain and player get deleted by parent class } @@ -48,2 +49,15 @@ void GatesGame :: init() break; + case MENU_DIFFICULTY_CUSTOM: + { + // Read custom difficulty settings for this game + gapHeight = parent->loadIntSetting( "Gates_custom_gapHeight", 75 ); + + double thrust = parent->loadDoubleSetting( "Gates_custom_player_thrust", 0.4 ); + double gravity = parent->loadDoubleSetting( "Gates_custom_player_gravity", 0.6 ); + double maxUp = parent->loadDoubleSetting( "Gates_custom_player_maxupspeed", 4.0 ); + double maxDown = parent->loadDoubleSetting( "Gates_custom_player_maxdownspeed", 5.0 ); + player->setMovementInfo( thrust, gravity, maxUp, maxDown ); + + break; + } } @@ -79,3 +93,2 @@ void GatesGame :: update( int state ) { -// printf( "Crashed!\n" ); parent->changeState( STATE_CRASHING ); 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 @@ -59,3 +59,2 @@ void Help :: draw( SDL_Surface *screen ) -
list<string>::iterator it = textList.begin();
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 @@ -10,3 +10,3 @@ -MenuOption :: MenuOption( QString text, int id ) +MenuOption :: MenuOption( string text, int id ) { @@ -117,2 +117,3 @@ Menu :: Menu( SFCave *p ) // Game Difficulty menu + MenuOption *customMenu = 0; Menu *gameDifficulty = new Menu( options ); @@ -124,2 +125,3 @@ Menu :: Menu( SFCave *p ) item->setNextMenu( options, false ); + customMenu = gameDifficulty->addMenuOption( "Custom", MENU_DIFFICULTY_CUSTOM ); item = gameDifficulty->addMenuOption( "Back", MENU_BACK ); @@ -138,2 +140,25 @@ Menu :: Menu( SFCave *p ) + // Custom Menu + Menu *custom = new Menu( gameDifficulty ); + Menu *updown = new Menu( custom ); + item = custom->addMenuOption( "Thrust", MENU_CUSTOM_THRUST ); + item->setNextMenu( updown ); + item = custom->addMenuOption( "Gravity", MENU_CUSTOM_GRAVITY ); + item->setNextMenu( updown ); + item = custom->addMenuOption( "Max Speed Up", MENU_CUSTOM_MAXSPEEDUP ); + item->setNextMenu( updown ); + item = custom->addMenuOption( "Max Speed Down", MENU_CUSTOM_MAXSPEEDDOWN ); + item->setNextMenu( updown ); + item = custom->addMenuOption( "Back", MENU_BACK ); + item->setNextMenu( gameDifficulty, false ); + customMenu->setNextMenu( custom ); + + // Up down menu + item = updown->addMenuOption( "Increase", MENU_CUSTOM_INCREASE ); + item = updown->addMenuOption( "Decrease", MENU_CUSTOM_DECREASE ); + item = updown->addMenuOption( "Save", MENU_CUSTOM_SAVE ); + item->setNextMenu( custom, false ); + item = updown->addMenuOption( "Cancel", MENU_CUSTOM_CANCEL ); + item->setNextMenu( custom, false ); + // Set static variables for menu selection up @@ -217,3 +242,2 @@ int Menu :: handleKeys( SDL_KeyboardEvent &key ) - statusText = ""; switch( key.keysym.sym ) @@ -278,4 +302,4 @@ int Menu :: handleKeys( SDL_KeyboardEvent &key ) { + statusText = ""; currentMenu = currentMenu->parentMenu; - printf( "HERE\n" ); @@ -288,5 +312,7 @@ int Menu :: handleKeys( SDL_KeyboardEvent &key ) { + statusText = ""; // select menu item int id = currentMenu->currentMenuOption->getMenuId(); -// // if the current item has a child menu then move to that menu + + // if the current item has a child menu then move to that menu Menu *next = currentMenu->currentMenuOption->getNextMenu(); @@ -298,8 +324,5 @@ int Menu :: handleKeys( SDL_KeyboardEvent &key ) initCurrentMenu(); -// return -1; } -// else - { + return id; - } @@ -315,3 +338,3 @@ int Menu :: handleKeys( SDL_KeyboardEvent &key ) -MenuOption *Menu :: addMenuOption( QString text, int id ) +MenuOption *Menu :: addMenuOption( string text, int 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 @@ -15,3 +15,3 @@ class MenuOption public: - MenuOption( QString text, int id ); + MenuOption( string text, int id ); ~MenuOption(); @@ -27,3 +27,3 @@ private: int menuId; - QString menuText; + string menuText; bool highlighted; @@ -42,3 +42,3 @@ public: int handleKeys( SDL_KeyboardEvent & ); - MenuOption *addMenuOption( QString text, int id ); + MenuOption *addMenuOption( string text, int id ); void resetToTopMenu(); @@ -46,3 +46,3 @@ public: - void setStatusText( QString text ) { statusText = text; } + void setStatusText( string text ) { statusText = text; } @@ -60,3 +60,3 @@ private: - QString statusText; + string statusText; 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 @@ -13,4 +13,4 @@ Player :: Player( int w, int h ) - thrustUp = 0.4; - thrustDown = 0.6; + thrust = 0.4; + gravity = 0.6; maxUpSpeed = 4.0; @@ -82,6 +82,3 @@ void Player :: drawTrails( SDL_Surface *screen ) { -// int r = (int) ((255.0/pos.x()) * (trail[i].x)); -// int g = (int) ((150.0/pos.x()) * (trail[i].x)); int c = (int)((150.0/50) * (50.0 - (pos.x() - trail[i].x() ) )); -// SDL_FillRect( screen, &trail[i], SDL_MapRGBA( screen->format, r, g, 0, 0 ) ); //(int)(1.5*c), 0, 255 ) ); boxRGBA( screen, trail[i].x(), trail[i].y(), trail[i].x() + 2, trail[i].y() + 2, 255, (int)(1.5*c), 0, c ); @@ -97,12 +94,12 @@ void Player :: move( bool up ) if ( up ) - thrust -= thrustUp; + currentThrust -= thrust; else - thrust += thrustDown; + currentThrust += gravity; - if ( thrust > maxDownSpeed ) - thrust = maxDownSpeed; - else if ( thrust < -maxUpSpeed ) - thrust = -maxUpSpeed; + if ( currentThrust > maxDownSpeed ) + currentThrust = maxDownSpeed; + else if ( currentThrust < -maxUpSpeed ) + currentThrust = -maxUpSpeed; - pos.moveBy( 0, (int)(thrust) ); + pos.moveBy( 0, (int)(currentThrust) ); } @@ -154,6 +151,6 @@ bool Player :: updateCrashing() -void Player :: setMovementInfo( double up, double down, double maxUp, double maxDown ) +void Player :: setMovementInfo( double up, double grav, double maxUp, double maxDown ) { - thrustUp = up; - thrustDown = down; + thrust = up; + gravity = grav; maxUpSpeed = maxUp; @@ -162 +159,126 @@ void Player :: setMovementInfo( double up, double down, double maxUp, double max + +void Player :: incValue( int valueType ) +{ + switch( valueType ) + { + case PLAYER_THRUST: + thrust += 0.1; + break; + case PLAYER_GRAVITY: + gravity += 0.1; + break; + case PLAYER_MAX_SPEED_UP: + maxUpSpeed += 0.1; + break; + case PLAYER_MAX_SPEED_DOWN: + maxDownSpeed += 0.1; + break; + } +} + +void Player :: decValue( int valueType ) +{ + switch( valueType ) + { + case PLAYER_THRUST: + thrust -= 0.1; + break; + case PLAYER_GRAVITY: + gravity -= 0.1; + break; + case PLAYER_MAX_SPEED_UP: + maxUpSpeed -= 0.1; + break; + case PLAYER_MAX_SPEED_DOWN: + maxDownSpeed -= 0.1; + break; + } +} + +void Player :: setValue( int valueType, double val ) +{ + switch( valueType ) + { + case PLAYER_THRUST: + thrust = val; + break; + case PLAYER_GRAVITY: + gravity = val; + break; + case PLAYER_MAX_SPEED_UP: + maxUpSpeed = val; + break; + case PLAYER_MAX_SPEED_DOWN: + maxDownSpeed = val; + break; + } +} + +double Player :: getValue( int valueType ) +{ + double val; + switch( valueType ) + { + case PLAYER_THRUST: + val = thrust; + break; + case PLAYER_GRAVITY: + val = gravity; + break; + case PLAYER_MAX_SPEED_UP: + val = maxUpSpeed; + break; + case PLAYER_MAX_SPEED_DOWN: + val = maxDownSpeed; + break; + } + + return val; +} + +string Player :: getValueTypeString( int valueType ) +{ + string val; + switch( valueType ) + { + case PLAYER_THRUST: + val = "thrust"; + break; + case PLAYER_GRAVITY: + val = "gravity"; + break; + case PLAYER_MAX_SPEED_UP: + val = "maxupspeed"; + break; + case PLAYER_MAX_SPEED_DOWN: + val = "maxdownspeed"; + break; + } + + return val; +} + +string Player :: getValueString( int valueType ) +{ + char val[50]; + switch( valueType ) + { + case PLAYER_THRUST: + sprintf( val, "Thrust - %lf", thrust ); + break; + case PLAYER_GRAVITY: + sprintf( val, "Gravity - %lf", gravity ); + break; + case PLAYER_MAX_SPEED_UP: + sprintf( val, "Max Speed Up - %lf", maxUpSpeed ); + break; + case PLAYER_MAX_SPEED_DOWN: + sprintf( val, "Max Speed Down - %lf", maxDownSpeed ); + break; + } + + string ret = val; + return ret; +} + 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 @@ -24,3 +24,9 @@ public: bool updateCrashing(); - void setMovementInfo( double up, double down, double maxUp, double maxDown ); + void setMovementInfo( double up, double grav, double maxUp, double maxDown ); + void incValue( int valType ); + void decValue( int valType ); + double getValue( int valueType ); + string getValueString( int valueType ); + string getValueTypeString( int valueType ); + void setValue( int valueType, double val ); @@ -38,6 +44,6 @@ private: Rect pos; - double thrust; + double currentThrust; - double thrustUp; - double thrustDown; + double thrust; + double gravity; double maxUpSpeed; 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 @@ -7,2 +7,4 @@ +// Defined in util.h +string getHomeDir(); @@ -18,11 +20,4 @@ Settings::Settings( char * env_file, char * env_dir ) { - char * homeDir = getenv( "HOME" );; - - if ( homeDir ) - { - envFile.append(homeDir); + envFile = getHomeDir(); envFile.append("/"); - } - else - printf( "Environment var HOME not set!\n" ); @@ -44,11 +39,4 @@ Settings::Settings() { - char * homeDir = getenv("HOME"); - - if ( homeDir) - { - envFile.append(homeDir); + envFile = getHomeDir(); envFile.append("/"); - } - else - printf( "Environment var HOME not set!\n" ); @@ -112,2 +100,14 @@ bool Settings::readSetting(const string key_str,unsigned long& result) +bool Settings::readSetting(const string key_str,double& result) +{ + string Buffer; + if (readSetting(key_str,Buffer)) + { + result = atof( Buffer.c_str() ); + return true; + } + else + return false; +} + bool Settings::readSetting(const string key_str,bool& result) @@ -161,2 +161,10 @@ void Settings::writeSetting(const string key_str,const bool value) +void Settings::writeSetting(const string key_str,const double value) +{ + char Buffer[30]; + + sprintf(Buffer,"%lf",value); + writeSetting(key_str,string(Buffer)); +} + void Settings::writeSetting(const string key_str,const int value) @@ -197,28 +205,17 @@ void Settings::writeSetting(const string key_str,const string value) // already exists then it will be overwritten. - - std::vector<string> FileEntries; FILE *fd=NULL,*ftemp=NULL; - char * dir_str; - char * dir_ptr; char buf[MAX_LINE_SIZE]; - char tempname[12]; - - dir_str = strdup(envFile.c_str()); - printf( "dir = %s, file - %s\n", dir_str, envFile.c_str() ); - if (dir_str) - { - // remove file from the directory string - dir_ptr = strrchr(dir_str, (int)'/'); - if (dir_ptr) - { - *dir_ptr = 0; - // make the directory path if it does not exist -// mkdir(dir_str, 777 ); + string tmp = getHomeDir() + "/tmpsfcave.dat"; // if file exists we need to save contents - if ((fd = fopen(envFile.c_str(), "r")) != NULL) + fd = fopen( envFile.c_str(), "r" ); + ftemp = fopen( tmp.c_str(), "w" ); + if ( fd != NULL && ftemp != NULL ) { while (fgets(buf, MAX_LINE_SIZE-1, fd)) - FileEntries.push_back(string(buf)); + { + if ( strncmp( buf, key_str.c_str(), key_str.size() ) != 0 ) + fprintf( ftemp, "%s", buf ); + } fclose(fd); @@ -226,8 +223,12 @@ void Settings::writeSetting(const string key_str,const string value) - char *home = getenv( "HOME" ); - string tmp; - if ( home ) - tmp = home + string( "/" ) + "tmpsfcave.dat"; - else - tmp = "./tmpsfcave.dat"; + if ( ftemp != NULL ) + { + fprintf(ftemp, "%s\t%s\n", key_str.c_str(),value.c_str()); + fclose( ftemp ); + + remove(envFile.c_str()); + rename( tmp.c_str(), envFile.c_str() ); + } +/* + string tmp = getHomeDir() + "/tmpsfcave.dat"; strcpy(tempname,tmp.c_str() ); @@ -256,6 +257,2 @@ void Settings::writeSetting(const string key_str,const string value) fclose(ftemp); - - remove(envFile.c_str()); - - rename( tempname, envFile.c_str() ); } @@ -267,2 +264,3 @@ void Settings::writeSetting(const string key_str,const string value) } +*/ } 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 @@ -34,2 +34,3 @@ public: bool readSetting(const string key_str,unsigned long& result); + bool readSetting(const string key_str,double & result); bool readSetting(const string key_str,bool& result); @@ -41,2 +42,3 @@ public: void writeSetting(const string key_str,const unsigned long result); + void writeSetting(const string key_str,const double value); void writeSetting(const string key_str,const bool value); 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 @@ -28,5 +28,5 @@ void start( int argc, char *argv[] ) { - FontHandler::init(); - SFCave app( argc, argv ); - FontHandler::cleanUp(); + SFCave *app = new SFCave( argc, argv ); + app->mainEventLoop(); + delete app; } @@ -45,2 +45,5 @@ SFCave :: SFCave( int argc, char *argv[] ) { + setupOK = false; + + // Load settings string diff = loadSetting( "GameDifficulty", "Easy" ); @@ -48,6 +51,8 @@ SFCave :: SFCave( int argc, char *argv[] ) musicPath = loadSetting( "MusicPath", SOUND_PATH ); - printf( "musicPath %s\n", musicPath.c_str() ); musicType = loadSetting( "MusicType", "mod,ogg" ); + bool soundOn = loadBoolSetting( "SoundOn", true ); + bool musicOn = loadBoolSetting( "MusicOn", true ); if ( musicPath[musicPath.size()-1] != '/' ) musicPath += "/"; + printf( "musicPath %s\n", musicPath.c_str() ); @@ -56,2 +61,9 @@ SFCave :: SFCave( int argc, char *argv[] ) + // Init font handler + if ( !FontHandler::init() ) + { + printf( "Unable to initialise fonts!\n" ); + return; + } + // Init SoundHandler @@ -60,2 +72,5 @@ SFCave :: SFCave( int argc, char *argv[] ) + SoundHandler :: setSoundsOn( soundOn ); + SoundHandler :: setMusicOn( musicOn ); + currentGame = Game::createGame( this, WIDTH, HEIGHT, game, diff ); @@ -64,4 +79,7 @@ SFCave :: SFCave( int argc, char *argv[] ) currentGame->setSeed(-1); + + // Create menu menu = new Menu( this ); + // Create help screen help = new Help( this ); @@ -70,6 +88,4 @@ SFCave :: SFCave( int argc, char *argv[] ) showFps = false; - mainEventLoop(); - SoundHandler :: cleanUp(); - SDL_Quit(); + setupOK = true; } @@ -84,12 +100,13 @@ SFCave :: ~SFCave() - SDL_FreeSurface( screen ); -} - + if ( help ) + delete help; -void SFCave :: drawGameScreen( ) -{ - //ClearScreen(screen, "Titletext"); + SDL_FreeSurface( screen ); + FontHandler::cleanUp(); + SoundHandler :: cleanUp(); + SDL_Quit(); } + void SFCave :: initSDL( int argc, char *argv[] ) @@ -100,5 +117,3 @@ void SFCave :: initSDL( int argc, char *argv[] ) - - - /* Initialize SDL */ + // Initialize SDL if ( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0 ) { @@ -107,26 +122,31 @@ void SFCave :: initSDL( int argc, char *argv[] ) } - atexit(SDL_Quit); - /* Alpha blending doesn't work well at 8-bit color */ video_bpp = 16; - if ( !SDL_VideoModeOK(WIDTH, HEIGHT, 16, SDL_DOUBLEBUF) ) + if ( !SDL_VideoModeOK(WIDTH, HEIGHT, video_bpp, SDL_DOUBLEBUF) ) printf( "No double buffering\n" ); - videoflags = SDL_HWSURFACE | SDL_SRCALPHA;//|| SDL_DOUBLEBUF;// | SDL_SRCALPHA | SDL_RESIZABLE; - while ( argc > 1 ) { + videoflags = SDL_HWSURFACE | SDL_SRCALPHA; + while ( argc > 1 ) + { --argc; - if ( strcmp(argv[argc-1], "-bpp") == 0 ) { + if ( strcmp(argv[argc-1], "-bpp") == 0 ) + { video_bpp = atoi(argv[argc]); --argc; - } else - if ( strcmp(argv[argc], "-hw") == 0 ) { + } + else if ( strcmp(argv[argc], "-hw") == 0 ) + { videoflags |= SDL_HWSURFACE; - } else - if ( strcmp(argv[argc], "-warp") == 0 ) { + } + else if ( strcmp(argv[argc], "-warp") == 0 ) + { videoflags |= SDL_HWPALETTE; - } else - if ( strcmp(argv[argc], "-fullscreen") == 0 ) { + } + else if ( strcmp(argv[argc], "-fullscreen") == 0 ) + { videoflags |= SDL_FULLSCREEN; - } else { + } + else if ( strcmp(argv[argc], "-h") == 0 ) + { fprintf(stderr, @@ -138,5 +158,6 @@ void SFCave :: initSDL( int argc, char *argv[] ) - /* Set 240x320 video mode */ - if ( (screen=SDL_SetVideoMode(WIDTH,HEIGHT,video_bpp,videoflags)) == NULL ) { - fprintf(stderr, "Couldn't set %ix%i video mode: %s\n",WIDTH,HEIGHT,SDL_GetError()); + // Set 240x320 video mode + if ( (screen = SDL_SetVideoMode( WIDTH,HEIGHT,video_bpp,videoflags )) == NULL ) + { + printf( "Couldn't set %ix%i video mode: %s\n",WIDTH,HEIGHT,SDL_GetError() ); exit(2); @@ -144,6 +165,6 @@ void SFCave :: initSDL( int argc, char *argv[] ) - /* Use alpha blending */ - SDL_SetAlpha(screen, SDL_RLEACCEL, 0); + // Use alpha blending + //SDL_SetAlpha(screen, SDL_RLEACCEL, 0); - /* Set title for window */ + // Set title for window SDL_WM_SetCaption("SFCave","SFCave"); @@ -153,7 +174,7 @@ void SFCave :: mainEventLoop() { - SDL_Event event; - int done; + if ( !setupOK ) + return; - /* Wait for a keystroke */ - done = 0; + // Wait for a keystroke + finish = false; state = 0; @@ -162,27 +183,30 @@ void SFCave :: mainEventLoop() - int FPS = 0; - bool limitFPS = true; + FPS = 0; actualFPS = 0; - long time1 = 0; - long start; - long end; -// long nrTimes = 0; - struct timeb tp; - while ( !done ) + time1 = 0; + + limitFPS = true; + while ( !finish ) { // calc FPS - ftime( &tp ); - start =(tp.time%10000)*10000 + tp.millitm; -// printf( "start = %ld, time1 - %d, st-tm - %d, tp.time - %ld\n", start, time1, start-time1, (tp.time%1000)*1000 ); - if ( start - time1 >= 1000 ) - { - actualFPS = FPS; -// printf( "%d FPS = %d\n", nrTimes++, actualFPS ); - FPS = 0; - time1 = start; - } - else - FPS ++; + calcFPS(); SDL_FillRect( screen, 0, 0 ); + + handleGameState( ); + + SDL_Flip( screen ); + + if ( limitFPS ) + FPSDelay(); + else + SDL_Delay( 5 ); + + handleEvents(); + } +} + + +void SFCave :: handleGameState() +{ switch( state ) @@ -199,3 +223,2 @@ void SFCave :: mainEventLoop() case STATE_NEWGAME: - printf( "STATE_NEWGAME\n" ); currentGame->setReplay( false ); @@ -206,3 +229,2 @@ void SFCave :: mainEventLoop() case STATE_REPLAY: - printf( "STATE_NEWGAME\n" ); currentGame->setReplay( true ); @@ -214,6 +236,2 @@ void SFCave :: mainEventLoop() case STATE_CRASHING: - currentGame->update( state ); - currentGame->draw( screen ); - break; - case STATE_CRASHED: @@ -221,4 +239,2 @@ void SFCave :: mainEventLoop() currentGame->draw( screen ); - - // Display Game Over message break; @@ -226,33 +242,12 @@ void SFCave :: mainEventLoop() case STATE_QUIT: - done = 1; + finish = true; break; } +} - /* Show */ -// if ( state != STATE_CRASHED ) - SDL_Flip( screen ); -// SDL_UpdateRect(screen, 0, 0, 0, 0); - - if ( limitFPS ) +void SFCave :: handleEvents() { - /* Slow down polling - limit to x FPS*/ - ftime( &tp ); - end = abs((tp.time%10000)*10000 + tp.millitm); - if ( end-start < (1000/maxFPS) ) - { -// printf( "end - %ld, timetaken for frame = %ld, sleeping for %ld %d\n", end, end-start, (1000/maxFPS)-(end-start), actualFPS ); - if ( (1000/maxFPS)-(end-start) > 500 ) - { - // Should never happen but in case it does sleep for 5 seconds - printf( "WARNING WILL ROBINSON! delay = %ld - start %ld, end %ld\n", (1000/maxFPS)-(end-start), start, end ); - SDL_Delay( 5 ); - } - else - SDL_Delay((1000/maxFPS)-(end-start) ); - } - } - else - SDL_Delay( 5 ); + SDL_Event event; - /* Check for events */ + // Check for events while ( SDL_PollEvent(&event) ) @@ -263,6 +258,9 @@ void SFCave :: mainEventLoop() case SDL_KEYUP: + { // Escape keypress quits the app - if ( event.key.keysym.sym != SDLK_ESCAPE ) + if ( event.key.keysym.sym == SDLK_ESCAPE ) { -// printf( "Key Pressed was %d %s\n", event.key.keysym.sym, SDL_GetKeyName( event.key.keysym.sym ) ); + finish = true; + break; + } @@ -306,3 +304,2 @@ void SFCave :: mainEventLoop() case SDLK_f: - printf( "showFPS - %d\n", showFps ); if ( event.type == SDL_KEYDOWN ) @@ -315,22 +312,2 @@ void SFCave :: mainEventLoop() - case SDLK_p: - if ( event.type == SDL_KEYDOWN ) - { - maxFPS ++; - printf( "maxFPS - %d\n", maxFPS ); - } - break; - - case SDLK_o: - if ( event.type == SDL_KEYDOWN ) - { - maxFPS --; - printf( "maxFPS - %d\n", maxFPS ); - } - break; - - case SDLK_n: - currentGame->getTerrain()->offset++; - break; - default: @@ -344,5 +321,4 @@ void SFCave :: mainEventLoop() - case SDL_QUIT: - done = 1; + finish = true; break; @@ -353,3 +329,2 @@ void SFCave :: mainEventLoop() } -} @@ -367,3 +342,2 @@ void SFCave :: changeState( int s ) string musicFile = chooseRandomFile( musicPath, musicType ); - printf("playing music %s\n", musicFile.c_str() ); SoundHandler :: setMusicVolume( 128 ); @@ -376,3 +350,3 @@ void SFCave :: changeState( int s ) // Start the in game music - string musicFile = SOUND_PATH "ingame.mod"; + string musicFile = INGAME_MUSIC; SoundHandler :: playMusic( musicFile ); @@ -410,8 +384,3 @@ void SFCave :: handleMenuSelect( int menuId ) { -#ifdef QWS - QString replayFile = getenv( "HOME" ); -#else - QString replayFile = "."; -#endif - replayFile += string( "/" ) + currentGame->getGameName() + ".replay"; + string replayFile = getHomeDir() + "/" + currentGame->getGameName() + ".replay"; @@ -427,8 +396,3 @@ void SFCave :: handleMenuSelect( int menuId ) { -#ifdef QWS - QString replayFile = getenv( "HOME" ); -#else - QString replayFile = "."; -#endif - replayFile += string( "/" ) + currentGame->getGameName() + ".replay"; + string replayFile = getHomeDir() + "/" + currentGame->getGameName() + ".replay"; @@ -496,4 +460,10 @@ void SFCave :: handleMenuSelect( int menuId ) + case MENU_DIFFICULTY_CUSTOM: + currentGame->setDifficulty( MENU_DIFFICULTY_CUSTOM ); + saveSetting( "GameDifficulty", "Custom" ); + break; + case MENU_SOUND_ON: SoundHandler :: setSoundsOn( true ); + saveSetting( "SoundOn", "true" ); break; @@ -502,2 +472,3 @@ void SFCave :: handleMenuSelect( int menuId ) SoundHandler :: setSoundsOn( false ); + saveSetting( "SoundOn", "false" ); break; @@ -506,2 +477,3 @@ void SFCave :: handleMenuSelect( int menuId ) SoundHandler :: setMusicOn( true ); + saveSetting( "MusicOn", "true" ); break; @@ -510,2 +482,43 @@ void SFCave :: handleMenuSelect( int menuId ) SoundHandler :: setMusicOn( false ); + saveSetting( "MusicOn", "false" ); + break; + + case MENU_CUSTOM_THRUST: + customPlayerMenuVal = PLAYER_THRUST; + origValue = currentGame->getPlayer()->getValue( customPlayerMenuVal ); + setMenuStatusText( currentGame->getPlayer()->getValueString( customPlayerMenuVal ) ); + break; + case MENU_CUSTOM_GRAVITY: + customPlayerMenuVal = PLAYER_GRAVITY; + origValue = currentGame->getPlayer()->getValue( customPlayerMenuVal ); + setMenuStatusText( currentGame->getPlayer()->getValueString( customPlayerMenuVal ) ); + break; + case MENU_CUSTOM_MAXSPEEDUP: + customPlayerMenuVal = PLAYER_MAX_SPEED_UP; + origValue = currentGame->getPlayer()->getValue( customPlayerMenuVal ); + setMenuStatusText( currentGame->getPlayer()->getValueString( customPlayerMenuVal ) ); + break; + case MENU_CUSTOM_MAXSPEEDDOWN: + customPlayerMenuVal = PLAYER_MAX_SPEED_DOWN; + origValue = currentGame->getPlayer()->getValue( customPlayerMenuVal ); + setMenuStatusText( currentGame->getPlayer()->getValueString( customPlayerMenuVal ) ); + break; + case MENU_CUSTOM_INCREASE: + currentGame->getPlayer()->incValue( customPlayerMenuVal ); + setMenuStatusText( currentGame->getPlayer()->getValueString( customPlayerMenuVal ) ); + break; + case MENU_CUSTOM_DECREASE: + currentGame->getPlayer()->decValue( customPlayerMenuVal ); + setMenuStatusText( currentGame->getPlayer()->getValueString( customPlayerMenuVal ) ); + break; + case MENU_CUSTOM_SAVE: + { + // save settings + string key = currentGame->getGameName() + "_custom_player_" + currentGame->getPlayer()->getValueTypeString( customPlayerMenuVal ); + saveSetting( key, currentGame->getPlayer()->getValue( customPlayerMenuVal ) ); + + break; + } + case MENU_CUSTOM_CANCEL: + currentGame->getPlayer()->setValue( customPlayerMenuVal, origValue ); break; @@ -535,2 +548,14 @@ void SFCave :: saveSetting( string key, int val ) +void SFCave :: saveSetting( string key, long val ) +{ + Settings cfg( "sfcave-sdl" ); + cfg.writeSetting( key, val ); +} + +void SFCave :: saveSetting( string key, double val ) +{ + Settings cfg( "sfcave-sdl" ); + cfg.writeSetting( key, val ); +} + string SFCave :: loadSetting( string key, string defaultVal ) @@ -546 +571,63 @@ string SFCave :: loadSetting( string key, string defaultVal ) } + +bool SFCave :: loadBoolSetting( string key, bool defaultVal ) +{ + bool val = defaultVal; + Settings cfg( "sfcave-sdl" ); + cfg.readSetting( key, val ); + + return val; +} + +int SFCave :: loadIntSetting( string key, int defaultVal ) +{ + int val = defaultVal; + Settings cfg( "sfcave-sdl" ); + cfg.readSetting( key, val ); + + return val; +} + +double SFCave :: loadDoubleSetting( string key, double defaultVal ) +{ + double val = defaultVal; + Settings cfg( "sfcave-sdl" ); + cfg.readSetting( key, val ); + + return val; +} + + +void SFCave :: calcFPS() +{ + struct timeb tp; + ftime( &tp ); + start =(tp.time%10000)*10000 + tp.millitm; + if ( start - time1 >= 1000 ) + { + actualFPS = FPS; + FPS = 0; + time1 = start; + } + else + FPS ++; +} + +void SFCave :: FPSDelay() +{ + struct timeb tp; + // Slow down polling - limit to x FPS + ftime( &tp ); + end = abs((tp.time%10000)*10000 + tp.millitm); + if ( end-start < (1000/maxFPS) ) + { + if ( (1000/maxFPS)-(end-start) > 500 ) + { + // Should never happen but in case it does sleep for 5 seconds + printf( "WARNING WILL ROBINSON! delay = %ld - start %ld, end %ld\n", (1000/maxFPS)-(end-start), start, end ); + SDL_Delay( 5 ); + } + else + SDL_Delay((1000/maxFPS)-(end-start) ); + } +} 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 @@ -17,3 +17,2 @@ public: - void drawGameScreen(); void initSDL( int argc, char *argv[] ); @@ -32,5 +31,12 @@ public: void saveSetting( string key, int val ); + void saveSetting( string key, long val ); + void saveSetting( string key, double val ); string loadSetting( string key, string defaultVal = "" ); + bool loadBoolSetting( string key, bool defaultVal); + int loadIntSetting( string key, int defaultVal ); + double loadDoubleSetting( string key, double defaultVal ); + private: SDL_Surface *screen; + bool setupOK; @@ -40,4 +46,2 @@ private: int state; - int maxFPS; - int actualFPS; bool showFps; @@ -45,4 +49,22 @@ private: string musicType; + bool finish; + + bool limitFPS; + int maxFPS; + int actualFPS; + int FPS; + long time1; + long start; + long end; + + // This is used when the user is setting the custom + // values in the menu + int customPlayerMenuVal; + double origValue; void handleMenuSelect( int menuId ); + void handleGameState(); + void handleEvents(); + void calcFPS(); + void FPSDelay(); }; 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 @@ -41,2 +41,15 @@ void SFCaveGame :: init() break; + case MENU_DIFFICULTY_CUSTOM: + { + // Read custom difficulty settings for this game + blockDistance = parent->loadIntSetting( "SFCave_custom_blockdistance", 50 ); + + double thrust = parent->loadDoubleSetting( "SFCave_custom_player_thrust", 0.4 ); + double gravity = parent->loadDoubleSetting( "SFCave_custom_player_gravity", 0.6 ); + double maxUp = parent->loadDoubleSetting( "SFCave_custom_player_maxupspeed", 4.0 ); + double maxDown = parent->loadDoubleSetting( "SFCave_custom_player_maxdownspeed", 5.0 ); + player->setMovementInfo( thrust, gravity, maxUp, maxDown ); + + break; + } } @@ -70,3 +83,2 @@ void SFCaveGame :: update( int state ) { -// printf( "Crashed!\n" ); parent->changeState( STATE_CRASHING ); 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 @@ -33,2 +33,3 @@ bool SoundHandler :: init( ) soundOn = true;
+ musicOn = true;
@@ -40,3 +41,5 @@ void SoundHandler :: cleanUp() // Free audio sounds
+ if ( sounds[SND_EXPLOSION] )
Mix_FreeChunk( sounds[SND_EXPLOSION] );
+ if ( sounds[SND_THRUST] )
Mix_FreeChunk( sounds[SND_THRUST] );
@@ -54,3 +57,3 @@ int SoundHandler :: playSound( int soundNr, int channel, int nrLoops, int playBe - if ( soundNr >= NR_SOUNDS )
+ if ( soundNr >= NR_SOUNDS || !sounds[soundNr] )
return -1;
@@ -103,3 +106,3 @@ void SoundHandler :: playMusic( bool fade ) {
- if ( !soundOn )
+ if ( !musicOn )
return;
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 @@ -223 +223,73 @@ void StarField :: draw( SDL_Surface *screen, int w, int h ) }
+
+
+
+// Test
+#ifdef DEBUG_STARS
+SDL_Surface *screen;
+StarField *stars;
+
+void go()
+{
+ /* Initialize SDL */
+ if ( SDL_Init(SDL_INIT_VIDEO) < 0 )
+ {
+ fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
+ exit(1);
+ }
+ atexit(SDL_Quit);
+
+ int videoflags = SDL_SWSURFACE ;
+
+ if ( (screen=SDL_SetVideoMode(240, 320,32,videoflags)) == NULL )
+ {
+ fprintf(stderr, "Couldn't set %ix%i video mode: %s\n",240,320,SDL_GetError());
+ exit(2);
+ }
+
+ stars = new StarField( false, 200 );
+
+ bool done = false;
+ while ( !done )
+ {
+ SDL_FillRect( screen, 0, 0 );
+ stars->draw( screen );
+ stars->move( );
+
+ SDL_Flip( screen );
+
+ SDL_Delay( 10 );
+
+ SDL_Event event;
+ while ( SDL_PollEvent(&event) )
+ {
+ switch (event.type)
+ {
+ case SDL_KEYDOWN:
+ // Escape keypress quits the app
+ if ( event.key.keysym.sym != SDLK_ESCAPE )
+ {
+ break;
+ }
+ case SDL_QUIT:
+ done = 1;
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ }
+
+
+
+
+#ifdef __cplusplus
+extern "C"
+#endif
+int main( int argc, char *argv[] )
+{
+ go();
+}
+
+#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 @@ -49,2 +49,3 @@ void Terrain :: initTerrain() SDL_FillRect( terrainSurface, 0, 0 ); + // Draw Terrain into surface @@ -93,3 +94,2 @@ void Terrain :: moveTerrain( int amountToMove ) -// printf( "offset - %d, speed - %d\n", offset, speed ); if ( offset >= segSize ) @@ -197,3 +197,2 @@ void Terrain :: drawTerrain( SDL_Surface *screen ) dst.h = sHeight; -// dst.h = maxHeight; @@ -206,18 +205,2 @@ void Terrain :: drawTerrain( SDL_Surface *screen ) stars->draw( screen ); - -// dst.y = sHeight - maxHeight; -// dst2.y = sHeight - maxHeight; -// SDL_BlitSurface(terrainSurface, &dst, screen, &dst2 ); - -/* - for ( int i = 0 ; i < MAPSIZE ; ++i ) - { - int x1 = (i*segSize) - (offset*speed); - int x2 = ((i+1)*segSize)-(offset*speed); - if ( x2 >= sWidth ) - x2 = sWidth-1; - aalineRGBA( screen, x1, mapTop[i], x2, mapTop[i+1], 0, 220, 0, 255 ); - aalineRGBA( screen, x1, mapBottom[i], x2, mapBottom[i+1], 0, 220, 0, 255 ); - } -*/ } @@ -228,2 +211,3 @@ bool Terrain :: checkCollision( int x, int y, int h ) return true; + // First get segment that matches x @@ -249,3 +233,3 @@ void go() { - /* Initialize SDL */ + // Initialize SDL if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) 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 @@ -37,3 +37,3 @@ Uint32 getpixel(SDL_Surface *surface, int x, int y) -const char *chooseRandomFile( string path, string fileType )
+string chooseRandomFile( string path, string fileType )
{
@@ -52,6 +52,4 @@ const char *chooseRandomFile( string path, string fileType ) string tmp = file.substr( pos );
- printf( "pos = %d, tmp =%s\n", pos, tmp.c_str() );
if ( tmp.size() > 0 && fileType.find( tmp ) != -1 )
{
- printf( "Matching <%s> - %s with <%s>\n", file.substr( pos ).c_str(), file.c_str(), fileType.c_str() );
files.push_back( file );
@@ -62,3 +60,16 @@ const char *chooseRandomFile( string path, string fileType ) closedir( d );
- return files[nextInt( files.size() )].c_str();
+ return files[nextInt( files.size() )];
+}
+
+
+string getHomeDir()
+{
+ string home;
+#ifdef QWS
+ home = getenv( "HOME" );
+#else
+ home = ".";
+#endif
+
+ return home;
}
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 @@ -7,4 +7,4 @@ using namespace std; Uint32 getpixel(SDL_Surface *surface, int x, int y);
-const char *chooseRandomFile( string path, string fileType );
-
+string chooseRandomFile( string path, string fileType );
+string getHomeDir();
#endif
|