From 5049efb952c3751ed00e7cc67eec76d6dc6ef585 Mon Sep 17 00:00:00 2001 From: En Yi Date: Mon, 3 Jul 2023 20:57:17 +0800 Subject: [PATCH] Allow hitboxes to hit multiple hurtboxes --- scenes/game_systems.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/scenes/game_systems.c b/scenes/game_systems.c index 23cc61a..17a52e6 100644 --- a/scenes/game_systems.c +++ b/scenes/game_systems.c @@ -1652,9 +1652,9 @@ void hitbox_update_system(Scene_t* scene) unsigned int ent_idx; CHitBoxes_t* p_hitbox; - sc_map_foreach(&scene->ent_manager.component_map[CHITBOXES_T], ent_idx, p_hitbox) { + bool hit = false; Entity_t *p_ent = get_entity(&scene->ent_manager, ent_idx); if (!p_ent->m_alive) continue; CTransform_t* p_ctransform = get_component(p_ent, CTRANSFORM_COMP_T); @@ -1692,17 +1692,15 @@ void hitbox_update_system(Scene_t* scene) ) ) { + hit = true; if (p_hitbox->atk > tilemap.tiles[tile_idx].def) { change_a_tile(&tilemap, tile_idx, EMPTY_TILE); - } - if (p_hitbox->one_hit) - { - remove_entity_from_tilemap(&scene->ent_manager, &tilemap, p_ent); - goto hitbox_done; + continue; } } } + sc_map_foreach(&tilemap.tiles[tile_idx].entities_set, other_ent_idx, p_other_ent) { if (other_ent_idx == ent_idx) continue; @@ -1724,6 +1722,7 @@ void hitbox_update_system(Scene_t* scene) ) ) { + hit = true; if (p_hitbox->atk > p_other_hurtbox->def) { p_other_hurtbox->damage_src = ent_idx; @@ -1750,17 +1749,15 @@ void hitbox_update_system(Scene_t* scene) remove_entity_from_tilemap(&scene->ent_manager, &tilemap, p_other_ent); } - if (p_hitbox->one_hit) - { - remove_entity_from_tilemap(&scene->ent_manager, &tilemap, p_ent); - goto hitbox_done; - } } } } } } -hitbox_done: continue; + if (p_hitbox->one_hit && hit) + { + remove_entity_from_tilemap(&scene->ent_manager, &tilemap, p_ent); + } } }