[Super-tux-commit] supertux/src gameloop.cpp,1.81,1.82 level.cpp,1.38,1.39 level.h,1.32,1.33
Brought to you by:
wkendrick
From: Ingo R. <gr...@us...> - 2004-04-19 22:47:52
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1601 Modified Files: gameloop.cpp level.cpp level.h Log Message: - implemented reset points Index: level.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/level.cpp,v retrieving revision 1.38 retrieving revision 1.39 diff -u -d -r1.38 -r1.39 --- level.cpp 18 Apr 2004 22:36:03 -0000 1.38 +++ level.cpp 19 Apr 2004 22:47:36 -0000 1.39 @@ -315,7 +315,29 @@ reader.read_int_vector("foreground-tm", &fg_tm); - { + { // Read ResetPoints + lisp_object_t* cur = 0; + if (reader.read_lisp("reset-points", &cur)) + { + while (!lisp_nil_p(cur)) + { + lisp_object_t* data = lisp_car(cur); + + ResetPoint pos; + + LispReader reader(lisp_cdr(data)); + if (reader.read_int("x", &pos.x) + && reader.read_int("y", &pos.y)) + { + reset_points.push_back(pos); + } + + cur = lisp_cdr(cur); + } + } + } + + { // Read BadGuys lisp_object_t* cur = 0; if (reader.read_lisp("objects", &cur)) { @@ -557,6 +579,7 @@ fg_tiles[i].clear(); } + reset_points.clear(); name.clear(); author.clear(); theme.clear(); Index: gameloop.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameloop.cpp,v retrieving revision 1.81 retrieving revision 1.82 diff -u -d -r1.81 -r1.82 --- gameloop.cpp 19 Apr 2004 21:20:57 -0000 1.81 +++ gameloop.cpp 19 Apr 2004 22:47:36 -0000 1.82 @@ -63,6 +63,13 @@ fps_timer.init(true); frame_timer.init(true); + float old_x_pos = -1; + + if (world) + { // Tux has lost a life, so we try to respawn him at the nearest reset point + old_x_pos = world->get_tux()->base.x; + } + delete world; if (st_gl_mode == ST_GL_LOAD_LEVEL_FILE) @@ -77,6 +84,25 @@ { world = new World(subset, levelnb); } + + // Set Tux to the nearest reset point + if (old_x_pos != -1) + { + ResetPoint best_reset_point = { -1, -1 }; + for(std::vector<ResetPoint>::iterator i = get_level()->reset_points.begin(); + i != get_level()->reset_points.end(); ++i) + { + if (i->x < old_x_pos && best_reset_point.x < i->x) + best_reset_point = *i; + } + + if (best_reset_point.x != -1) + { + world->get_tux()->base.x = best_reset_point.x; + world->get_tux()->base.y = best_reset_point.y; + } + } + if (st_gl_mode != ST_GL_DEMO_GAME) { Index: level.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/level.h,v retrieving revision 1.32 retrieving revision 1.33 diff -u -d -r1.32 -r1.33 --- level.h 18 Apr 2004 22:36:03 -0000 1.32 +++ level.h 19 Apr 2004 22:47:36 -0000 1.33 @@ -50,6 +50,12 @@ TM_FG }; +struct ResetPoint +{ + int x; + int y; +}; + class Level { public: @@ -74,6 +80,9 @@ float gravity; std::vector<BadGuyData> badguy_data; + + /** A collection of points to which Tux can be reset after a lost live */ + std::vector<ResetPoint> reset_points; public: Level(); Level(const std::string& subset, int level); |