From: Ricardo Cruz Date: Mon, 3 May 2004 23:44:28 +0000 (+0000) Subject: Changed the way the scrolling was calculated. Instead of calculating it relatively... X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=34145bb580a8cf8756a67e4b4ee34c0db7aee784;p=supertux.git Changed the way the scrolling was calculated. Instead of calculating it relatively to the middle of the screen, calculte it relatively to the borders. This solution is more clear (IMO) and elegant because; there isn't that ugly code anymore: scroll_x -= screen.w / 2; (...) scroll_x += screen.w / 2; Besides from that, in case we change the resolution, this makes the playbility to be not affected. Note: if you think the scrolling is made when Tux is too much in the right or in the left, you can easily change this, by changine the SPACE_X value in world.cpp. SVN-Revision: 962 --- diff --git a/src/world.cpp b/src/world.cpp index c0ce08ec6..0bf61f437 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -305,28 +305,24 @@ World::action(double frame_ratio) } } -// the space that it takes for the screen to start scrolling -#define X_SPACE 40 +// the space that it takes for the screen to start scrolling, regarding +// screen bounds (in pixels) +#define X_SPACE 160 /* 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) + if (scroll_x < tux_pos_x - (screen->w - X_SPACE)) + scroll_x = tux_pos_x - (screen->w - X_SPACE); + else if (scroll_x > tux_pos_x - X_SPACE && level->back_scrolling) 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() {