[Super-tux-commit] supertux/src level.cpp,1.59,1.60 level.h,1.42,1.43 player.cpp,1.81,1.82 player.h,
Brought to you by:
wkendrick
From: Ricardo C. <rm...@us...> - 2004-05-03 12:34:46
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10732/src Modified Files: level.cpp level.h player.cpp player.h world.cpp world.h Log Message: Added back scrolling! It is only enabled if the level explicity asks for. Index: world.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/world.h,v retrieving revision 1.33 retrieving revision 1.34 diff -u -d -r1.33 -r1.34 --- world.h 28 Apr 2004 20:24:34 -0000 1.33 +++ world.h 3 May 2004 12:34:37 -0000 1.34 @@ -76,6 +76,7 @@ void draw(); void action(double frame_ratio); + void keep_in_bounds(); void play_music(int musictype); int get_music_type(); Index: level.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/level.h,v retrieving revision 1.42 retrieving revision 1.43 diff -u -d -r1.42 -r1.43 --- level.h 29 Apr 2004 16:23:32 -0000 1.42 +++ level.h 3 May 2004 12:34:37 -0000 1.43 @@ -89,6 +89,7 @@ int start_pos_x; int start_pos_y; float gravity; + bool back_scrolling; std::vector<BadGuyData> badguy_data; Index: player.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/player.cpp,v retrieving revision 1.81 retrieving revision 1.82 diff -u -d -r1.81 -r1.82 --- player.cpp 1 May 2004 15:46:08 -0000 1.81 +++ player.cpp 3 May 2004 12:34:37 -0000 1.82 @@ -191,7 +191,7 @@ 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 @@ } 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 @@ 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 // Index: player.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/player.h,v retrieving revision 1.49 retrieving revision 1.50 diff -u -d -r1.49 -r1.50 --- player.h 2 May 2004 21:28:32 -0000 1.49 +++ player.h 3 May 2004 12:34:37 -0000 1.50 @@ -144,7 +144,7 @@ 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(); Index: level.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/level.cpp,v retrieving revision 1.59 retrieving revision 1.60 diff -u -d -r1.59 -r1.60 --- level.cpp 29 Apr 2004 16:23:32 -0000 1.59 +++ level.cpp 3 May 2004 12:34:37 -0000 1.60 @@ -237,6 +237,7 @@ 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 @@ 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 @@ 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 "); Index: world.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/world.cpp,v retrieving revision 1.50 retrieving revision 1.51 diff -u -d -r1.50 -r1.51 --- world.cpp 2 May 2004 21:28:32 -0000 1.50 +++ world.cpp 3 May 2004 12:34:37 -0000 1.51 @@ -257,6 +257,7 @@ 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 @@ } } +// 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() { |