diff --git a/src/corelib/world.c b/src/corelib/world.c index 8a063e9..57c64f1 100644 --- a/src/corelib/world.c +++ b/src/corelib/world.c @@ -189,13 +189,14 @@ void interpolate_move(object_t* object, float target_x, float target_y, float ma while(object->sprite.x != target_x || object->sprite.y != target_y) { // move towards target, snap to target if distance is too low const float old_x = object->sprite.x, old_y = object->sprite.y; + float new_x, new_y; const float distx = fabsf(object->sprite.x - target_x), disty = fabsf(object->sprite.y - target_y); if(distx < fabsf(dx) && disty < fabsf(dy)) { - object->sprite.x += dx; - object->sprite.y += dy; + new_x = object->sprite.x += dx; + new_y = object->sprite.y += dy; } else { - object->sprite.x = target_x; - object->sprite.y = target_y; + new_x = object->sprite.x = target_x; + new_y = object->sprite.y = target_y; } // loop over all objects and check collision if applicable @@ -206,9 +207,20 @@ void interpolate_move(object_t* object, float target_x, float target_y, float ma if(_can_collide(other) && object != other && _collision_check(other, object)) { object_broadcast_collision(other, object); object_broadcast_collision(object, other); - object->sprite.x = old_x; - object->sprite.y = old_y; - return; + if(slide) { + object->sprite.x = old_x; + if(_collision_check(other, object)) { + object->sprite.x = new_x; + } + object->sprite.y = old_y; + if(_collision_check(other, object)) { + object->sprite.y = new_y; + } + } else { + object->sprite.x = old_x; + object->sprite.y = old_y; + return; + } } } }