diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2022-10-17 20:15:19 -0700 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2022-10-17 20:15:19 -0700 |
commit | 6d0078cb9d2b96ca0f26196be295307352c3d10f (patch) | |
tree | c5eafa7732367e48ba261a1a735bc51fcf72b915 /src | |
parent | 60d28d1309cf37942363d10f7d135b02a4c82078 (diff) |
game: propagate virus for newly infected babies
The existing code wouldn't handle when newly infected babies
overlapped with other uninfected babies, creating potential
outcomes where a stationary virus is left visibly touching an
uninfected baby.
This commit puts new infections on a list to be processed like
viruses after performing the per-virus search creating the new
infections. Now when a newly infected baby is touching other
babies, those other babies become immediately infected as well.
Diffstat (limited to 'src')
-rw-r--r-- | src/game.c | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -103,6 +103,7 @@ typedef struct baby_t { typedef struct virus_t { entity_any_t entity; + entity_t *new_infections_next; } virus_t; typedef struct adult_t { @@ -146,6 +147,7 @@ typedef struct game_t { adult_t *adult; tv_t *tv; + entity_t *new_infections; virus_t *viruses[GAME_NUM_VIRUSES]; m4f_t score_digits_x[10]; } game_t; @@ -323,6 +325,9 @@ 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; + /* stick entity on a new_infections list for potential propagation */ + entity->virus.new_infections_next = search->game->new_infections; + search->game->new_infections = entity; (void) baby_new(search->game, search->game->babies_node); @@ -399,6 +404,16 @@ static void update_entities(play_t *play, game_t *game) /* search ix2 for collisions */ if (ix2_search_by_aabb(game->ix2, NULL, NULL, &virus->entity.aabb_x, virus_search, &search)) reset_virus(virus); + + /* propagate any new infections */ + while (game->new_infections) { + entity_t *infection = game->new_infections; + + game->new_infections = infection->virus.new_infections_next; + + search.virus = &infection->virus; + (void) ix2_search_by_aabb(game->ix2, NULL, NULL, &infection->virus.entity.aabb_x, virus_search, &search); + } } } } |