- // up to 4 tries
- for(int t = 0; t < 4; ++t) {
- CollisionHit hit;
- hit.time = -1;
- MovingObject* collided_with = NULL;
-
- // collision with tilemap
- collision_tilemap(moving_object, hit);
-
- // collision with other objects
- Rect dest1 = moving_object->get_bbox();
- dest1.move(moving_object->get_movement());
- CollisionHit temphit;
-
- for(MovingObjects::iterator i2 = moving_objects.begin();
- i2 != moving_objects.end(); ++i2) {
- MovingObject* moving_object_2 = *i2;
- if(moving_object_2->get_group() != COLGROUP_STATIC
- || !moving_object_2->is_valid())
- continue;
-
- Rect dest2 = moving_object_2->get_bbox();
- dest2.move(moving_object_2->get_movement());
- Vector movement
- = moving_object->get_movement() - moving_object_2->get_movement();
- if(Collision::rectangle_rectangle(temphit, dest1, movement, dest2)
- && temphit.time > hit.time) {
- hit = temphit;
- collided_with = moving_object_2;
+ Constraints constraints;
+ Vector movement = moving_object->get_movement();
+ Rect& dest = moving_object->dest;
+ float owidth = moving_object->get_bbox().get_width();
+ float oheight = moving_object->get_bbox().get_height();
+
+ for(int i = 0; i < 2; ++i) {
+ collision_static(&constraints, Vector(0, movement.y), dest, *moving_object);
+ if(!constraints.has_constraints())
+ break;
+
+ // apply calculated horizontal constraints
+ if(constraints.bottom < INFINITY) {
+ float height = constraints.bottom - constraints.top;
+ if(height < oheight) {
+ // we're crushed, but ignore this for now, we'll get this again
+ // later if we're really crushed or things will solve itself when
+ // looking at the vertical constraints