From: Ingo Ruhnke Date: Mon, 19 Apr 2004 22:47:36 +0000 (+0000) Subject: - implemented reset points X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=38c527eb063f90e3e8d7fe3d80244ab0fd0599d4;p=supertux.git - implemented reset points SVN-Revision: 582 --- diff --git a/src/gameloop.cpp b/src/gameloop.cpp index cfdefc16d..00c26bd36 100644 --- a/src/gameloop.cpp +++ b/src/gameloop.cpp @@ -63,6 +63,13 @@ GameSession::restart_level() 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 @@ GameSession::restart_level() { 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::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) { diff --git a/src/level.cpp b/src/level.cpp index e21be8752..4811a7bb0 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -315,7 +315,29 @@ Level::load(const std::string& filename) 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 @@ Level::cleanup() fg_tiles[i].clear(); } + reset_points.clear(); name.clear(); author.clear(); theme.clear(); diff --git a/src/level.h b/src/level.h index f09368338..4a22948dc 100644 --- a/src/level.h +++ b/src/level.h @@ -50,6 +50,12 @@ enum TileMapType { TM_FG }; +struct ResetPoint +{ + int x; + int y; +}; + class Level { public: @@ -74,6 +80,9 @@ class Level float gravity; std::vector badguy_data; + + /** A collection of points to which Tux can be reset after a lost live */ + std::vector reset_points; public: Level(); Level(const std::string& subset, int level);