diff -r 2b856bc88e6d -r e36f5e1a1c8d src/PhysicsObject.cc --- a/src/PhysicsObject.cc Mon Dec 08 01:31:09 2008 +0000 +++ b/src/PhysicsObject.cc Mon Dec 08 01:38:43 2008 +0000 @@ -5,9 +5,10 @@ #include #include -PhysicsObject::PhysicsObject (PhysicsWorld &world, float mass, Vector position, Vector velocity, ObjectType type, bool enabled) : +PhysicsObject::PhysicsObject (PhysicsWorld &world, float mass, Vector position, Vector velocity, ObjectType type, + float collision_elasticity, bool enabled) : world(world), position(position), velocity(velocity), mass(mass), inAir(true), aim(0), facing(FACING_RIGHT), - alive(false), shouldDelete(false), type(type), pivot(NULL) + alive(false), shouldDelete(false), type(type), pivot(NULL), collision_elasticity(collision_elasticity) { if (enabled) enable(); @@ -187,30 +188,32 @@ bool collided = false; Vector collisionPoint; - const Vector diffVec = newPosition-position; + const Vector diffVec = newPosition - position; const Vector unitVector = diffVec / diffVec.length(); Vector reached = position; - while ((position-reached).sqrLength() < diffVec.sqrLength()) { + while ((position - reached).sqrLength() < diffVec.sqrLength()) { reached += unitVector; + // Check if any of the shapes points collide for (uint64_t i = 0; i < shape.size(); i++) { if (world.collides(reached+shape[i])) { // Collision collisionPoint = reached+shape[i]; - if (inAir) { - this->bounce(world.getNormal(reached+shape[i], - reached-unitVector+shape[i])); - } + if (inAir) + this->bounce(world.getNormal(reached+shape[i], reached-unitVector+shape[i])); + reached = reached - unitVector; // Return to last point collided = true; - if (this->velocity.sqrLength() < PLAYER_MIN_SPEED * PLAYER_MIN_SPEED) { + + if (this->velocity.sqrLength() < PLAYER_MIN_SPEED * PLAYER_MIN_SPEED) this->velocity = Vector(0,0); - } + break; } } + if (collided) break; }