implemented slide
parent
81e242532b
commit
0a8aac2325
|
@ -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) {
|
while(object->sprite.x != target_x || object->sprite.y != target_y) {
|
||||||
// move towards target, snap to target if distance is too low
|
// move towards target, snap to target if distance is too low
|
||||||
const float old_x = object->sprite.x, old_y = object->sprite.y;
|
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);
|
const float distx = fabsf(object->sprite.x - target_x), disty = fabsf(object->sprite.y - target_y);
|
||||||
if(distx < fabsf(dx) && disty < fabsf(dy)) {
|
if(distx < fabsf(dx) && disty < fabsf(dy)) {
|
||||||
object->sprite.x += dx;
|
new_x = object->sprite.x += dx;
|
||||||
object->sprite.y += dy;
|
new_y = object->sprite.y += dy;
|
||||||
} else {
|
} else {
|
||||||
object->sprite.x = target_x;
|
new_x = object->sprite.x = target_x;
|
||||||
object->sprite.y = target_y;
|
new_y = object->sprite.y = target_y;
|
||||||
}
|
}
|
||||||
|
|
||||||
// loop over all objects and check collision if applicable
|
// 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)) {
|
if(_can_collide(other) && object != other && _collision_check(other, object)) {
|
||||||
object_broadcast_collision(other, object);
|
object_broadcast_collision(other, object);
|
||||||
object_broadcast_collision(object, other);
|
object_broadcast_collision(object, other);
|
||||||
object->sprite.x = old_x;
|
if(slide) {
|
||||||
object->sprite.y = old_y;
|
object->sprite.x = old_x;
|
||||||
return;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue