From: Matthias Braun Date: Sat, 11 Mar 2006 23:33:44 +0000 (+0000) Subject: disable gravity for tux when he is on ground, this improves handling of 1 tile holes X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=fb0352196d3ade68ccae3e2aa25a8be3e8a9ade0;p=supertux.git disable gravity for tux when he is on ground, this improves handling of 1 tile holes SVN-Revision: 3083 --- diff --git a/data/images/creatures/zeekling/zeekling.sprite b/data/images/creatures/zeekling/zeekling.sprite index 3909abf87..dccbcbf43 100644 --- a/data/images/creatures/zeekling/zeekling.sprite +++ b/data/images/creatures/zeekling/zeekling.sprite @@ -32,5 +32,7 @@ (name "diving-right") (x-offset 2) (y-offset 4) - (mirror-action "left"))) + (mirror-action "diving-left") + ) +) diff --git a/data/levels/world2/castle.stl b/data/levels/world2/castle.stl index d14ce395f..550112e7f 100644 --- a/data/levels/world2/castle.stl +++ b/data/levels/world2/castle.stl @@ -8,7 +8,7 @@ (start_pos_x 100) (start_pos_y 100) (background "") - (music "music/music/chipdisko.ogg") + (music "music/chipdisko.ogg") (bkgd_red_top 60) (bkgd_green_top 70) (bkgd_blue_top 110) diff --git a/src/badguy/badguy.cpp b/src/badguy/badguy.cpp index bafa67bf4..902a12f86 100644 --- a/src/badguy/badguy.cpp +++ b/src/badguy/badguy.cpp @@ -170,15 +170,15 @@ BadGuy::collision_player(Player& player, const CollisionHit& ) kill_fall(); return ABORT_MOVE; } + // hit from above? if(player.get_movement().y - get_movement().y > 0 && player.get_bbox().p2.y < (get_bbox().p1.y + get_bbox().p2.y) / 2) { // if it's not possible to squish us, then this will hurt - if(!collision_squished(player)) - player.kill(Player::SHRINK); - - return FORCE_MOVE; + if(collision_squished(player)) + return CONTINUE; } + player.kill(Player::SHRINK); return FORCE_MOVE; } diff --git a/src/badguy/badguy.hpp b/src/badguy/badguy.hpp index 6980ba9a1..278d3e663 100644 --- a/src/badguy/badguy.hpp +++ b/src/badguy/badguy.hpp @@ -72,7 +72,7 @@ public: /** Writes out the badguy into the included lisp::Writer. Useful e.g. when * converting an old-format level to the new format. */ - virtual void save(lisp::Writer& ); + virtual void save(lisp::Writer& writer); Vector get_start_position() const { diff --git a/src/object/player.cpp b/src/object/player.cpp index 199ff5a79..d7458647e 100644 --- a/src/object/player.cpp +++ b/src/object/player.cpp @@ -155,19 +155,21 @@ Player::set_controller(Controller* controller) void Player::update(float elapsed_time) { + // do we need to enable gravity again? + if(on_ground_flag) { + Rect lower = bbox; + lower.move(Vector(0, 4.0)); + if(Sector::current()->is_free_space(lower)) { + physic.enable_gravity(true); + on_ground_flag = false; + } + } + if(dying && dying_timer.check()) { dead = true; return; } - // fixes the "affected even while blinking" bug - if (safe_timer.started() && this->get_group() != COLGROUP_MOVING_ONLY_STATIC) { - this->set_group(COLGROUP_MOVING_ONLY_STATIC); - } - else if (!safe_timer.started() && this->get_group() == COLGROUP_MOVING_ONLY_STATIC) { - this->set_group(COLGROUP_MOVING); - } - if(!controller->hold(Controller::ACTION) && grabbed_object) { // move the grabbed object a bit away from tux Vector pos = get_pos() + @@ -192,7 +194,6 @@ Player::update(float elapsed_time) handle_input(); movement = physic.get_movement(elapsed_time); - on_ground_flag = false; #if 0 // special exception for cases where we're stuck under tiles after @@ -326,7 +327,7 @@ Player::handle_horizontal_input() // extend/shrink tux collision rectangle so that we fall through/walk over 1 // tile holes if(fabsf(vx) > MAX_WALK_XM) { - bbox.set_width(33); + bbox.set_width(34); } else { bbox.set_width(31.8); } @@ -744,6 +745,8 @@ Player::collision(GameObject& other, const CollisionHit& hit) floor_normal.y = (floor_normal.y * 0.9) + (hit.normal.y * 0.1); } + // disable gravity + physic.enable_gravity(false); } else if(hit.normal.y > 0) { // bumped against the roof physic.set_velocity_y(.1); } @@ -770,8 +773,12 @@ Player::collision(GameObject& other, const CollisionHit& hit) } BadGuy* badguy = dynamic_cast (&other); - if(badguy != NULL) + if(badguy != NULL) { + if(safe_timer.started()) + return FORCE_MOVE; + return CONTINUE; + } return FORCE_MOVE; } @@ -842,7 +849,6 @@ Player::move(const Vector& vector) bbox.set_size(31.8, 63.8); else bbox.set_size(31.8, 31.8); - on_ground_flag = false; duck = false; last_ground_y = vector.y; diff --git a/src/physic.cpp b/src/physic.cpp index 2a3f95cf7..e9fe94d97 100644 --- a/src/physic.cpp +++ b/src/physic.cpp @@ -22,7 +22,7 @@ #include "physic.hpp" Physic::Physic() - : ax(0), ay(0), vx(0), vy(0), gravity_enabled(true) + : ax(0), ay(0), vx(0), vy(0), gravity_enabled_flag(true) { } @@ -34,7 +34,7 @@ void Physic::reset() { ax = ay = vx = vy = 0; - gravity_enabled = true; + gravity_enabled_flag = true; } void @@ -112,13 +112,19 @@ Physic::get_acceleration_y() void Physic::enable_gravity(bool enable_gravity) { - gravity_enabled = enable_gravity; + gravity_enabled_flag = enable_gravity; +} + +bool +Physic::gravity_enabled() const +{ + return gravity_enabled_flag; } Vector Physic::get_movement(float elapsed_time) { - float grav = gravity_enabled ? 1000 : 0; + float grav = gravity_enabled_flag ? 1000 : 0; Vector result( vx * elapsed_time + ax * elapsed_time * elapsed_time, diff --git a/src/physic.hpp b/src/physic.hpp index eee215612..828b1e105 100644 --- a/src/physic.hpp +++ b/src/physic.hpp @@ -62,6 +62,7 @@ public: /// Enables or disables handling of gravity. void enable_gravity(bool gravity_enabled); + bool gravity_enabled() const; Vector get_movement(float elapsed_time); @@ -71,7 +72,7 @@ private: /// horizontal and vertical velocity float vx, vy; /// should we respect gravity in out calculations? - bool gravity_enabled; + bool gravity_enabled_flag; }; #endif