[Super-tux-commit] supertux/src player.cpp,1.82,1.83 player.h,1.50,1.51 world.cpp,1.54,1.55 world.h,
Brought to you by:
wkendrick
From: Ricardo C. <rm...@us...> - 2004-05-04 13:59:42
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27208/src Modified Files: player.cpp player.h world.cpp world.h Log Message: Made it possible for Tux to be in a position before the half of the screen. Started implementing a moving camera, but it isn't working very well, i'll have a look at it later. Index: player.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/player.cpp,v retrieving revision 1.82 retrieving revision 1.83 diff -u -d -r1.82 -r1.83 --- player.cpp 3 May 2004 12:34:37 -0000 1.82 +++ player.cpp 4 May 2004 13:58:59 -0000 1.83 @@ -78,6 +78,7 @@ base.ym = 0; previous_base = old_base = base; dir = RIGHT; + old_dir = dir; duck = false; dying = DYING_NOT; @@ -295,9 +296,11 @@ float dirsign = 0; if(input.left == DOWN && input.right == UP && (!duck || physic.get_velocity_y() != 0)) { + old_dir = dir; dir = LEFT; dirsign = -1; } else if(input.left == UP && input.right == DOWN && (!duck || physic.get_velocity_y() != 0)) { + old_dir = dir; dir = RIGHT; dirsign = 1; } Index: world.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/world.h,v retrieving revision 1.34 retrieving revision 1.35 diff -u -d -r1.34 -r1.35 --- world.h 3 May 2004 12:34:37 -0000 1.34 +++ world.h 4 May 2004 13:59:00 -0000 1.35 @@ -44,6 +44,9 @@ Level* level; Player tux; + Timer scrolling_timer; + float moved_scroll_x; + int distro_counter; bool counting_distros; int currentmusic; @@ -76,7 +79,7 @@ void draw(); void action(double frame_ratio); - void keep_in_bounds(); + void scrolling(); // camera scrolling void play_music(int musictype); int get_music_type(); Index: world.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/world.cpp,v retrieving revision 1.54 retrieving revision 1.55 diff -u -d -r1.54 -r1.55 --- world.cpp 3 May 2004 23:44:28 -0000 1.54 +++ world.cpp 4 May 2004 13:59:00 -0000 1.55 @@ -54,6 +54,8 @@ get_level()->load_song(); apply_bonuses(); + + scrolling_timer.init(true); } World::World(const std::string& subset, int level_nr) @@ -73,6 +75,8 @@ get_level()->load_song(); apply_bonuses(); + + scrolling_timer.init(true); } void @@ -257,7 +261,7 @@ World::action(double frame_ratio) { tux.action(frame_ratio); - keep_in_bounds(); + scrolling(); /* Handle bouncy distros: */ for (unsigned int i = 0; i < bouncy_distros.size(); i++) @@ -307,17 +311,41 @@ // the space that it takes for the screen to start scrolling, regarding // screen bounds (in pixels) -#define X_SPACE 160 +#define X_SPACE 380 +// the time it takes to move the camera (in ms) +#define CHANGE_DIR_SCROLL_SPEED 2000 /* This functions takes cares of the scrolling */ -void World::keep_in_bounds() +void World::scrolling() { int tux_pos_x = (int)(tux.base.x + (tux.base.width/2)); - 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; + if(tux.old_dir != tux.dir && (level->back_scrolling || debug_mode)) + scrolling_timer.start(CHANGE_DIR_SCROLL_SPEED); + + if(scrolling_timer.check()) + { + float final_scroll_x; + if (tux.dir == RIGHT) + final_scroll_x = tux_pos_x - (screen->w - X_SPACE); + else// if (tux.dir == LEFT)// && ) + final_scroll_x = tux_pos_x - X_SPACE; + + if(moved_scroll_x == 0) + moved_scroll_x = scroll_x; + + scroll_x += (final_scroll_x - scroll_x) / (CHANGE_DIR_SCROLL_SPEED); + } + + else + { + moved_scroll_x = 0; + + if (tux.dir == RIGHT && scroll_x < tux_pos_x - (screen->w - X_SPACE)) + scroll_x = tux_pos_x - (screen->w - X_SPACE); + else if (tux.dir == LEFT && scroll_x > tux_pos_x - X_SPACE && (level->back_scrolling || debug_mode)) + scroll_x = tux_pos_x - X_SPACE; + } if(scroll_x < 0) scroll_x = 0; Index: player.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/player.h,v retrieving revision 1.50 retrieving revision 1.51 diff -u -d -r1.50 -r1.51 --- player.h 3 May 2004 12:34:37 -0000 1.50 +++ player.h 4 May 2004 13:59:00 -0000 1.51 @@ -117,6 +117,7 @@ DyingType dying; Direction dir; + Direction old_dir; bool jumping; bool can_jump; |