--- a/src/proto2/GameState.hh Fri Nov 21 21:18:22 2008 +0000
+++ b/src/proto2/GameState.hh Fri Nov 21 22:31:23 2008 +0000
@@ -29,10 +29,10 @@
PhysicsObject((PhysicsWorld &) state, PLAYER_MASS, position, Vector(0, 0)), state(state), visible(visible) {
std::vector<Vector> shape(4);
- shape[0] = Vector(0,-6);
- shape[1] = Vector(4,0);
- shape[2] = Vector(0,6);
- shape[3] = Vector(-4,0);
+ shape[0] = Vector(0,-9);
+ shape[1] = Vector(6,0);
+ shape[2] = Vector(0,9);
+ shape[3] = Vector(-6,0);
// Initialize the shape of the player (salmiakki shape)
setShape(shape);
}
--- a/src/proto2/Physics.cc Fri Nov 21 21:18:22 2008 +0000
+++ b/src/proto2/Physics.cc Fri Nov 21 22:31:23 2008 +0000
@@ -71,31 +71,63 @@
Vector tmpVector = position;
Vector reached = position;
- int steps = (int) (newPosition-position).length();
+ int steps = (int) (newPosition-position).length() + 2;
+
+ //Engine::log(DEBUG, "physics.update_position") << unitVector-newPosition;
+ //Vector foo = position+unitVector*steps-newPosition;
+ //Engine::log(DEBUG, "PhysicsObject.updatePosition") << "Virhe: "<< foo;
+
for(int i = 0; i < steps; i++) {
tmpVector += unitVector;
- if(world.getType(tmpVector) != EMPTY) {
- //Engine::log(DEBUG, "physics.update_position") << "hit something";
- // Then we have hit something
- reached = position + unitVector*(i-1);
- collided = true;
- break;
- } else {
+ // Check if any of the four corners of worm collides
+ if(velocity.y > 0) {
+ if(world.getType(tmpVector+shape[2])) {
+ reached = position + unitVector*(i-1);
+ collided = true;
+ this->velocity.y *= -0.3;
+ break;
+ }
+ } else {
+ if(world.getType(tmpVector+shape[0])) {
+ reached = position + unitVector*(i-1);
+ collided = true;
+ this->velocity.y *= -0.3;
+ break;
+ }
+ }
+
+ if(velocity.x > 0) {
+ if(world.getType(tmpVector+shape[1])) {
+ reached = position + unitVector*(i-1);
+ collided = true;
+ this->velocity.x *= -0.5;
+ break;
+ }
+ } else {
+ if(world.getType(tmpVector+shape[3])) {
+ reached = position + unitVector*(i-1);
+ collided = true;
+ this->velocity.x *= -0.5;
+ break;
+ }
+ }
//Engine::log(DEBUG, "physics.update_position") << "didnt hit";
- }
}
- // In case of some float error
+ // In case of some float error check the final coordinate
if(!collided) {
- if(world.getType(newPosition)) {
- // There was error, and there is ground
- newPosition = tmpVector;
+ if(world.getType(newPosition+shape[0]) != EMPTY || (world.getType(newPosition+shape[1]) != EMPTY)
+ || (world.getType(newPosition+shape[2]) != EMPTY) || (world.getType(newPosition+shape[3]) != EMPTY)) {
+
+ Engine::log(DEBUG, "physics.update_position") << "didnt hit";
+ // There was error, and there is ground
+ //newPosition = tmpVector;
} else {
// This means everything was ok, so no need to do anything
}
} else {
newPosition = reached;
- this->velocity = Vector(0, 0);
+ //this->velocity = Vector(0, 0);
//TODO: it shouldn't just stop on collision
}
this->position = newPosition;