+ // calculate destination positions of the objects
+ for(MovingObjects::iterator i = moving_objects.begin();
+ i != moving_objects.end(); ++i) {
+ MovingObject* moving_object = *i;
+
+ moving_object->dest = moving_object->get_bbox();
+ moving_object->dest.move(moving_object->get_movement());
+ }
+
+ // part1: COLGROUP_MOVING vs COLGROUP_STATIC and tilemap
+ // we do this up to 4 times and have to sort all results for the smallest
+ // one before we can continue here
+ for(MovingObjects::iterator i = moving_objects.begin();
+ i != moving_objects.end(); ++i) {
+ MovingObject* moving_object = *i;
+ if((moving_object->get_group() != COLGROUP_MOVING
+ && moving_object->get_group() != COLGROUP_MOVING_ONLY_STATIC)
+ || !moving_object->is_valid())
+ continue;
+
+ Vector movement = moving_object->get_movement();
+
+ // test if x or y movement is dominant
+ if(fabsf(moving_object->get_movement().x) < fabsf(moving_object->get_movement().y)) {
+
+ // test in x direction first, then y direction
+ moving_object->dest.move(Vector(0, -movement.y));
+ for(int i = 0; i < 2; ++i) {
+ bool res = collision_static(moving_object, Vector(movement.x, 0));
+ if(res)
+ break;
+ }
+ moving_object->dest.move(Vector(0, movement.y));
+ for(int i = 0; i < 2; ++i) {
+ bool res = collision_static(moving_object, Vector(0, movement.y));
+ if(res)
+ break;
+ }
+
+ } else {
+
+ // test in y direction first, then x direction
+ moving_object->dest.move(Vector(-movement.x, 0));
+ for(int i = 0; i < 2; ++i) {
+ bool res = collision_static(moving_object, Vector(0, movement.y));
+ if(res)
+ break;
+ }
+ moving_object->dest.move(Vector(movement.x, 0));
+ for(int i = 0; i < 2; ++i) {
+ bool res = collision_static(moving_object, Vector(movement.x, 0));
+ if(res)
+ break;
+ }
+ }
+ }
+
+ // part2: COLGROUP_MOVING vs tile attributes
+ for(MovingObjects::iterator i = moving_objects.begin();
+ i != moving_objects.end(); ++i) {
+ MovingObject* moving_object = *i;
+ if((moving_object->get_group() != COLGROUP_MOVING
+ && moving_object->get_group() != COLGROUP_MOVING_ONLY_STATIC)
+ || !moving_object->is_valid())