diff options
author | Richard Braun <rbraun@sceen.net> | 2025-07-07 23:20:36 +0200 |
---|---|---|
committer | Richard Braun <rbraun@sceen.net> | 2025-07-07 23:33:24 +0200 |
commit | bad173c52be8ebfe75a4a46465b2d89669432246 (patch) | |
tree | 1757009d45d2fbbf97d5d63fc00809d2775aca1e /src/eetg.c | |
parent | ec598949b407d86d0d35548566c70c18fbce76aa (diff) |
Update embedded invadersdev/et
Diffstat (limited to 'src/eetg.c')
-rw-r--r-- | src/eetg.c | 28 |
1 files changed, 19 insertions, 9 deletions
@@ -130,6 +130,12 @@ eetg_object_check_collision(struct eetg_object *object1, if (hit) { return true; } + + if ((eetg_object_get_world(object1) == NULL) + || (eetg_object_get_world(object2) == NULL)) + { + return false; + } } } @@ -346,6 +352,8 @@ eetg_world_set_collision_fn(struct eetg_world *world, static bool eetg_world_scan_collisions(struct eetg_world *world, struct eetg_object *object) { + bool hit = false; + assert(world); assert(!world->handling_collision); @@ -363,26 +371,28 @@ eetg_world_scan_collisions(struct eetg_world *world, struct eetg_object *object) tmp = eetg_layer_get_objects(layer); while (tmp) { - if (tmp != object) { - bool hit; + struct eetg_object *next; + + next = tmp->next; + if (tmp != object) { hit = eetg_object_check_collision(object, tmp, world->handle_collision_fn, world->handle_collision_fn_arg); - if (hit) { - world->handling_collision = false; - return true; + if (hit || (eetg_object_get_world(object) == NULL)) { + goto out; } } - tmp = tmp->next; + tmp = next; } } +out: world->handling_collision = false; - return false; + return hit; } bool @@ -402,7 +412,7 @@ eetg_world_add(struct eetg_world *world, struct eetg_object *object, eetg_object_attach(object, world, x, y, layer_id); hit = eetg_world_scan_collisions(world, object); - if (hit) { + if (hit && (eetg_object_get_world(object) != NULL)) { eetg_world_remove(world, object); } @@ -853,7 +863,7 @@ eetg_object_move(struct eetg_object *object, int x, int y) if (object->world) { hit = eetg_world_scan_collisions(object->world, object); - if (hit) { + if (hit && object->world) { object->x = prev_x; object->y = prev_y; } |