Pomppimisia.
authorterom
Tue, 18 Nov 2008 21:54:57 +0000
changeset 64 81302d3350eb
parent 63 1969a1447ef9
child 65 be91c125f741
Pomppimisia.
src/proto2/GameState.hh
src/proto2/Physics.cc
src/proto2/Physics.hh
--- a/src/proto2/GameState.hh	Tue Nov 18 21:32:26 2008 +0000
+++ b/src/proto2/GameState.hh	Tue Nov 18 21:54:57 2008 +0000
@@ -14,7 +14,7 @@
 const float MAP_HEIGHT = 100.0;
 const float MAP_GRAVITY = 9.81;
 const float PLAYER_MASS = 10.0;
-const float PLAYER_MOVE_FORCE = 20.0;
+const float PLAYER_MOVE_FORCE = 500.0;
 
 // forward-declare GameState
 class GameState;
--- a/src/proto2/Physics.cc	Tue Nov 18 21:32:26 2008 +0000
+++ b/src/proto2/Physics.cc	Tue Nov 18 21:54:57 2008 +0000
@@ -39,24 +39,39 @@
 
     //TODO Handle the object as a square or a polygon
     
-    Engine::log(DEBUG, "physics.update_position") << "position=" << newPosition << ", velocity=" << velocity;
+//    Engine::log(DEBUG, "physics.update_position") << "position=" << newPosition << ", velocity=" << velocity;
 
+    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(this->velocity.x < 0.1)
+		if (abs(this->velocity.x) < 0.1)
 			this->velocity.x = 0;
+
+        collided = true;
+    } else {
+        this->position.x = newPosition.x;
     }
-	else if(newPosition.y < 0 || (newPosition.y >= world.dimensions.y)) {
+    
+    if (newPosition.y <= 0 || (newPosition.y >= world.dimensions.y)) {
 		this->velocity.y *= -0.3;
 
-		if(this->velocity.y < 0.1)
+		if (abs(this->velocity.y) < 0.1)
 			this->velocity.y = 0;
-	}
-	else {
+
+        // Friction
+        if(this->velocity.y == 0)
+            this->velocity.x = 0;
+
+        collided = true;
+	} else {
+        this->position.y = newPosition.y;
+    }
+    
+    if(!collided) {
         this->position = newPosition;
     }
 }
--- a/src/proto2/Physics.hh	Tue Nov 18 21:32:26 2008 +0000
+++ b/src/proto2/Physics.hh	Tue Nov 18 21:54:57 2008 +0000
@@ -5,7 +5,7 @@
 
 #include <ClanLib/core.h>
 
-const uint16_t PHYSICS_TICK_MS = 100;
+const uint16_t PHYSICS_TICK_MS = 10;
 
 // forward-declare
 class PhysicsObject;