--- a/src/proto2/Physics.cc Thu Nov 20 15:01:17 2008 +0000
+++ b/src/proto2/Physics.cc Thu Nov 20 16:23:01 2008 +0000
@@ -90,6 +90,25 @@
}
}
+bool PhysicsWorld::collided (Vector oldPos, Vector newPos) {
+ int deltaX = oldPos.x - newPos.x;
+ int deltaY = oldPos.y - newPos.y;
+ double distance = sqrt(deltaX * deltaX + deltaY * deltaY);
+ double xInc = (double) deltaX / distance;
+ double yInc = (double) deltaY / distance;
+ double currentX = oldPos.x;
+ double currentY = oldPos.y;
+
+ // This implementation is bit slow since it checks some squares twice.
+ for(unsigned int i = 1; i < distance; i++) {
+ currentX += xInc;
+ currentY += yInc;
+ if(terrain[(int)currentX][(int)currentY] != EMPTY)
+ return false;
+ }
+ return true;
+}
+
void PhysicsObject::integrate(Vector force, uint16_t dt) {
// TODO
}
--- a/src/proto2/Physics.hh Thu Nov 20 15:01:17 2008 +0000
+++ b/src/proto2/Physics.hh Thu Nov 20 16:23:01 2008 +0000
@@ -34,6 +34,8 @@
void addObject (PhysicsObject *object);
void tick (void);
+ void generateTerrain (int seed);
+ bool collided (Vector oldPos, Vector newPos);
};
class PhysicsObject {
@@ -42,8 +44,8 @@
float mass;
Vector position;
Vector velocity;
- // Whether the object (worms mainly) is in the air or on the ground.
- // Affects to physics.
+ // Whether the object (worms mainly) is in the air
+ // or firmly on the ground. Affects to physics.
bool inAir;
PhysicsObject (PhysicsWorld &world, float mass, Vector position, Vector velocity);