From 21fcbb8870e735ca14d1278f31e4997a823024c7 Mon Sep 17 00:00:00 2001 From: Ricardo Cruz Date: Tue, 4 May 2004 13:59:00 +0000 Subject: [PATCH] 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. SVN-Revision: 968 --- src/player.cpp | 3 +++ src/player.h | 1 + src/world.cpp | 42 +++++++++++++++++++++++++++++++++++------- src/world.h | 5 ++++- 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/src/player.cpp b/src/player.cpp index 401055147..617b48d83 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -78,6 +78,7 @@ Player::init() base.ym = 0; previous_base = old_base = base; dir = RIGHT; + old_dir = dir; duck = false; dying = DYING_NOT; @@ -295,9 +296,11 @@ Player::handle_horizontal_input() 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; } diff --git a/src/player.h b/src/player.h index e3c8a0e01..a92855612 100644 --- a/src/player.h +++ b/src/player.h @@ -117,6 +117,7 @@ public: DyingType dying; Direction dir; + Direction old_dir; bool jumping; bool can_jump; diff --git a/src/world.cpp b/src/world.cpp index 0bf61f437..972f292e4 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -54,6 +54,8 @@ World::World(const std::string& filename) get_level()->load_song(); apply_bonuses(); + + scrolling_timer.init(true); } World::World(const std::string& subset, int level_nr) @@ -73,6 +75,8 @@ World::World(const std::string& subset, int level_nr) get_level()->load_song(); apply_bonuses(); + + scrolling_timer.init(true); } void @@ -257,7 +261,7 @@ void 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 @@ World::action(double frame_ratio) // 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; diff --git a/src/world.h b/src/world.h index 57d803d16..c8716888a 100644 --- a/src/world.h +++ b/src/world.h @@ -44,6 +44,9 @@ private: Level* level; Player tux; + Timer scrolling_timer; + float moved_scroll_x; + int distro_counter; bool counting_distros; int currentmusic; @@ -76,7 +79,7 @@ public: void draw(); void action(double frame_ratio); - void keep_in_bounds(); + void scrolling(); // camera scrolling void play_music(int musictype); int get_music_type(); -- 2.11.0