diff --git a/src/corelib/world.c b/src/corelib/world.c index 11a8d82..957655e 100644 --- a/src/corelib/world.c +++ b/src/corelib/world.c @@ -144,6 +144,12 @@ short _can_collide(const object_t* object) { return object->active && object->enabled; } +void object_broadcast_collision(object_t* this, object_t* other) { + if(this->collider.evt_collision != NULL) { + this->collider.evt_collision(this, other); + } +} + void update_collision() { for(int outer = 0; outer < WORLD_NUM_OBJECTS; ++outer) { object_t* oobject = g_objects + outer; @@ -153,8 +159,8 @@ void update_collision() { if(!_can_collide(oobject)) continue; if(outer != inner && _collision_check(iobject, oobject)) { - oobject->collider.evt_collision(oobject, iobject); - iobject->collider.evt_collision(iobject, oobject); + object_broadcast_collision(oobject, iobject); + object_broadcast_collision(iobject, oobject); } } } @@ -197,8 +203,8 @@ object_t* interpolate_move(object_t* object, float target_x, float target_y, flo object_t* other = g_objects + i; // check collision, return if found if(_can_collide(other) && object != other && _collision_check(other, object)) { - other->collider.evt_collision(other, object); - object->collider.evt_collision(object, other); + object_broadcast_collision(other, object); + object_broadcast_collision(object, other); return other; } } diff --git a/src/corelib/world.h b/src/corelib/world.h index d82287a..2c57f31 100644 --- a/src/corelib/world.h +++ b/src/corelib/world.h @@ -55,6 +55,7 @@ object_t* instantiate_object(const object_t* original); collider_t collider_default(); void object_draw_sprite(object_t* object); +void object_broadcast_evt_collision(object_t* this, object_t* other); void update_objects(); void draw_objects();