From c2b5367f6f1d24f84ea26da553245128f241690e Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Wed, 26 May 2004 15:57:36 +0000 Subject: [PATCH] some cleanups and robustness checks, I added while searching for a bug (that was none as it turned out :) SVN-Revision: 1332 --- src/level.cpp | 34 ++++++++++++++-------------------- src/level.h | 2 -- src/player.cpp | 14 +------------- src/player.h | 2 +- src/world.cpp | 3 +-- src/world.h | 12 ++++++++---- 6 files changed, 25 insertions(+), 42 deletions(-) diff --git a/src/level.cpp b/src/level.cpp index 82c1d6216..485e5e82d 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -227,8 +227,6 @@ Level::init_defaults() start_pos.y = 170; time_left = 100; gravity = 10.; - back_scrolling = false; - hor_autoscroll_speed = 0; bkgd_speed = 50; bkgd_top.red = 0; bkgd_top.green = 0; @@ -265,7 +263,9 @@ Level::load(const std::string& filename, World* world) if (root_obj->type == LISP_TYPE_EOF || root_obj->type == LISP_TYPE_PARSE_ERROR) { - printf("World: Parse Error in file %s", filename.c_str()); + lisp_free(root_obj); + std::cout << "World: Parse Error in file '" << filename + << "'.\n"; return -1; } @@ -281,21 +281,16 @@ Level::load(const std::string& filename, World* world) if (!reader.read_float("start_pos_y", &start_pos.y)) start_pos.y = 170; time_left = 500; if(!reader.read_int("time", &time_left)) { - printf("Warning no time specified for level.\n"); + printf("Warning: no time specified for level.\n"); } height = 15; - reader.read_int("height", &height); - - back_scrolling = false; - reader.read_bool("back_scrolling", &back_scrolling); - - hor_autoscroll_speed = 0; - reader.read_float("hor_autoscroll_speed", &hor_autoscroll_speed); + if(!reader.read_int("height", &height)) { + printf("Warning: no height specified for level.\n"); + } bkgd_speed = 50; reader.read_int("bkgd_speed", &bkgd_speed); - bkgd_top.red = bkgd_top.green = bkgd_top.blue = 0; reader.read_int("bkgd_red_top", &bkgd_top.red); @@ -369,8 +364,9 @@ Level::load(const std::string& filename, World* world) if (reader.read_lisp("camera", &cur)) { LispReader reader(cur); - if(world) + if(world) { world->camera->read(reader); + } } } } @@ -388,13 +384,13 @@ Level::save(const std::string& subset, int level, World* world) char str[80]; /* Save data file: */ - sprintf(str, "/levels/%s/", subset.c_str()); + snprintf(str, sizeof(str), "/levels/%s/", subset.c_str()); fcreatedir(str); - snprintf(filename, 1024, "%s/levels/%s/level%d.stl", st_dir, subset.c_str(), - level); + snprintf(filename, sizeof(filename), + "%s/levels/%s/level%d.stl", st_dir, subset.c_str(), level); if(!fwriteable(filename)) - snprintf(filename, 1024, "%s/levels/%s/level%d.stl", datadir.c_str(), - subset.c_str(), level); + snprintf(filename, sizeof(filename), "%s/levels/%s/level%d.stl", + datadir.c_str(), subset.c_str(), level); std::ofstream out(filename); if(!out.good()) { @@ -422,8 +418,6 @@ Level::save(const std::string& subset, int level, World* world) writer.write_int("time", time_left); writer.write_int("width", width); writer.write_int("height", height); - writer.write_bool("back_scrolling", back_scrolling); - writer.write_float("hor_autoscroll_speed", hor_autoscroll_speed); writer.write_float("gravity", gravity); writer.write_int_vector("background-tm", bg_tiles); diff --git a/src/level.h b/src/level.h index 70015fc59..1f2fe9486 100644 --- a/src/level.h +++ b/src/level.h @@ -94,8 +94,6 @@ class Level int bkgd_speed; Vector start_pos; float gravity; - bool back_scrolling; - float hor_autoscroll_speed; /** A collection of points to which Tux can be reset after a lost live */ std::vector reset_points; diff --git a/src/player.cpp b/src/player.cpp index 88b67611c..1c3493956 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -886,8 +886,7 @@ Player::move(const Vector& vector) } void -Player::check_bounds(Camera& viewport, - bool back_scrolling, bool hor_autoscroll) +Player::check_bounds(Camera& viewport) { /* Keep tux in bounds: */ if (base.x < 0) @@ -921,17 +920,6 @@ Player::check_bounds(Camera& viewport, return; } } - - if(hor_autoscroll) - { - if(base.x == viewport.get_translation().x) - if(issolid(base.x+32, base.y) || (size != SMALL && issolid(base.x+32, base.y+32))) - kill(KILL); - - if(base.x + base.width > viewport.get_translation().x + screen->w) - base.x = viewport.get_translation().x + screen->w - base.width; - } - } // EOF // diff --git a/src/player.h b/src/player.h index 6852ebc14..d0a4cf03d 100644 --- a/src/player.h +++ b/src/player.h @@ -161,7 +161,7 @@ public: void collision(void* p_c_object, int c_object); void kill(HurtMode mode); void player_remove_powerups(); - void check_bounds(Camera& viewport, bool back_scrolling, bool hor_autoscroll); + void check_bounds(Camera& viewport); bool on_ground(); bool under_solid(); bool tiles_on_air(int tiles); diff --git a/src/world.cpp b/src/world.cpp index 70da9b4eb..fb850205b 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -200,8 +200,7 @@ World::draw() void World::action(float elapsed_time) { - tux->check_bounds(*camera, - level->back_scrolling, (bool)level->hor_autoscroll_speed); + tux->check_bounds(*camera); /* update objects (don't use iterators here, because the list might change * during the iteration) diff --git a/src/world.h b/src/world.h index 6635fe36c..072386f69 100644 --- a/src/world.h +++ b/src/world.h @@ -66,14 +66,18 @@ public: DisplayManager displaymanager; public: - static World* current() { return current_; } - static void set_current(World* w) { current_ = w; } + static World* current() + { return current_; } + static void set_current(World* w) + { current_ = w; } World(const std::string& filename, int level_nr = -1); ~World(); - Level* get_level() { return level; } - Player* get_tux() { return tux; } + Level* get_level() + { return level; } + Player* get_tux() + { return tux; } void add_object(GameObject* object); -- 2.11.0