summaryrefslogtreecommitdiff
path: root/src/eetg.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/eetg.c')
-rw-r--r--src/eetg.c28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/eetg.c b/src/eetg.c
index fe92ed3..b5f372b 100644
--- a/src/eetg.c
+++ b/src/eetg.c
@@ -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;
}