diff --git a/CMakeLists.txt b/CMakeLists.txt index 943eae8..9470331 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -211,7 +211,7 @@ add_executable(My3D lib/my/my/my_str_replace.c lib/gamacon/src/sfml_renderer/sfml_init.c lib/gamacon/src/sfml_renderer/sfml_events.c - lib/xmlparser/src/otherget.c src/options.c lib/gamacon/src/components/input_component.c lib/gamacon/include/components/input_component.h) + lib/xmlparser/src/otherget.c src/options.c lib/gamacon/src/components/input_component.c lib/gamacon/include/components/input_component.h src/systems/teams_system.c include/systems/teams_system.h include/components/teams_component.h src/components/teams_component.c) add_compile_options(-W -Wall -Wextra -Wshadow) diff --git a/include/components/teams_component.h b/include/components/teams_component.h new file mode 100644 index 0000000..23b749f --- /dev/null +++ b/include/components/teams_component.h @@ -0,0 +1,21 @@ +// +// Created by anonymus-raccoon on 3/3/20. +// + +#ifndef _TEAMS_COMPONENT_C_ +#define _TEAMS_COMPONENT_H_ + +#include "component.h" + +struct teams_component +{ + gc_component base; + float next_teams; + float delay; + char **prefabs; + int prefab_count; +}; + +const struct teams_component teams_component; + +#endif //_TEAMS_COMPONENT_C_ diff --git a/include/systems/teams_system.h b/include/systems/teams_system.h new file mode 100644 index 0000000..ee190c3 --- /dev/null +++ b/include/systems/teams_system.h @@ -0,0 +1,12 @@ +// +// Created by anonymus-raccoon on 3/3/20. +// + +#ifndef _TEAMS_SYSTEM_H_ +#define _TEAMS_SYSTEM_H_ + +#include "system.h" + +const gc_system teams_system; + +#endif //_TEAMS_SYSTEM_H_ diff --git a/lib/xmlparser b/lib/xmlparser index 959963b..5028a21 160000 --- a/lib/xmlparser +++ b/lib/xmlparser @@ -1 +1 @@ -Subproject commit 959963b7a830ce198f208b8cc43d24a5fa26ad13 +Subproject commit 5028a210a2b30afbea128f47e3030b4da84f0271 diff --git a/prefabs/game.gcprefab b/prefabs/game.gcprefab index fb7b8b4..debbca9 100644 --- a/prefabs/game.gcprefab +++ b/prefabs/game.gcprefab @@ -22,16 +22,16 @@ + + + + + + + - - - - - - - diff --git a/prefabs/teams/forgot_register.gcprefab b/prefabs/teams/forgot_register.gcprefab new file mode 100644 index 0000000..64fbf31 --- /dev/null +++ b/prefabs/teams/forgot_register.gcprefab @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/src/components/teams_component.c b/src/components/teams_component.c new file mode 100644 index 0000000..04555d2 --- /dev/null +++ b/src/components/teams_component.c @@ -0,0 +1,61 @@ +/* +** EPITECH PROJECT, 2020 +** Twac +** File description: +** camera_follow +*/ + +#include "xml.h" +#include "component.h" +#include "components/teams_component.h" +#include "utility.h" +#include + +static void ctr(void *component, va_list args) +{ + struct teams_component *cmp = (struct teams_component *)component; + + cmp->delay = va_arg(args, double); + cmp->next_teams = cmp->delay; +} + +static void fdctr(gc_entity *entity, gc_scene *scene, void *component, node *n) +{ + struct teams_component *cmp = (struct teams_component *)component; + + cmp->delay = xml_getfloatprop(n, "delay"); + cmp->next_teams = cmp->delay; + cmp->prefab_count = xml_getchildcount_filtered(n, "prefab"); + cmp->prefabs = malloc(sizeof(char *) * cmp->prefab_count); + n = n->child; + for (int i = 0; i < cmp->prefab_count; i++) { + cmp->prefabs[i] = xml_getproperty(n, "src"); + n = n->next; + } +} + +static void dtr(void *component) +{ + (void)component; +} + +static char *serialize(void *component) +{ + (void)component; + return (NULL); +} + +const struct teams_component teams_component = { + base: { + name: "teams_component", + size: sizeof(struct teams_component), + dependencies: (char *[]) { + NULL + }, + ctr: &ctr, + fdctr: &fdctr, + dtr: &dtr, + serialize: &serialize, + destroy: &component_destroy + } +}; \ No newline at end of file diff --git a/src/game_loader.c b/src/game_loader.c index 4203767..4ebb9bb 100644 --- a/src/game_loader.c +++ b/src/game_loader.c @@ -7,10 +7,14 @@ #include "engine.h" #include "setup.h" +#include "components/teams_component.h" +#include "systems/teams_system.h" #include int register_customcmps(gc_engine *engine) { + engine->add_component(engine, &teams_component); + engine->add_system(engine, &teams_system); engine->finish_physics(engine); engine->add_callback(engine, "start_button", &start_button); engine->add_callback(engine, "options", &options); diff --git a/src/systems/teams_system.c b/src/systems/teams_system.c new file mode 100644 index 0000000..7a19344 --- /dev/null +++ b/src/systems/teams_system.c @@ -0,0 +1,45 @@ +/* +** EPITECH PROJECT, 2019 +** MUL_my_runner_2019 +** File description: +** teams_system +*/ + +#include "entity.h" +#include "system.h" +#include "sprite.h" +#include "vector2.h" +#include "prefab.h" +#include "components/teams_component.h" +#include "systems/teams_system.h" +#include +#include +#include + +static void update_entity(gc_engine *engine, void *system, gc_entity *entity, \ +float dtime) +{ + struct teams_component *team = GETCMP(entity, teams_component); + + team->next_teams -= dtime; + if (team->next_teams < 0 && team->prefab_count) { + team->next_teams = team->delay; + prefab_load(engine, team->prefabs[random() % team->prefab_count]); + } +} + +static void destroy(void *system) +{ + (void)system; +} + +const gc_system teams_system = { + name: "teams_system", + component_name: "teams_component", + size: sizeof(gc_system), + ctr: NULL, + dtr: NULL, + check_dependencies: &system_check_dependencies, + update_entity: &update_entity, + destroy: &destroy +}; \ No newline at end of file