From cd728101c06cd0280fe3f57dcc3f934a217fdcc9 Mon Sep 17 00:00:00 2001 From: Ingo Ruhnke Date: Tue, 20 Apr 2004 17:58:12 +0000 Subject: [PATCH] - stop tux if he ran into a block, no more accelerating while standing infront of a block SVN-Revision: 597 --- src/physic.cpp | 12 ++++++++++++ src/physic.h | 3 +++ src/player.cpp | 30 ++++++++++++++++++++---------- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/physic.cpp b/src/physic.cpp index edd976cd3..3b90c6ef2 100644 --- a/src/physic.cpp +++ b/src/physic.cpp @@ -85,6 +85,18 @@ Physic::get_velocity_y() } void +Physic::set_acceleration_x(float nax) +{ + ax = nax; +} + +void +Physic::set_acceleration_y(float nay) +{ + ay = -nay; +} + +void Physic::set_acceleration(float nax, float nay) { ax = nax; diff --git a/src/physic.h b/src/physic.h index 8e467d777..558cebd4c 100644 --- a/src/physic.h +++ b/src/physic.h @@ -51,6 +51,9 @@ public: */ void set_acceleration(float ax, float ay); + void set_acceleration_x(float ax); + void set_acceleration_y(float ay); + float get_acceleration_x(); float get_acceleration_y(); diff --git a/src/player.cpp b/src/player.cpp index 4f52d343a..baedf1253 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -183,17 +183,27 @@ Player::action(double frame_ratio) previous_base = base; physic.apply(frame_ratio, base.x, base.y); - if(dying == DYING_NOT) { + if(dying == DYING_NOT) + { + base_type target = base; + collision_swept_object_map(&old_base, &base); + + // Don't accelerate Tux if he is running against a wall + if (target.x != base.x) + { + physic.set_velocity_x(0); + } + // special exception for cases where we're stuck under tiles after // being ducked. In this case we drift out if(!duck && on_ground() && old_base.x == base.x && old_base.y == base.y - && collision_object_map(&base)) { - base.x += frame_ratio * WALK_SPEED * (dir ? 1 : -1); - previous_base = old_base = base; + && collision_object_map(&base)) { + base.x += frame_ratio * WALK_SPEED * (dir ? 1 : -1); + previous_base = old_base = base; } keep_in_bounds(); - } + } if (dying == DYING_NOT) { @@ -273,10 +283,10 @@ Player::action(double frame_ratio) if (get_current_music() == HERRING_MUSIC && !invincible_timer.check()) { /* - no, we are no more invincible - or we were not in invincible mode - but are we in hurry ? - */ + no, we are no more invincible + or we were not in invincible mode + but are we in hurry ? + */ // FIXME: Move this to gamesession if (GameSession::current()->time_left.get_left() < TIME_WARNING) @@ -284,7 +294,7 @@ Player::action(double frame_ratio) /* yes, we are in hurry stop the herring_song, prepare to play the correct fast level_song ! - */ + */ set_current_music(HURRYUP_MUSIC); } else -- 2.11.0