Pomppii paremmin
authorekku
Mon, 24 Nov 2008 22:05:19 +0000
changeset 104 5cb116dc0759
parent 103 dcf86a4a92b4
child 105 91e3f3806b31
Pomppii paremmin
src/proto2/Physics.cc
--- a/src/proto2/Physics.cc	Mon Nov 24 21:51:58 2008 +0000
+++ b/src/proto2/Physics.cc	Mon Nov 24 22:05:19 2008 +0000
@@ -5,6 +5,7 @@
 #include <algorithm>
 #include <functional>
 #include <cmath>
+#include <assert.h>
 
 PhysicsWorld::PhysicsWorld (Vector gravity, Vector dimensions)
     : tick_timer(PHYSICS_TICK_MS), gravity(gravity), dimensions(dimensions), terrain(dimensions.x, std::vector<TerrainType>(dimensions.y, DIRT)) {
@@ -179,7 +180,7 @@
 				reached = position + unitVector*(i-1);
 				collided = true;
 				this->bounce(world.getNormal(tmpVector+shape[sh], tmpVector-unitVector+shape[sh]));
-				this->velocity *= 0.6;
+				this->velocity *= 0.4;
 				if(abs(this->velocity.x) < minVelocity && (abs(this->velocity.y) < minVelocity)) {
 					this->inAir = false;
 					this->velocity = Vector(0,0);
@@ -313,16 +314,21 @@
 	std::vector<Vector> frees;
 	Vector hit = Vector((int)hitPoint.x, (int)hitPoint.y);
 	Vector prev = Vector((int)prevPoint.x, (int)prevPoint.y);
+
+	assert(hit != prev);
+	
 	int dirIdx = getDirectionIndex(hit-prev);
+	Engine::log(DEBUG, "physics.getNormal ") << dirIdx;
+
 	for(int i = 1; i <= 2; i++) {
-		if(getType(hit+DIRECTIONS[dirIdx+i]) == EMPTY)
-			frees.push_back(DIRECTIONS[dirIdx+i]);
+		if(getType(hit+DIRECTIONS[(dirIdx+i) % 8]) == EMPTY)
+			frees.push_back(DIRECTIONS[(dirIdx+i) % 8]);
 		else
 			break;
 	}
 	for(int i = 1; i <= 2; i++) {
-		if(getType(hit+DIRECTIONS[dirIdx-i]) == EMPTY)
-			frees.push_back(DIRECTIONS[dirIdx-i]);
+		if(getType(hit+DIRECTIONS[(dirIdx-i) % 8]) == EMPTY)
+			frees.push_back(DIRECTIONS[(dirIdx-i) % 8]);
 		else
 			break;
 	}