From 60d28d1309cf37942363d10f7d135b02a4c82078 Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Mon, 17 Oct 2022 20:13:37 -0700 Subject: game: handle infecting multiple babies at once It's possible for babies to overlap and a virus to encounter them simultaneously. The existing code halted the search on the first hit. This commit changes things to continue the search and infect all hits before resetting the infecting virus. --- src/game.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/game.c b/src/game.c index f304094..0d3f57e 100644 --- a/src/game.c +++ b/src/game.c @@ -323,11 +323,10 @@ static ix2_search_status_t virus_search(void *cb_context, ix2_object_t *ix2_obje sfx_play(sfx.baby_infected); entity->any.type = ENTITY_TYPE_VIRUS; - (void) baby_new(search->game, search->game->babies_node); - reset_virus(search->virus); + (void) baby_new(search->game, search->game->babies_node); - return IX2_SEARCH_STOP_HIT; + return IX2_SEARCH_MORE_HIT; case ENTITY_TYPE_ADULT: /* convert adult into inanimate virus (off the viruses array) */ @@ -398,7 +397,8 @@ static void update_entities(play_t *play, game_t *game) search.virus = virus; /* search ix2 for collisions */ - ix2_search_by_aabb(game->ix2, NULL, NULL, &virus->entity.aabb_x, virus_search, &search); + if (ix2_search_by_aabb(game->ix2, NULL, NULL, &virus->entity.aabb_x, virus_search, &search)) + reset_virus(virus); } } } -- cgit v1.2.3