implemented slide

pull/8/head
Sara 2023-06-18 14:18:37 +02:00
parent 81e242532b
commit 0a8aac2325
1 changed files with 19 additions and 7 deletions

View File

@ -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;
}
}
}
}