src/Rope.cc
changeset 305 56799ec8d7be
parent 296 4d3ebaa29430
child 311 440763821484
--- a/src/Rope.cc	Mon Dec 08 18:36:06 2008 +0000
+++ b/src/Rope.cc	Mon Dec 08 20:23:18 2008 +0000
@@ -6,7 +6,7 @@
 #include <stdexcept>
 
 Rope::Rope(Player &player) : 
-    PhysicsObject(player.state.world, ROPE_MASS, Vector(0,0), Vector(0,0), ROPE, 0.00, false), player(player), state(ROPE_FOLDED) 
+    PhysicsObject(player.state.world, ROPE_MASS, Vector(0,0), Vector(0,0), ROPE, 0.00, false), player(player), state(ROPE_FOLDED), pivotObject(NULL) 
 {
     // XXX: better shape
     std::vector<Vector> shape(4);
@@ -38,10 +38,21 @@
 }
 
 void Rope::onCollision (Vector collisionPoint, PhysicsObject *other) {
-    (void) other;
+
+    if (other != NULL) {
+        if (other->getType() == PLAYER) {
+            Player *target = dynamic_cast<Player*>(other);
+            if (target == &(this->player))
+                return;
+            pivotObject = target;            
+        } else if (other->getType() == PROJECTILE) {
+            return;
+        }
+    }
 
     // attached to something!
     state = ROPE_FIXED;
+    velocity = Vector(0,0);
         
     // Ropes location will be used as the pivot point, so move the location to the collisionPoint.
     // Currently the position is something like one pixel away from the collisionPoint where there isn't ground.