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 0000000..891eb1a Binary files /dev/null and b/assets/sprites/npc/mia.png differ diff --git a/include/setup.h b/include/setup.h index bef2f24..928a468 100644 --- a/include/setup.h +++ b/include/setup.h @@ -61,4 +61,12 @@ void water_jet(gc_engine *engine, gc_entity *from, gc_entity *enemy); void shield(gc_engine *engine, gc_entity *from, gc_entity *enemy); void enemy_attack(gc_engine *engine, gc_entity *from, gc_entity *enemy); -void load_attacks(gc_scene *scene); \ No newline at end of file +void load_attacks(gc_scene *scene); + + +bool mia_heal(gc_engine *engine, gc_entity *entity, \ +gc_vector2 pos, enum gc_mousekeys key); +void mia_setup(gc_engine *engine); + + void load_data(gc_scene *scene, const gc_data *datas); +extern const struct gc_data game_data[]; \ No newline at end of file diff --git a/lib/gamacon b/lib/gamacon index c9e7795..1715d0e 160000 --- a/lib/gamacon +++ b/lib/gamacon @@ -1 +1 @@ -Subproject commit c9e77951c86e0bf921d22eae39f1e6f5a2a86164 +Subproject commit 1715d0ecd313c622d77ca2cc52f2b87cc716f1d0 diff --git a/prefabs/game.gcprefab b/prefabs/game.gcprefab index e2a4cc7..51dd0b7 100644 --- a/prefabs/game.gcprefab +++ b/prefabs/game.gcprefab @@ -144,6 +144,7 @@ + @@ -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