reversed order of operations in interpolate_move
parent
1748db8412
commit
f8d69e3537
|
@ -177,28 +177,32 @@ object_t* interpolate_move(object_t* object, float target_x, float target_y, flo
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 1. check collision with every other object
|
* 1. move towards target
|
||||||
* 2. move towards target
|
* 2. check collision with every other object
|
||||||
*/
|
*/
|
||||||
while(object->sprite.x != target_x || object->sprite.y != target_y) {
|
while(object->sprite.x != target_x || object->sprite.y != target_y) {
|
||||||
for(int i = 0; i < WORLD_NUM_OBJECTS; ++i) {
|
|
||||||
object_t* other = g_objects + i;
|
|
||||||
if(!_can_collide(other)) continue;
|
|
||||||
if(object != other && _collision_check(other, object)) {
|
|
||||||
other->collider.evt_collision(other, object);
|
|
||||||
object->collider.evt_collision(object, other);
|
|
||||||
return other;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// move towards target, snap to target if distance is too low
|
// move towards target, snap to target if distance is too low
|
||||||
float distx = fabsf(object->sprite.x - target_x), disty = fabsf(object->sprite.y - target_y);
|
const float old_x = object->sprite.x, old_y = object->sprite.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; object->sprite.y += dy;
|
object->sprite.x += dx; object->sprite.y += dy;
|
||||||
} else {
|
} else {
|
||||||
object->sprite.x = target_x;
|
object->sprite.x = target_x;
|
||||||
object->sprite.y = target_y;
|
object->sprite.y = target_y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// loop over all objects and check collision if applicable
|
||||||
|
for(int i = 0; i < WORLD_NUM_OBJECTS; ++i) {
|
||||||
|
// get pointer to other object
|
||||||
|
object_t* other = g_objects + i;
|
||||||
|
if(!_can_collide(other)) continue;
|
||||||
|
// check collision, return if found
|
||||||
|
if(object != other && _collision_check(other, object)) {
|
||||||
|
other->collider.evt_collision(other, object);
|
||||||
|
object->collider.evt_collision(object, other);
|
||||||
|
return other;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// no collision, return nothing
|
// no collision, return nothing
|
||||||
|
|
Loading…
Reference in New Issue