From: Wolfgang Becker Date: Mon, 14 Aug 2006 19:33:32 +0000 (+0000) Subject: ugly hack to fix grabbing X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=0dcf316ce925bdd7500386bf139d8b797bb04e15;p=supertux.git ugly hack to fix grabbing SVN-Revision: 4186 --- diff --git a/data/levels/test/grab.stl b/data/levels/test/grab.stl index 1c12110a0..c4967e7ee 100644 --- a/data/levels/test/grab.stl +++ b/data/levels/test/grab.stl @@ -38,8 +38,8 @@ ) (spawnpoint (name "main") - (x 288) - (y 480) + (x 256) + (y 256) ) (trampoline (x 128) @@ -93,6 +93,18 @@ (x 608) (y 512) ) + (rock + (x 352) + (y 192) + ) + (rock + (x 352) + (y 224) + ) + (rock + (x 352) + (y 320) + ) (tilemap (z-pos -100) (solid #f) @@ -107,7 +119,7 @@ (speed 1) (width 30) (height 35) - (tiles 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 48 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 48 1755 1756 1757 0 0 0 0 0 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1419 66 1419 66 66 0 0 0 0 0 0 0 0 1755 1756 1757 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1420 66 1420 66 66 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 67 0 67 66 66 0 0 0 0 0 0 0 0 1755 1756 1757 0 0 0 0 0 0 0 0 0 0 0 0 0 0 67 321 66 0 321 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 67 66 66 321 66 0 0 0 0 0 0 0 0 1755 1756 1757 0 0 0 0 0 0 0 0 0 0 0 0 0 0 67 66 66 66 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 48 48 48 48 48 48 48 48 48 48 67 66 0 67 321 0 0 0 0 0 0 0 0 1755 1756 1757 0 0 0 0 0 0 0 0 0 0 0 0 0 0 67 66 321 66 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 67 66 321 0 0 0 0 0 0 0 0 0 0 1755 1756 1757 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 83 83 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1755 1756 1757 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 66 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1001 1002 1001 1002 1001 1002 1001 1002 1001 1002 67 66 321 66 66 1002 321 321 1001 1002 1001 1002 1001 1755 1756 1757 0 0 0 0 1005 1006 1005 1006 1005 1006 1005 1006 1005 1006 67 66 66 66 66 1006 1005 1006 1005 1006 1005 1006 1005 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1755 1756 1757 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1755 1756 1757 0 0 0 0 0 0 0 0 0 0 0 48 0 0 0 0 48 48 48 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 48 48 48 48 48 48 0 0 0 0 0 0 0 0 0 0 1755 1756 1757 48 48 48 48 48 48 48 48 0 0 0 0 0 0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0 0 0 0 0 0 0 1420 66 1420 66 66 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 48 0 0 0 0 0 67 0 67 66 66 0 0 0 0 0 0 0 0 1755 1756 1757 0 0 0 0 0 0 0 0 48 0 0 0 0 0 67 321 66 0 321 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 67 66 66 321 66 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 48 0 0 0 0 0 67 66 66 66 0 0 0 0 0 0 0 0 0 0 1756 1756 1756 1756 1756 1756 1755 1756 1757 48 48 48 48 48 48 48 67 66 0 67 321 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 67 66 321 66 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1755 1756 1757 0 0 0 0 0 0 0 67 66 321 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 83 83 0 0 0 0 0 0 0 1755 1756 1757 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 66 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1001 1002 1001 1002 1001 1002 1001 1002 1001 1002 67 66 321 66 66 1002 321 321 1001 1002 1001 1002 1001 1755 1756 1757 0 0 0 0 1005 1006 1005 1006 1005 1006 1005 1006 1005 1006 67 66 66 66 66 1006 1005 1006 1005 1006 1005 1006 1005 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1755 1756 1757 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1755 1756 1757 0 0 0 0 0 0 0 0 0 0 0 48 0 0 0 0 48 48 48 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 48 48 48 48 48 48 0 0 0 0 0 0 0 0 0 0 1755 1756 1757 48 48 48 48 48 48 48 48 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1755 1756 1757 0 0 0 0 0 0 0 0 0 0 0 48 0 0 0 0 0 0 0 0 48 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 48 48 48 48 48 48 48 48 48 48 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 48 0 0 0 0 0 0 0 0 0 0 0 0 0 0 48 0 0 0 0 0 0 0 0 0 0 0 0 0 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) ) (tilemap (z-pos 100) diff --git a/src/object/player.cpp b/src/object/player.cpp index 7297a39a9..0379da314 100644 --- a/src/object/player.cpp +++ b/src/object/player.cpp @@ -233,8 +233,6 @@ Player::update(float elapsed_time) if (deactivated) apply_friction(); - try_grab = false; - // extend/shrink tux collision rectangle so that we fall through/walk over 1 // tile holes if(fabsf(physic.get_velocity_x()) > MAX_WALK_XM) { @@ -563,8 +561,6 @@ Player::handle_vertical_input() void Player::handle_input() { - Sector* sector = Sector::current(); - if (ghost_mode) { handle_input_ghost(); return; @@ -611,10 +607,35 @@ Player::handle_input() } /* grabbing */ + try_grab(); + + if(!controller->hold(Controller::ACTION) && grabbed_object) { + // move the grabbed object a bit away from tux + Vector pos = get_pos() + + Vector(dir == LEFT ? -bbox.get_width()-1 : bbox.get_width()+1, + bbox.get_height()*0.66666 - 32); + Rect dest(pos, pos + Vector(32, 32)); + if(Sector::current()->is_free_of_statics(dest)) { + MovingObject* moving_object = dynamic_cast (grabbed_object); + if(moving_object) { + moving_object->set_pos(pos); + } else { + log_debug << "Non MovingObjetc grabbed?!?" << std::endl; + } + grabbed_object->ungrab(*this, dir); + grabbed_object = NULL; + } + } +} + +void +Player::try_grab() +{ if(controller->hold(Controller::ACTION) && !grabbed_object - && try_grab && !duck) { + && !duck) { + Sector* sector = Sector::current(); Vector pos; - if(grab_dir == LEFT) { + if(dir == LEFT) { pos = Vector(bbox.get_left() - 5, bbox.get_bottom() - 16); } else { pos = Vector(bbox.get_right() + 5, bbox.get_bottom() - 16); @@ -638,24 +659,6 @@ Player::handle_input() } } } - - if(!controller->hold(Controller::ACTION) && grabbed_object) { - // move the grabbed object a bit away from tux - Vector pos = get_pos() + - Vector(dir == LEFT ? -bbox.get_width()-1 : bbox.get_width()+1, - bbox.get_height()*0.66666 - 32); - Rect dest(pos, pos + Vector(32, 32)); - if(Sector::current()->is_free_of_statics(dest)) { - MovingObject* moving_object = dynamic_cast (grabbed_object); - if(moving_object) { - moving_object->set_pos(pos); - } else { - log_debug << "Non MovingObjetc grabbed?!?" << std::endl; - } - grabbed_object->ungrab(*this, dir); - grabbed_object = NULL; - } - } } void @@ -955,8 +958,6 @@ Player::collision_solid(const CollisionHit& hit) if(hit.left || hit.right) { physic.set_velocity_x(0); - try_grab = true; - grab_dir = hit.left ? LEFT : RIGHT; } // crushed? @@ -979,8 +980,7 @@ Player::collision(GameObject& other, const CollisionHit& hit) if(hit.left || hit.right) { physic.set_velocity_x(0); - try_grab = true; - grab_dir = hit.left ? LEFT : RIGHT; + try_grab(); //grab objects right now, in update it will be too late } #ifdef DEBUG assert(dynamic_cast (&other) != NULL); diff --git a/src/object/player.hpp b/src/object/player.hpp index 0fecfef0a..a66f80b1e 100644 --- a/src/object/player.hpp +++ b/src/object/player.hpp @@ -279,8 +279,7 @@ private: Sprite* bigtux_star; Vector floor_normal; - bool try_grab; - Direction grab_dir; + void try_grab(); bool ghost_mode; /**< indicates if Tux should float around and through solid objects */