From: Ricardo Cruz Date: Mon, 3 May 2004 12:34:37 +0000 (+0000) Subject: Added back scrolling! X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=47ab536b3f0f77cb6c92ac66a072a104749b1f87;p=supertux.git Added back scrolling! It is only enabled if the level explicity asks for. SVN-Revision: 939 --- diff --git a/src/level.cpp b/src/level.cpp index d8880da24..15e258c0c 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -237,6 +237,7 @@ Level::init_defaults() start_pos_y = 170; time_left = 100; gravity = 10.; + back_scrolling = false; bkgd_top.red = 0; bkgd_top.green = 0; bkgd_top.blue = 0; @@ -311,6 +312,9 @@ Level::load(const std::string& filename) if(!reader.read_int("time", &time_left)) { printf("Warning no time specified for level.\n"); } + + back_scrolling = false; + reader.read_bool("back_scrolling", &back_scrolling); bkgd_top.red = bkgd_top.green = bkgd_top.blue = 0; reader.read_int("bkgd_red_top", &bkgd_top.red); @@ -551,6 +555,10 @@ Level::save(const std::string& subset, int level) fprintf(fi," (bkgd_blue_bottom %d)\n", bkgd_bottom.blue); fprintf(fi," (time %d)\n", time_left); fprintf(fi," (width %d)\n", width); + if(back_scrolling) + fprintf(fi," (back_scrolling 1)\n"); + else + fprintf(fi," (back_scrolling 0)\n"); fprintf(fi," (gravity %2.1f)\n", gravity); fprintf(fi," (background-tm "); diff --git a/src/level.h b/src/level.h index 682cbe6c9..8ba3fd05a 100644 --- a/src/level.h +++ b/src/level.h @@ -89,6 +89,7 @@ class Level int start_pos_x; int start_pos_y; float gravity; + bool back_scrolling; std::vector badguy_data; diff --git a/src/player.cpp b/src/player.cpp index d6f60e98b..401055147 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -191,7 +191,7 @@ Player::action(double frame_ratio) base.x += frame_ratio * WALK_SPEED * (dir ? 1 : -1); previous_base = old_base = base; } - keep_in_bounds(); + check_bounds(); // Land: if (!on_ground()) @@ -734,20 +734,14 @@ Player::remove_powerups() } void -Player::keep_in_bounds() +Player::check_bounds() { - Level* plevel = World::current()->get_level(); - /* Keep tux in bounds: */ if (base.x < 0) { // Lock Tux to the size of the level, so that he doesn't fall of // on the left side base.x = 0; } - else if (base.x < scroll_x) - { - base.x = scroll_x; - } /* Keep in-bounds, vertically: */ if (base.y > screen->h) @@ -755,37 +749,8 @@ Player::keep_in_bounds() kill(KILL); } - int scroll_threshold = screen->w/2 - 80; - if (debug_mode) - { - scroll_x += screen->w/2; - // Backscrolling for debug mode - if (scroll_x < base.x - 80) - scroll_x = base.x - 80; - else if (scroll_x > base.x + 80) - scroll_x = base.x + 80; - scroll_x -= screen->w/2; - - if(scroll_x < 0) - scroll_x = 0; - } - else - { - if (base.x > scroll_threshold + scroll_x - && scroll_x < ((World::current()->get_level()->width * 32) - screen->w)) - { - // FIXME: Scrolling needs to be handled by a seperate View - // class, doing it as a player huck is ugly - - // Scroll the screen in past center: - scroll_x = base.x - scroll_threshold; - - // Lock the scrolling to the levelsize, so that we don't - // scroll over the right border - if (scroll_x > 32 * plevel->width - screen->w) - scroll_x = 32 * plevel->width - screen->w; - } - } + if(base.x < scroll_x) // can happen if back scrolling is disabled + base.x = scroll_x; } // EOF // diff --git a/src/player.h b/src/player.h index 7eb858e6a..e3c8a0e01 100644 --- a/src/player.h +++ b/src/player.h @@ -144,7 +144,7 @@ public: void is_dying(); bool is_dead(); void player_remove_powerups(); - void keep_in_bounds(); + void check_bounds(); bool on_ground(); bool under_solid(); void grow(); diff --git a/src/world.cpp b/src/world.cpp index 94a398fc8..9e4b843cb 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -257,6 +257,7 @@ void World::action(double frame_ratio) { tux.action(frame_ratio); + keep_in_bounds(); /* Handle bouncy distros: */ for (unsigned int i = 0; i < bouncy_distros.size(); i++) @@ -304,6 +305,28 @@ World::action(double frame_ratio) } } +// the space that it takes for the screen to start scrolling +#define X_SPACE 80 + +/* This functions takes cares of the scrolling */ +void World::keep_in_bounds() +{ +int tux_pos_x = (int)(tux.base.x - (tux.base.width/2)); + +scroll_x += screen->w/2; + +if (scroll_x < tux_pos_x - X_SPACE) + scroll_x = tux_pos_x - X_SPACE; +else if (scroll_x > tux_pos_x + X_SPACE && level->back_scrolling) + scroll_x = tux_pos_x + X_SPACE; + +scroll_x -= screen->w/2; + +if(scroll_x < 0) + scroll_x = 0; +} + + void World::collision_handler() { diff --git a/src/world.h b/src/world.h index 591d30576..57d803d16 100644 --- a/src/world.h +++ b/src/world.h @@ -76,6 +76,7 @@ public: void draw(); void action(double frame_ratio); + void keep_in_bounds(); void play_music(int musictype); int get_music_type();