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)
{
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)
{
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))
{
fg_tiles[i].clear();
}
+ reset_points.clear();
name.clear();
author.clear();
theme.clear();
TM_FG
};
+struct ResetPoint
+{
+ int x;
+ int y;
+};
+
class Level
{
public:
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);