[Super-tux-commit] supertux/src gameloop.cpp,1.70,1.71 gameloop.h,1.38,1.39 player.cpp,1.37,1.38 pla
Brought to you by:
wkendrick
From: Ingo R. <gr...@us...> - 2004-04-16 16:52:27
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12476 Modified Files: gameloop.cpp gameloop.h player.cpp player.h scene.cpp scene.h setup.cpp setup.h special.cpp text.h worldmap.cpp worldmap.h Log Message: - some more savegame stuff - added status on worldmap - made worldmap start on 'start game' - moved lives, distros, score into PlayerStatus Index: scene.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/scene.cpp,v retrieving revision 1.20 retrieving revision 1.21 diff -u -d -r1.20 -r1.21 --- scene.cpp 11 Apr 2004 15:33:53 -0000 1.20 +++ scene.cpp 16 Apr 2004 16:52:18 -0000 1.21 @@ -15,6 +15,13 @@ PlayerStatus player_status; +PlayerStatus::PlayerStatus() + : score(0), + distros(0), + lives(3) +{ +} + // FIXME: Move this into a view class float scroll_x; Index: player.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/player.h,v retrieving revision 1.26 retrieving revision 1.27 diff -u -d -r1.26 -r1.27 --- player.h 13 Apr 2004 02:19:13 -0000 1.26 +++ player.h 16 Apr 2004 16:52:18 -0000 1.27 @@ -94,9 +94,6 @@ { public: player_keymap_type keymap; - int lives; - int score; - int distros; player_input_type input; bool got_coffee; Index: setup.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/setup.h,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- setup.h 10 Apr 2004 18:56:17 -0000 1.15 +++ setup.h 16 Apr 2004 16:52:18 -0000 1.16 @@ -36,8 +36,6 @@ void st_abort(const std::string& reason, const std::string& details); void process_options_menu(void); -void process_save_game_menu(); - /** Return true if the gameloop() was entered, false otherwise */ bool process_load_game_menu(); Index: special.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/special.cpp,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- special.cpp 13 Apr 2004 18:24:06 -0000 1.17 +++ special.cpp 16 Apr 2004 16:52:18 -0000 1.18 @@ -307,8 +307,8 @@ } else if (kind == UPGRADE_1UP) { - if(pplayer->lives < MAX_LIVES) { - pplayer->lives++; + if(player_status.lives < MAX_LIVES) { + player_status.lives++; play_sound(sounds[SND_LIFEUP], SOUND_CENTER_SPEAKER); } } Index: worldmap.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/worldmap.cpp,v retrieving revision 1.25 retrieving revision 1.26 diff -u -d -r1.25 -r1.26 --- worldmap.cpp 15 Apr 2004 19:08:01 -0000 1.25 +++ worldmap.cpp 16 Apr 2004 16:52:18 -0000 1.26 @@ -18,6 +18,7 @@ // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include <iostream> +#include <fstream> #include <vector> #include <assert.h> #include "globals.h" @@ -270,6 +271,7 @@ { Level level; LispReader reader(lisp_cdr(element)); + level.solved = false; reader.read_string("name", &level.name); reader.read_int("x", &level.x); reader.read_int("y", &level.y); @@ -438,10 +440,17 @@ { std::cout << "Enter the current level: " << i->name << std::endl;; halt_music(); - GameSession session(datadir + "levels/default/" + i->name, + GameSession session(datadir + "levels/" + i->name, 1, ST_GL_LOAD_LEVEL_FILE); session.run(); + + if (1) // FIXME: insert exit status checker here + i->solved = true; + play_music(song, 1); + show_menu = 0; + menu_reset(); + savegame(std::string(st_save_dir) + "/slot1.stsg"); return; } } @@ -499,11 +508,54 @@ } tux->draw(offset); + draw_status(); +} + +void +WorldMap::draw_status() +{ + char str[80]; + sprintf(str, "%d", player_status.score); + white_text->draw("SCORE", 0, 0); + gold_text->draw(str, 96, 0); + + sprintf(str, "%d", player_status.distros); + white_text->draw_align("COINS", 320-64, 0, A_LEFT, A_TOP); + gold_text->draw_align(str, 320+64, 0, A_RIGHT, A_TOP); + + white_text->draw("LIVES", 480, 0); + if (player_status.lives >= 5) + { + sprintf(str, "%dx", player_status.lives); + gold_text->draw(str, 585, 0); + tux_life->draw(565+(18*3), 0); + } + else + { + for(int i= 0; i < player_status.lives; ++i) + tux_life->draw(565+(18*i),0); + } + + if (!tux->is_moving()) + { + for(Levels::iterator i = levels.begin(); i != levels.end(); ++i) + { + if (i->x == tux->get_tile_pos().x && + i->y == tux->get_tile_pos().y) + { + white_text->draw_align(i->name.c_str(), screen->w/2, screen->h, A_HMIDDLE, A_BOTTOM); + break; + } + } + } } void WorldMap::display() { + show_menu = 0; + menu_reset(); + quit = false; song = load_song(datadir + "/music/" + music); @@ -536,6 +588,32 @@ free_music(song); } +void +WorldMap::savegame(const std::string& filename) +{ + std::ofstream out(filename.c_str()); + + out << "(supertux-savegame\n" + << " (version 1)\n" + << " (lives " << player_status.lives << ")\n" + << " (score " << player_status.score << ")\n" + << " (distros " << player_status.distros << ")\n" + << " (tux (x " << tux->get_tile_pos().x << ") (y " << tux->get_tile_pos().y << ")\n" + << " (levels\n"; + + for(Levels::iterator i = levels.begin(); i != levels.end(); ++i) + { + if (i->solved) + { + out << " (level (name \"" << i->name << "\")\n" + << " (solved #t))\n"; + } + } + + out << " )\n" + << " )\n\n;; EOF ;;" << std::endl; +} + } // namespace WorldMapNS void worldmap_run() Index: scene.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/scene.h,v retrieving revision 1.23 retrieving revision 1.24 diff -u -d -r1.23 -r1.24 --- scene.h 11 Apr 2004 15:33:53 -0000 1.23 +++ scene.h 16 Apr 2004 16:52:18 -0000 1.24 @@ -23,8 +23,12 @@ { int score; int distros; + int lives; + int next_level; int score_multiplier; + + PlayerStatus(); }; extern PlayerStatus player_status; Index: worldmap.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/worldmap.h,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- worldmap.h 15 Apr 2004 19:08:02 -0000 1.14 +++ worldmap.h 16 Apr 2004 16:52:18 -0000 1.15 @@ -132,6 +132,7 @@ int x; int y; std::string name; + bool solved; }; typedef std::vector<Level> Levels; @@ -143,6 +144,8 @@ bool enter_level; Point offset; + + void draw_status(); public: WorldMap(); ~WorldMap(); @@ -166,6 +169,8 @@ /** Check if it is possible to walk from \a pos into \a direction, if possible, write the new position to \a new_pos */ bool path_ok(Direction direction, Point pos, Point* new_pos); + + void savegame(const std::string& filename); }; } // namespace WorldMapNS Index: gameloop.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameloop.cpp,v retrieving revision 1.70 retrieving revision 1.71 diff -u -d -r1.70 -r1.71 --- gameloop.cpp 13 Apr 2004 18:39:56 -0000 1.70 +++ gameloop.cpp 16 Apr 2004 16:52:17 -0000 1.71 @@ -117,9 +117,6 @@ time_left.init(true); start_timers(); - - if(st_gl_mode == ST_GL_LOAD_GAME) - loadgame(levelnb); } GameSession::~GameSession() @@ -130,8 +127,6 @@ void GameSession::levelintro(void) { - Player& tux = *world->get_tux(); - char str[60]; /* Level Intro: */ clearscreen(0, 0, 0); @@ -145,7 +140,7 @@ sprintf(str, "by %s", world->get_level()->author.c_str()); red_text->drawf(str, 0, 256, A_HMIDDLE, A_TOP, 1); - sprintf(str, "TUX x %d", tux.lives); + sprintf(str, "TUX x %d", player_status.lives); white_text->drawf(str, 0, 288, A_HMIDDLE, A_TOP, 1); flipscreen(); @@ -267,7 +262,7 @@ break; case SDLK_l: if(debug_mode) - --tux.lives; + --player_status.lives; break; case SDLK_s: if(debug_mode) @@ -375,7 +370,7 @@ /* No more lives!? */ - if (tux.lives < 0) + if (player_status.lives < 0) { if(st_gl_mode != ST_GL_TEST) drawendscreen(); @@ -538,10 +533,6 @@ { process_options_menu(); } - else if(current_menu == save_game_menu ) - { - process_save_game_menu(); - } else if(current_menu == load_game_menu ) { process_load_game_menu(); @@ -658,7 +649,6 @@ void GameSession::drawstatus() { - Player& tux = *world->get_tux(); char str[60]; sprintf(str, "%d", player_status.score); @@ -696,7 +686,7 @@ gold_text->draw(str, screen->h + 60, 40, 1); } - for(int i= 0; i < tux.lives; ++i) + for(int i= 0; i < player_status.lives; ++i) { tux_life->draw(565+(18*i),20); } @@ -714,7 +704,7 @@ sprintf(str, "SCORE: %d", player_status.score); gold_text->drawf(str, 0, 224, A_HMIDDLE, A_TOP, 1); - sprintf(str, "DISTROS: %d", player_status.distros); + sprintf(str, "COINS: %d", player_status.distros); gold_text->drawf(str, 0, 256, A_HMIDDLE, A_TOP, 1); flipscreen(); @@ -744,100 +734,6 @@ wait_for_event(event,2000,5000,true); } -void -GameSession::savegame(int) -{ -#if 0 - char savefile[1024]; - FILE* fi; - unsigned int ui; - - sprintf(savefile,"%s/slot%d.save",st_save_dir,slot); - - fi = fopen(savefile, "wb"); - - if (fi == NULL) - { - fprintf(stderr, "Warning: I could not open the slot file "); - } - else - { - fputs(level_subset, fi); - fputs("\n", fi); - fwrite(&level,sizeof(int),1,fi); - fwrite(&score,sizeof(int),1,fi); - fwrite(&distros,sizeof(int),1,fi); - fwrite(&scroll_x,sizeof(float),1,fi); - //FIXME:fwrite(&tux,sizeof(Player),1,fi); - //FIXME:timer_fwrite(&tux.invincible_timer,fi); - //FIXME:timer_fwrite(&tux.skidding_timer,fi); - //FIXME:timer_fwrite(&tux.safe_timer,fi); - //FIXME:timer_fwrite(&tux.frame_timer,fi); - timer_fwrite(&time_left,fi); - ui = st_get_ticks(); - fwrite(&ui,sizeof(int),1,fi); - } - fclose(fi); -#endif -} - -void -GameSession::loadgame(int) -{ -#if 0 - char savefile[1024]; - char str[100]; - FILE* fi; - unsigned int ui; - - sprintf(savefile,"%s/slot%d.save",st_save_dir,slot); - - fi = fopen(savefile, "rb"); - - if (fi == NULL) - { - fprintf(stderr, "Warning: I could not open the slot file "); - - } - else - { - fgets(str, 100, fi); - strcpy(level_subset, str); - level_subset[strlen(level_subset)-1] = '\0'; - fread(&level,sizeof(int),1,fi); - - world->set_defaults(); - world->get_level()->cleanup(); - world->arrays_free(); - world->get_level()->free_gfx(); - world->get_level()->free_song(); - - if(world->get_level()->load(level_subset,level) != 0) - exit(1); - - world->activate_bad_guys(); - world->activate_particle_systems(); - world->get_level()->load_gfx(); - world->get_level()->load_song(); - - levelintro(); - update_time = st_get_ticks(); - - fread(&score, sizeof(int),1,fi); - fread(&distros, sizeof(int),1,fi); - fread(&scroll_x,sizeof(float),1,fi); - //FIXME:fread(&tux, sizeof(Player), 1, fi); - //FIXME:timer_fread(&tux.invincible_timer,fi); - //FIXME:timer_fread(&tux.skidding_timer,fi); - //FIXME:timer_fread(&tux.safe_timer,fi); - //FIXME:timer_fread(&tux.frame_timer,fi); - timer_fread(&time_left,fi); - fread(&ui,sizeof(int),1,fi); - fclose(fi); - } -#endif -} - std::string slotinfo(int slot) { FILE* fi; Index: gameloop.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameloop.h,v retrieving revision 1.38 retrieving revision 1.39 diff -u -d -r1.38 -r1.39 --- gameloop.h 11 Apr 2004 16:38:58 -0000 1.38 +++ gameloop.h 16 Apr 2004 16:52:17 -0000 1.39 @@ -69,9 +69,6 @@ Level* get_level() { return world->get_level(); } World* get_world() { return world; } - void savegame(int slot); - void loadgame(int slot); - static GameSession* current() { return current_; } private: static GameSession* current_; Index: setup.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/setup.cpp,v retrieving revision 1.38 retrieving revision 1.39 diff -u -d -r1.38 -r1.39 --- setup.cpp 13 Apr 2004 14:32:48 -0000 1.38 +++ setup.cpp 16 Apr 2004 16:52:18 -0000 1.39 @@ -40,6 +40,7 @@ #include "gameloop.h" #include "configfile.h" #include "scene.h" +#include "worldmap.h" #ifdef WIN32 #define mkdir(dir, mode) mkdir(dir) @@ -455,13 +456,6 @@ } } -void process_save_game_menu() -{ - int slot = save_game_menu->check(); - if (slot != -1) - GameSession::current()->savegame(slot - 1); -} - bool process_load_game_menu() { int slot = load_game_menu->check(); @@ -474,30 +468,14 @@ if (tmp.length() == strlen("Slot X - Free")) { // Slot is free, so start a new game - GameSession session("default", 1, ST_GL_PLAY); - session.run(); - + worldmap_run(); + show_menu = true; Menu::set_current(main_menu); } else { puts("Warning: Loading games isn't supported at the moment"); -#if 0 - // Slot contains a level, so load it - if (game_started) - { - GameSession session("default",slot - 1,ST_GL_LOAD_GAME); - session.run(); - - show_menu = true; - Menu::set_current(main_menu); - } - else - { - //loadgame(slot - 1); - } -#endif } st_pause_ticks_stop(); return true; Index: text.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/text.h,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- text.h 13 Apr 2004 12:25:22 -0000 1.10 +++ text.h 16 Apr 2004 16:52:18 -0000 1.11 @@ -47,10 +47,10 @@ Text(const std::string& file, int kind, int w, int h); ~Text(); - void draw(const char* text, int x, int y, int shadowsize, int update = NO_UPDATE); + void draw(const char* text, int x, int y, int shadowsize = 1, int update = NO_UPDATE); void draw_chars(Surface* pchars, const char* text, int x, int y, int update = NO_UPDATE); void drawf(const char* text, int x, int y, TextHAlign halign, TextVAlign valign, int shadowsize, int update = NO_UPDATE); - void draw_align(const char* text, int x, int y, TextHAlign halign, TextVAlign valign, int shadowsize, int update = NO_UPDATE); + void draw_align(const char* text, int x, int y, TextHAlign halign, TextVAlign valign, int shadowsize = 1, int update = NO_UPDATE); void erasetext(const char * text, int x, int y, Surface* surf, int update, int shadowsize); void erasecenteredtext(const char * text, int y, Surface* surf, int update, int shadowsize); }; Index: player.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/player.cpp,v retrieving revision 1.37 retrieving revision 1.38 diff -u -d -r1.37 -r1.38 --- player.cpp 16 Apr 2004 16:24:54 -0000 1.37 +++ player.cpp 16 Apr 2004 16:52:17 -0000 1.38 @@ -83,10 +83,7 @@ frame_main = 0; frame_ = 0; - lives = 3; - score = 0; - distros = 0; - + player_input_init(&input); keymap.jump = SDLK_UP; @@ -504,11 +501,11 @@ } /* Enough distros for a One-up? */ - if (distros >= DISTROS_LIFEUP) + if (player_status.distros >= DISTROS_LIFEUP) { - distros = distros - DISTROS_LIFEUP; - if(lives < MAX_LIVES) - lives++; + player_status.distros = player_status.distros - DISTROS_LIFEUP; + if(player_status.lives < MAX_LIVES) + ++player_status.lives; /*We want to hear the sound even, if MAX_LIVES is reached*/ play_sound(sounds[SND_LIFEUP], SOUND_CENTER_SPEAKER); } @@ -723,9 +720,6 @@ } } - if(dying) - gold_text->drawf("Penguins can fly !:",0,0,A_HMIDDLE,A_VMIDDLE,1); - if (debug_mode) fillrect(base.x - scroll_x, base.y, 32, 32, 75,75,75, 150); } @@ -830,7 +824,7 @@ { /* He died :^( */ - --lives; + --player_status.lives; remove_powerups(); dying = DYING_NOT; } |