Foo
authorekku
Thu, 20 Nov 2008 21:22:03 +0000
changeset 82 8f60abd6a083
parent 81 4a91cf6f5cc7
child 83 cbba9729e92b
Foo
src/proto2/Physics.cc
--- a/src/proto2/Physics.cc	Thu Nov 20 19:58:41 2008 +0000
+++ b/src/proto2/Physics.cc	Thu Nov 20 21:22:03 2008 +0000
@@ -33,15 +33,6 @@
     
 void PhysicsObject::updatePosition () {
 
-    // Check if the player is moving on the ground
-    /*if (this->velocity.y == 0 && (position.y >= world.dimensions.y - 3)) {
-        position.x += 50 * velocity.x * (PHYSICS_TICK_MS / 1000.0);
-        velocity.x = 0;
-        return;
-    }*/
-
-    // If not moving on the ground, apply normal physics
-
     // Calculate gravity's influence on the velocity vector
     this->velocity += world.gravity * (PHYSICS_TICK_MS / 1000.0);
         
@@ -49,15 +40,15 @@
 
     //TODO Handle the object as a square or a polygon
     
-//    Engine::log(DEBUG, "physics.update_position") << "position=" << newPosition << ", velocity=" << velocity;
-  /*
     bool collided = false;
 
     //goes 1 unit forward every step and check if has hit anything
     Vector unitVector = (newPosition-position) / (newPosition-position).length();
-    Vector tmpVector = position;
+    
+	Vector tmpVector = position;
     Vector reached = position;
-    for(int i = 0; i < newPosition.length(); i++) {
+	int steps = (int) (newPosition-position).length();
+    for(int i = 0; i < steps; i++) {
         tmpVector += unitVector;
         if(world.getType(tmpVector) != EMPTY) {
 			//Engine::log(DEBUG, "physics.update_position") << "hit something";
@@ -84,46 +75,6 @@
         //TODO: it shouldn't just stop on collision
     }
     this->position = newPosition;
-    
-*/
-    bool collided = false;
-     
-    if (newPosition.x < 0 || (newPosition.x > world.dimensions.x)) {
-        // CRASH!
-        this->velocity.x *= -0.5;
-        
-        // If the velocity drops under some fixed constant we decide it is zero.
-        // This is to prevent the object from bouncing eternally.
-        if (abs(this->velocity.x) < 0.1)
-            this->velocity.x = 0;
-
-        collided = true;
-    } else {
-        this->position.x = newPosition.x;
-    }
-    
-    if (newPosition.y <= 0 || (newPosition.y >= world.dimensions.y)) {
-        this->velocity.y *= -0.3;
-
-
- 
-        if (abs(this->velocity.y) < 0.1) {
-            this->velocity.y = 0;
-            // Static friction
-            this->velocity.x *= 0.95;
-        } else {
-            // Kinetic friction
-            this->velocity.x *= 0.75;
-        }
-
-        collided = true;
-    } else {
-        this->position.y = newPosition.y;
-    }
-    
-    if(!collided) {
-        this->position = newPosition;
-    }
 }
 
 bool PhysicsWorld::collided (Vector oldPos, Vector newPos) {