[Super-tux-commit] supertux/src flip_level_transformer.cpp,1.1,1.2 gameloop.cpp,1.213,1.214 gameloop
Brought to you by:
wkendrick
From: Matze B. <mat...@us...> - 2005-03-30 01:52:36
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13952/src Modified Files: flip_level_transformer.cpp gameloop.cpp gameloop.h sector.cpp sector.h title.cpp Log Message: added a bell object which is a new better way to do reset points Index: sector.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/sector.h,v retrieving revision 1.31 retrieving revision 1.32 diff -u -d -r1.31 -r1.32 --- sector.h 25 Mar 2005 20:39:53 -0000 1.31 +++ sector.h 30 Mar 2005 01:52:13 -0000 1.32 @@ -69,9 +69,8 @@ void write(lisp::Writer& writer); /// activates this sector (change music, intialize player class, ...) - void activate(const std::string& spawnpoint = "main"); - /// get best spawn point - Vector get_best_spawn_point(Vector pos); + void activate(const std::string& spawnpoint); + void activate(const Vector& player_pos); void action(float elapsed_time); void update_game_objects(); Index: flip_level_transformer.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/flip_level_transformer.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- flip_level_transformer.cpp 25 Mar 2005 20:39:49 -0000 1.1 +++ flip_level_transformer.cpp 30 Mar 2005 01:52:12 -0000 1.2 @@ -71,8 +71,8 @@ void FlipLevelTransformer::transform_moving_object(float height, MovingObject*object) { - Vector pos = object->bbox.p1; + Vector pos = object->get_pos(); pos.y = height - pos.y; - object->bbox.set_pos(pos); + object->set_pos(pos); } Index: gameloop.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameloop.h,v retrieving revision 1.67 retrieving revision 1.68 diff -u -d -r1.67 -r1.68 --- gameloop.h 25 Mar 2005 20:39:50 -0000 1.67 +++ gameloop.h 30 Mar 2005 01:52:12 -0000 1.68 @@ -55,39 +55,9 @@ keeping the speed and framerate sane, etc. */ class GameSession { -private: - Uint32 fps_ticks; - Timer2 endsequence_timer; - Level* level; - Sector* currentsector; - - int st_gl_mode; - int levelnb; - float fps_fps; - int pause_menu_frame; - - /** If true the end_sequence will be played, user input will be - ignored while doing that */ - enum EndSequenceState { - NO_ENDSEQUENCE, - ENDSEQUENCE_RUNNING, // tux is running right - ENDSEQUENCE_WAITING // waiting for the end of the music - }; - EndSequenceState end_sequence; - float last_x_pos; - - bool game_pause; - - std::string levelfile; - - // the sector and spawnpoint we shoudl spawn after this frame - std::string newsector; - std::string newspawnpoint; - public: enum ExitStatus { ES_NONE, ES_LEVEL_FINISHED, ES_GAME_OVER, ES_LEVEL_ABORT }; -private: - ExitStatus exit_status; + public: DrawingContext* context; Timer2 time_left; @@ -107,23 +77,14 @@ void respawn(const std::string& sectorname, const std::string& spawnpointname); + void set_reset_point(const std::string& sectorname, + const Vector& pos); Sector* get_current_sector() { return currentsector; } void start_sequence(const std::string& sequencename); private: - static GameSession* current_; - - // for cheating - std::string last_keys; - - // swap points - Vector last_swap_point; - Statistics last_swap_stats; - - Statistics* best_level_statistics; - void restart_level(); void check_end_conditions(); @@ -138,12 +99,52 @@ void on_escape_press(); void process_menu(); + + + Uint32 fps_ticks; + Timer2 endsequence_timer; + Level* level; + Sector* currentsector; + + int st_gl_mode; + int levelnb; + float fps_fps; + int pause_menu_frame; + + /** If true the end_sequence will be played, user input will be + ignored while doing that */ + enum EndSequenceState { + NO_ENDSEQUENCE, + ENDSEQUENCE_RUNNING, // tux is running right + ENDSEQUENCE_WAITING // waiting for the end of the music + }; + EndSequenceState end_sequence; + float last_x_pos; + + bool game_pause; + + std::string levelfile; + + // reset point (the point where tux respawns if he dies) + std::string reset_sector; + Vector reset_pos; + + // the sector and spawnpoint we should spawn after this frame + std::string newsector; + std::string newspawnpoint; + + static GameSession* current_; + + // for cheating + std::string last_keys; + + Statistics* best_level_statistics; + + ExitStatus exit_status; }; std::string slotinfo(int slot); -void bumpbrick(float x, float y); - /** Return true if the gameloop() was entered, false otherwise */ bool process_load_game_menu(); Index: title.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/title.cpp,v retrieving revision 1.140 retrieving revision 1.141 diff -u -d -r1.140 -r1.141 --- title.cpp 25 Mar 2005 20:39:53 -0000 1.140 +++ title.cpp 30 Mar 2005 01:52:13 -0000 1.141 @@ -85,7 +85,7 @@ { // FIXME: shouldn't be needed if GameSession // didn't relay on global variables - titlesession->get_current_sector()->activate(); + titlesession->get_current_sector()->activate("main"); titlesession->set_current(); frame_rate.update(); @@ -214,7 +214,7 @@ contrib_subset_menu->additem(MN_HL,"",0,0); contrib_subset_menu->additem(MN_BACK, _("Back"), 0, 0); - titlesession->get_current_sector()->activate(); + titlesession->get_current_sector()->activate("main"); titlesession->set_current(); } } @@ -297,7 +297,7 @@ logo = new Surface(datadir + "/images/title/logo.png", true); img_choose_subset = new Surface(datadir + "/images/status/choose-level-subset.png", true); - titlesession->get_current_sector()->activate(); + titlesession->get_current_sector()->activate("main"); titlesession->set_current(); /* --- Main title loop: --- */ Index: gameloop.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameloop.cpp,v retrieving revision 1.213 retrieving revision 1.214 diff -u -d -r1.213 -r1.214 --- gameloop.cpp 26 Mar 2005 12:31:13 -0000 1.213 +++ gameloop.cpp 30 Mar 2005 01:52:12 -0000 1.214 @@ -91,9 +91,6 @@ context = new DrawingContext(); - last_swap_point = Vector(-1, -1); - last_swap_stats.reset(); - restart_level(); } @@ -126,40 +123,23 @@ global_stats.set_total_points(BADGUYS_KILLED_STAT, level->get_total_badguys()); global_stats.set_total_points(TIME_NEEDED_STAT, level->timelimit); - currentsector = level->get_sector("main"); - if(!currentsector) - Termination::abort("Level has no main sector.", ""); - currentsector->activate("main"); - -#if 0 - // Set Tux to the nearest reset point - if(tux_pos.x != -1) - { - tux_pos = currentsector->get_best_spawn_point(tux_pos); - - if(last_swap_point.x > tux_pos.x) - tux_pos = last_swap_point; - else // new swap point - { - last_swap_point = tux_pos; - - last_swap_stats += global_stats; - } - - currentsector->player->base.x = tux_pos.x; - currentsector->player->base.y = tux_pos.y; - - // has to reset camera on swapping - currentsector->camera->reset(Vector(currentsector->player->base.x, - currentsector->player->base.y)); - } -#endif - - if (st_gl_mode != ST_GL_DEMO_GAME) - { - if(st_gl_mode == ST_GL_PLAY || st_gl_mode == ST_GL_LOAD_LEVEL_FILE) - levelintro(); + if(reset_sector != "") { + currentsector = level->get_sector(reset_sector); + if(!currentsector) { + std::stringstream msg; + msg << "Couldn't find sector '" << reset_sector << "' for resetting tux."; + throw std::runtime_error(msg.str()); } + currentsector->activate(reset_pos); + } else { + currentsector = level->get_sector("main"); + if(!currentsector) + throw std::runtime_error("Couldn't find main sector"); + currentsector->activate("main"); + } + + if(st_gl_mode == ST_GL_PLAY || st_gl_mode == ST_GL_LOAD_LEVEL_FILE) + levelintro(); start_timers(); currentsector->play_music(LEVEL_MUSIC); @@ -172,7 +152,7 @@ } void -GameSession::levelintro(void) +GameSession::levelintro() { SoundManager::get()->halt_music(); @@ -383,13 +363,13 @@ } } - /* Check if chacrater is ASCII */ - char ch[2]; - if((event.key.keysym.unicode & 0xFF80) == 0) - { - ch[0] = event.key.keysym.unicode & 0x7F; - ch[1] = '\0'; - } + /* Check if chacrater is ASCII */ + char ch[2]; + if((event.key.keysym.unicode & 0xFF80) == 0) + { + ch[0] = event.key.keysym.unicode & 0x7F; + ch[1] = '\0'; + } last_keys.append(ch); // add to cheat keys handle_cheats(); break; @@ -572,9 +552,8 @@ /* End of level? */ if(end_sequence && endsequence_timer.check()) { - exit_status = ES_LEVEL_FINISHED; - global_stats += last_swap_stats; // add swap points stats - return; + exit_status = ES_LEVEL_FINISHED; + return; } else if (!end_sequence && tux->is_dead()) { player_status.bonus = PlayerStatus::NO_BONUS; @@ -795,6 +774,13 @@ } void +GameSession::set_reset_point(const std::string& sector, const Vector& pos) +{ + reset_sector = sector; + reset_pos = pos; +} + +void GameSession::start_sequence(const std::string& sequencename) { if(sequencename == "endsequence" || sequencename == "fireworks") { Index: sector.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/sector.cpp,v retrieving revision 1.67 retrieving revision 1.68 diff -u -d -r1.67 -r1.68 --- sector.cpp 26 Mar 2005 12:31:13 -0000 1.67 +++ sector.cpp 30 Mar 2005 01:52:12 -0000 1.68 @@ -392,11 +392,33 @@ void Sector::activate(const std::string& spawnpoint) { + SpawnPoint* sp = 0; + for(SpawnPoints::iterator i = spawnpoints.begin(); i != spawnpoints.end(); + ++i) { + if((*i)->name == spawnpoint) { + sp = *i; + break; + } + } + if(!sp) { + std::cerr << "Spawnpoint '" << spawnpoint << "' not found.\n"; + if(spawnpoint != "main") { + activate("main"); + } else { + activate(Vector(0, 0)); + } + } else { + activate(sp->pos); + } +} + +void +Sector::activate(const Vector& player_pos) +{ _current = this; // Apply bonuses from former levels - switch (player_status.bonus) - { + switch (player_status.bonus) { case PlayerStatus::NO_BONUS: break; @@ -407,41 +429,16 @@ case PlayerStatus::GROWUP_BONUS: player->grow(false); break; - } - SpawnPoint* sp = 0; - for(SpawnPoints::iterator i = spawnpoints.begin(); i != spawnpoints.end(); - ++i) { - if((*i)->name == spawnpoint) { - sp = *i; + default: + std::cerr << "Unknown bonus in PlayerStatus?!?\n"; break; - } - } - if(!sp) { - std::cerr << "Spawnpoint '" << spawnpoint << "' not found.\n"; - } else { - player->move(sp->pos); } + player->move(player_pos); camera->reset(player->get_pos()); } -Vector -Sector::get_best_spawn_point(Vector pos) -{ - Vector best_reset_point = Vector(-1,-1); - - for(SpawnPoints::iterator i = spawnpoints.begin(); i != spawnpoints.end(); - ++i) { - if((*i)->name != "main") - continue; - if((*i)->pos.x > best_reset_point.x && (*i)->pos.x < pos.x) - best_reset_point = (*i)->pos; - } - - return best_reset_point; -} - Rectangle Sector::get_active_region() { |