Kirjottelin jotain uuden t?rm?ystarkistuksen tapasta, se kyll? bugaa jotenkin.
--- a/src/proto2/GameState.hh Fri Nov 28 12:26:39 2008 +0000
+++ b/src/proto2/GameState.hh Fri Nov 28 13:00:24 2008 +0000
@@ -14,10 +14,13 @@
const uint16_t MAP_WIDTH = 800;
const uint16_t MAP_HEIGHT = 600;
const float MAP_GRAVITY = 1200.0;
+const float COLLISION_ELASTICITY = 0.4;
+
const float PLAYER_MASS = 10.0;
const float PLAYER_MOVE_FORCE = 5000.0;
const float PLAYER_INITIAL_X = 400.0;
const float PLAYER_INITIAL_Y = 300.0;
+const float PLAYER_MIN_SPEED = 10.0;
const float CROSSHAIR_ANGLE_SPEED = PI/40; // TODO: Adjust this
const float PLAYER_AIM_MIN = -KG_PI/2; // TODO: -- || --
--- a/src/proto2/Physics.cc Fri Nov 28 12:26:39 2008 +0000
+++ b/src/proto2/Physics.cc Fri Nov 28 13:00:24 2008 +0000
@@ -1,6 +1,7 @@
#include "Physics.hh"
#include "Engine.hh"
+#include "GameState.hh"
#include <algorithm>
#include <functional>
@@ -43,61 +44,61 @@
Vector PhysicsObject::walk (bool right) {
Vector cursor = right ? this->position + Vector(1,0) : this->position + Vector(-1,0);
Vector reached = this->position;
-
+
//for(int steps = 0; steps < 3; steps++) {
- // Go up but not if the wall is over two pixels
- if(world.getType(cursor) != EMPTY) {
- for(int height = 0, max = 3; height < max+42; height++) {
-
- if(height >= max)
+ // Go up but not if the wall is over two pixels
+ if(world.getType(cursor) != EMPTY) {
+ for(int height = 0, max = 3; height < max+42; height++) {
+
+ if(height >= max)
+ return reached;
+
+ cursor.y--;
+ if(world.getType(cursor) == EMPTY) {
+ // Check that the other parts of the worm don't collide with anything
+ if(possibleLocation(cursor)) {
+ reached = cursor;
+ continue;
+ } else {
+ // Can't get any further
return reached;
-
- cursor.y--;
- if(world.getType(cursor) == EMPTY) {
- // Check that the other parts of the worm don't collide with anything
- if(possibleLocation(cursor)) {
- reached = cursor;
- continue;
- } else {
- // Can't get any further
- return reached;
- }
}
}
- } else {
- if(possibleLocation(cursor)) {
- reached = cursor;
- }
- // Start checking if the lower squares are empty
-
- for(int depth = 0, max = 3; depth < max+42; depth++) {
-
- if(depth >= max) {
- // We can start a free fall now
+ }
+ } else {
+ if(possibleLocation(cursor)) {
+ reached = cursor;
+ }
+ // Start checking if the lower squares are empty
+
+ for(int depth = 0, max = 3; depth < max+42; depth++) {
+
+ if(depth >= max) {
+ // We can start a free fall now
//
// TODO it should be set inAir if it falls from a cliff
//this->inAir = true;
-
- // Put some speed there to make loke smoother
- //this->velocity.y = -5;
+
+ // Put some speed there to make loke smoother
+ //this->velocity.y = -5;
+ return reached;
+ }
+
+ cursor.y++;
+ if(world.getType(cursor) == EMPTY) {
+ // Check that the other parts of the worm don't collide with anything
+ if(possibleLocation(cursor)) {
+ reached = cursor;
+ continue;
+ } else {
+ // Can't get any further
return reached;
}
-
- cursor.y++;
- if(world.getType(cursor) == EMPTY) {
- // Check that the other parts of the worm don't collide with anything
- if(possibleLocation(cursor)) {
- reached = cursor;
- continue;
- } else {
- // Can't get any further
- return reached;
- }
- }
}
- }
-
+ }
+ }
+
// cursor.x += right ? 1 : -1;
//}
return reached;
@@ -154,7 +155,35 @@
Vector newPosition = posAfterTick /*+ (velAfterTick * PHYSICS_TICK_MS)/1000*/;
this->velocity = velAfterTick;
+ /*
// Collision detection
+ bool collided = false;
+
+ const Vector diffVec = newPosition-position;
+ const Vector unitVector = diffVec / diffVec.length();
+ Vector reached = position;
+
+ while ((position-reached).length() < diffVec.length()) {
+ // Check if any of the shapes points collide
+ for (int i = 0; i < shape.size(); i ++) {
+ if (world.getType(reached+shape[i]) != EMPTY) { // Collision
+ reached = reached - unitVector; // Return to last point
+ collided = true;
+ this->bounce(world.getNormal(reached+shape[i], reached-unitVector+shape[i]));
+ this->velocity *= COLLISION_ELASTICITY;
+ if (abs(this->velocity.x) < PLAYER_MIN_SPEED && (abs(this->velocity.y) < PLAYER_MIN_SPEED)) {
+ this->inAir = false;
+ this->velocity = Vector(0,0);
+ }
+ break;
+ }
+ }
+ if (collided)
+ break;
+ reached += unitVector;
+ }
+ */
+
bool collided = false;