From 008b9c5fbeeef43dae8bd8464041c3636017b5f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Mon, 27 Apr 2020 17:41:07 +0200 Subject: [PATCH] now when the player leaves the combat scene his health component should be updated correctly nad removing xp display form the combat screen --- CMakeLists.txt | 2 +- include/player_utilities.h | 15 +++++++++++++++ prefabs/combat.gcprefab | 3 --- src/player_utilities.c | 23 +++++++++++++++++++++++ src/systems/combat_manager.c | 6 +++++- src/systems/combat_methods.c | 15 +-------------- 6 files changed, 45 insertions(+), 19 deletions(-) create mode 100644 include/player_utilities.h create mode 100644 src/player_utilities.c diff --git a/CMakeLists.txt b/CMakeLists.txt index a10dd7d..b76e283 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -298,7 +298,7 @@ add_executable(my_rpg include/components/attack_component.h src/systems/combat_methods.c src/combat/fireball.c -) + src/player_utilities.c include/player_utilities.h) add_compile_options(-W -Wall -Wextra -Wshadow) diff --git a/include/player_utilities.h b/include/player_utilities.h new file mode 100644 index 0000000..fe13434 --- /dev/null +++ b/include/player_utilities.h @@ -0,0 +1,15 @@ +/* +** EPITECH PROJECT, 2019 +** MUL_my_runner_2019 +** File description: +** game_loader +*/ + +#ifndef MY_RPG_PLAYER_UTILITIES_H +#define MY_RPG_PLAYER_UTILITIES_H + +#include "entity.h" + +void set_combat_player(gc_entity *main_player, gc_entity *combat_player); + +#endif //MY_RPG_PLAYER_UTILITIES_H diff --git a/prefabs/combat.gcprefab b/prefabs/combat.gcprefab index 5da72a4..d3f54ff 100644 --- a/prefabs/combat.gcprefab +++ b/prefabs/combat.gcprefab @@ -52,8 +52,5 @@ - - - \ No newline at end of file diff --git a/src/player_utilities.c b/src/player_utilities.c new file mode 100644 index 0000000..aae16b3 --- /dev/null +++ b/src/player_utilities.c @@ -0,0 +1,23 @@ +/* +** EPITECH PROJECT, 2019 +** MUL_my_runner_2019 +** File description: +** game_loader +*/ + +#include "components//health_component.h" +#include "entity.h" + +void set_combat_player(gc_entity *main_player, gc_entity *combat_player) +{ + struct health_component *h_cmp_main = \ +GETCMP(main_player, health_component); + struct health_component *h_cmp_combat = \ +GETCMP(combat_player, health_component); + + if (!h_cmp_main || !h_cmp_combat) + return; + h_cmp_combat->health_max = h_cmp_main->health_max; + h_cmp_combat->health = h_cmp_main->health; + h_cmp_combat->dead = h_cmp_main->dead; +} \ No newline at end of file diff --git a/src/systems/combat_manager.c b/src/systems/combat_manager.c index 1ac3ec4..3925b24 100644 --- a/src/systems/combat_manager.c +++ b/src/systems/combat_manager.c @@ -13,6 +13,7 @@ #include "my.h" #include "components/dialog_holder.h" #include "enemy.h" +#include "player_utilities.h" void entity_moved(gc_engine *engine, va_list args) { @@ -31,9 +32,12 @@ void entity_moved(gc_engine *engine, va_list args) void dialog_ended(gc_engine *engine, va_list args) { struct combat_manager *this = GETSYS(engine, combat_manager); + gc_entity *player = engine->scene->get_entity(engine->scene, 50); + gc_entity *player_combat = this->game_scene->get_entity(this->game_scene, 50); - if (!this->current_enemy) + if (!this->current_enemy || !player || ! player_combat) return; + set_combat_player(player_combat, player); engine->trigger_event(engine, "combat_ended", this->current_enemy); this->current_enemy = NULL; engine->change_scene(engine, this->game_scene); diff --git a/src/systems/combat_methods.c b/src/systems/combat_methods.c index 85da902..b29003f 100644 --- a/src/systems/combat_methods.c +++ b/src/systems/combat_methods.c @@ -17,20 +17,7 @@ #include "components/health_component.h" #include "enemy.h" #include "setup.h" - -void set_combat_player(gc_entity *main_player, gc_entity *combat_player) -{ - struct health_component *h_cmp_main = \ -GETCMP(main_player, health_component); - struct health_component *h_cmp_combat = \ -GETCMP(combat_player, health_component); - - if (!h_cmp_main || !h_cmp_combat) - return; - h_cmp_combat->health_max = h_cmp_main->health_max; - h_cmp_combat->health = h_cmp_main->health; - h_cmp_combat->dead = h_cmp_main->dead; -} +#include "player_utilities.h" void combat_start(gc_engine *engine, char *enemy_name) {