From 98d6f7b9650e1abe1d463e160349338187d6b179 Mon Sep 17 00:00:00 2001 From: Anonymus Raccoon Date: Fri, 1 May 2020 15:36:46 +0200 Subject: [PATCH] Adding the heal dialog of Mia --- CMakeLists.txt | 2 +- assets/sprites/npc/mia.png | Bin 0 -> 1651 bytes include/setup.h | 10 ++++++- lib/gamacon | 2 +- prefabs/game.gcprefab | 20 ++++++++++++++ src/components/dialog_holder.c | 35 +++++++++++++++-------- src/game_loader.c | 39 +++++++++++++++++--------- src/main_menu.c | 10 +++---- src/npc/mia.c | 49 +++++++++++++++++++++++++++++++++ 9 files changed, 135 insertions(+), 32 deletions(-) create mode 100644 assets/sprites/npc/mia.png create mode 100644 src/npc/mia.c diff --git a/CMakeLists.txt b/CMakeLists.txt index f859e55..1a35d22 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/attacks.c - src/player_utilities.c include/player_utilities.h src/systems/inventory.c include/systems/inventory.h src/systems/game_over.c include/systems/game_over.h) + src/player_utilities.c include/player_utilities.h src/systems/inventory.c include/systems/inventory.h src/systems/game_over.c include/systems/game_over.h src/npc/mia.c lib/gamacon/src/scene/scene_constructor.c) add_compile_options(-W -Wall -Wextra -Wshadow) diff --git a/assets/sprites/npc/mia.png b/assets/sprites/npc/mia.png new file mode 100644 index 0000000000000000000000000000000000000000..891eb1a780841fd196956f80a30385260797dbe5 GIT binary patch literal 1651 zcmV-(28{WMP)K1G)}Rj4v$x-BPNN*g*= zL1BVbcdu!U+kK*8JOJ{whUA8Jm{~ypJUkwDkWIM%p0fY?`ugMR|1cFWeuUix1qIjF z*Jva||JtyNBtj2aW`WHAplvq%0000UbW%=J0RR90|NsC0|NsC0|NsC0|NsC0|NsC0 z|NsC0|Nrzj8aDs{1&B#RK~#90?O9=Sqc{wW&B=xuFc3)EF8lxg=1C%Hi6wQ(?#_MK zTTQ0Zk@Vg(4uh4)>GVGi$MNd`=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ik& + @@ -210,6 +211,25 @@ + + + + + + + + + + + + + + + + + + + diff --git a/src/components/dialog_holder.c b/src/components/dialog_holder.c index 7a5847a..0c9e92b 100644 --- a/src/components/dialog_holder.c +++ b/src/components/dialog_holder.c @@ -55,29 +55,42 @@ static void ctr(void *component, va_list args) setup_tile_interactions(cmp, scene, (gc_vector2i){x, y}, texture); } +bool dialog_parse_inputs(struct dialog_line *txt, gc_scene *scene, node *n) +{ + char *click; + int i = 0; + + txt->inputs = malloc(sizeof(struct dialog_input) * txt->input_count); + if (!txt->inputs) + return (false); + for (n = n->child; n; n = n->next) { + txt->inputs[i].text = xml_getproperty(n, "text"); + click = xml_gettempprop(n, "click"); + txt->inputs[i].callback = scene->get_data(scene, "input", click); + if (!txt->inputs[i++].callback && click) + my_printf("Couldn't find an input with the name: %s.\n", click); + } + return (false); +} + struct dialog_line *dialog_parse_text(gc_scene *scene, node *n) { struct dialog_line *txt = malloc(sizeof(struct dialog_line)); - char *click; - int i = 0; + char *callback; if (!txt) return (NULL); txt->name = my_strdup(n->name); txt->text = xml_getproperty(n, "line"); txt->input_count = xml_getchildcount_filtered(n, "input"); - txt->callback = NULL; + callback = xml_gettempprop(n, "callback"); + txt->callback = scene->get_data(scene, "dialog_callback", callback); + if (callback && !txt->callback) + my_printf("Couldn't find an callback with the name: %s.\n", callback); txt->inputs = NULL; if (txt->input_count == 0) return (txt); - txt->inputs = malloc(sizeof(struct dialog_input) * txt->input_count); - for (n = n->child; n; n = n->next) { - txt->inputs[i].text = xml_getproperty(n, "text"); - click = xml_gettempprop(n, "click"); - txt->inputs[i++].callback = scene->get_data(scene, "input", click); - if (!txt->inputs) - my_printf("Couldn't find a callback with the name: %s.\n", click); - } + dialog_parse_inputs(txt, scene, n); return (txt); } diff --git a/src/game_loader.c b/src/game_loader.c index 5eb4b50..92b1722 100644 --- a/src/game_loader.c +++ b/src/game_loader.c @@ -47,9 +47,16 @@ const struct callback callbacks[] = { {"action2", &dialog_input2}, {"action3", &dialog_input3}, {"hide_game_over", &hide_game_over}, + {"mia_heal", &mia_heal}, {NULL, NULL} }; +const struct gc_data game_data[] = { + {"input", "mia_heal", &mia_heal, NULL}, + {"dialog_callback", "mia_setup", &mia_setup, NULL}, + {NULL, NULL, NULL, NULL} +}; + const struct callback map_editor_callbacks[] = { {"map_manage_click", &map_onclick}, {"tile_select", &tile_select}, @@ -64,30 +71,36 @@ const struct callback map_editor_callbacks[] = { }; const struct gc_data attacks[] = { - {"attack", "Uppercut", &uppercut, NULL}, - {"attack", "Fireball", &fireball, NULL}, - {"attack", "Water jet", &water_jet, NULL}, - {"attack", "Shield", &shield, NULL}, + {"attack", "Uppercut", &uppercut, NULL}, + {"attack", "Fireball", &fireball, NULL}, + {"attack", "Water jet", &water_jet, NULL}, + {"attack", "Shield", &shield, NULL}, {"attack", "Aerial attack", &enemy_attack, NULL}, - {NULL, NULL, NULL, NULL} + {NULL, NULL, NULL, NULL} }; -void load_attacks(gc_scene *scene) +void load_data(gc_scene *scene, const gc_data *datas) { gc_data *data; - gc_list *li = scene->get_entity_by_cmp(scene, "attack_component"); - struct attack_component *att; - for (int i = 0; attacks[i].name; i++) { + for (int i = 0; datas[i].name; i++) { data = malloc(sizeof(*data)); if (!data) return; - data->name = my_strdup(attacks[i].name); - data->type = my_strdup(attacks[i].type); - data->custom = attacks[i].custom; - data->destroy = attacks[i].destroy; + data->name = my_strdup(datas[i].name); + data->type = my_strdup(datas[i].type); + data->custom = datas[i].custom; + data->destroy = datas[i].destroy; LISTADD(scene->data, data); } +} + +void load_attacks(gc_scene *scene) +{ + gc_list *li = scene->get_entity_by_cmp(scene, "attack_component"); + struct attack_component *att; + + load_data(scene, attacks); for (; li; li = li->next) { att = GETCMP(li->data, attack_component); for (int i = 0; att->attacks && att->attacks[i].name; i++) diff --git a/src/main_menu.c b/src/main_menu.c index 8ba9e8d..8b99ce7 100644 --- a/src/main_menu.c +++ b/src/main_menu.c @@ -19,18 +19,18 @@ enum gc_mousekeys __) prefab_load(engine, "prefabs/loading.gcprefab"); engine->game_loop(engine, 0); - scene = scene_create(engine, "prefabs/game.gcprefab"); + scene = scene_new(engine); + load_data(scene, game_data); + scene = scene_parse_xml(scene, engine, "prefabs/game.gcprefab"); if (!scene) { engine->should_close = true; my_printf("The game scene couldn't be loaded.\n"); return (true); } engine->change_scene(engine, scene); - if (prefab_load(engine, "prefabs/player.gcprefab") < 0) { + if (prefab_load(engine, "prefabs/player.gcprefab") < 0) my_printf("Could not load the player.\n"); - return (true); - } - if (prefab_load(engine, "prefabs/map_entities.gcprefab") < 0) + else if (prefab_load(engine, "prefabs/map_entities.gcprefab") < 0) return (true); if (engine->get_callback(engine, "map_manage_click")) if (prefab_load(engine, "prefabs/editor_ui.gcprefab") < 0) diff --git a/src/npc/mia.c b/src/npc/mia.c new file mode 100644 index 0000000..e570472 --- /dev/null +++ b/src/npc/mia.c @@ -0,0 +1,49 @@ +/* +** EPITECH PROJECT, 2020 +** my_rpg +** File description: +** mia.c +*/ + +#include +#include +#include "engine.h" + +struct dialog_holder *dialog_get_current(gc_engine *engine) +{ + struct dialog_manager *manager = GETSYS(engine, dialog_manager); + + return (manager->current_dialog); +} + +void mia_setup(gc_engine *engine) +{ + struct dialog_holder *holder = dialog_get_current(engine); + + holder->text[2] = NULL; +} + +bool mia_heal(gc_engine *engine, gc_entity *entity, \ +gc_vector2 pos, enum gc_mousekeys key) +{ + gc_entity *player = engine->scene->get_entity(engine->scene, 50); + struct health_component *hea; + struct dialog_holder *dialog = dialog_get_current(engine); + + if (!player || !dialog) + return (false); + hea = GETCMP(player, health_component); + if (!hea) + return (false); + if (hea->health != hea->health_max) { + hea->health = hea->health_max; + dialog_add_line(dialog, "Mia", "Of course, let me\ +take care\nof it.", NULL); + } else { + dialog_add_line(dialog, "Mia", "You don't seem to have\n\ +any wounds.", NULL); + dialog_add_line(dialog, "Mia", "Are you sure you are\n\ +here for that?", NULL); + } + return (true); +} \ No newline at end of file