added broadcast collision

pull/6/head
Sara 2023-06-18 13:22:35 +02:00
parent e32eb731c2
commit 4bf759d224
2 changed files with 11 additions and 4 deletions

View File

@ -144,6 +144,12 @@ short _can_collide(const object_t* object) {
return object->active && object->enabled; 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() { void update_collision() {
for(int outer = 0; outer < WORLD_NUM_OBJECTS; ++outer) { for(int outer = 0; outer < WORLD_NUM_OBJECTS; ++outer) {
object_t* oobject = g_objects + outer; object_t* oobject = g_objects + outer;
@ -153,8 +159,8 @@ void update_collision() {
if(!_can_collide(oobject)) continue; if(!_can_collide(oobject)) continue;
if(outer != inner && _collision_check(iobject, oobject)) { if(outer != inner && _collision_check(iobject, oobject)) {
oobject->collider.evt_collision(oobject, iobject); object_broadcast_collision(oobject, iobject);
iobject->collider.evt_collision(iobject, oobject); 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; object_t* other = g_objects + i;
// check collision, return if found // check collision, return if found
if(_can_collide(other) && object != other && _collision_check(other, object)) { if(_can_collide(other) && object != other && _collision_check(other, object)) {
other->collider.evt_collision(other, object); object_broadcast_collision(other, object);
object->collider.evt_collision(object, other); object_broadcast_collision(object, other);
return other; return other;
} }
} }

View File

@ -55,6 +55,7 @@ object_t* instantiate_object(const object_t* original);
collider_t collider_default(); collider_t collider_default();
void object_draw_sprite(object_t* object); void object_draw_sprite(object_t* object);
void object_broadcast_evt_collision(object_t* this, object_t* other);
void update_objects(); void update_objects();
void draw_objects(); void draw_objects();