diff --git a/Makefile b/Makefile index 80d0060..2867930 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,7 @@ SRC = main.c \ src/components/jump_component.c \ src/components/live_component.c \ src/components/kill_component.c \ + src/components/win_component.c \ src/systems/gravity_system.c \ src/systems/walk_system.c \ src/systems/jump_system.c diff --git a/include/components/win_component.h b/include/components/win_component.h new file mode 100644 index 0000000..2060f0b --- /dev/null +++ b/include/components/win_component.h @@ -0,0 +1,12 @@ +/* +** EPITECH PROJECT, 2019 +** Gamacon +** File description: +** gravity_component +*/ + +#pragma once + +#include "component.h" + +extern const struct gc_component win_component; \ No newline at end of file diff --git a/prefabs/game.gcprefab b/prefabs/game.gcprefab index 03b538e..b2df42b 100644 --- a/prefabs/game.gcprefab +++ b/prefabs/game.gcprefab @@ -62,6 +62,14 @@ + + + + + + + + diff --git a/src/components/kill_component.c b/src/components/kill_component.c index d818f70..b84d499 100644 --- a/src/components/kill_component.c +++ b/src/components/kill_component.c @@ -22,7 +22,7 @@ const struct kill_component kill_component = { name: "kill_component", size: sizeof(struct kill_component), dependencies: (char *[]){ - "movable_component", + "collision_component", "transform_component", NULL }, diff --git a/src/components/live_component.c b/src/components/live_component.c index 658b157..a270962 100644 --- a/src/components/live_component.c +++ b/src/components/live_component.c @@ -10,6 +10,7 @@ #include "components/live_component.h" #include "components/collision_component.h" #include "components/transform_component.h" +#include "components/win_component.h" #include "utility.h" #include @@ -18,13 +19,16 @@ static void on_collide(gc_engine *engine, gc_entity *entity, int id) struct live_component *cmp = GETCMP(live_component); struct transform_component *trans = GETCMP(transform_component); - if (!GETCOLCMP(kill_component)) - return; - cmp->live--; - if (cmp->live < 0) { + if (GETCOLCMP(kill_component)) { + cmp->live--; + if (cmp->live < 0) { + exit(0); + } else { + trans->position = cmp->spawn_position; + } + } + if (GETCOLCMP(win_component)) { exit(0); - } else { - trans->position = cmp->spawn_position; } } diff --git a/src/components/win_component.c b/src/components/win_component.c new file mode 100644 index 0000000..a08ef88 --- /dev/null +++ b/src/components/win_component.c @@ -0,0 +1,32 @@ +/* +** EPITECH PROJECT, 2020 +** Twac +** File description: +** win_component +*/ + +#include "component.h" +#include "components/win_component.h" +#include "utility.h" +#include + +static char *serialize(void *component) +{ + (void)component; + return (NULL); +} + +const struct gc_component win_component = { + name: "win_component", + size: sizeof(struct gc_component), + dependencies: (char *[]){ + "collision_component", + "transform_component", + NULL + }, + ctr: NULL, + fdctr: NULL, + dtr: NULL, + serialize: &serialize, + destroy: &component_destroy +}; \ No newline at end of file diff --git a/src/game_loader.c b/src/game_loader.c index 66be0d4..5b19b08 100644 --- a/src/game_loader.c +++ b/src/game_loader.c @@ -13,6 +13,7 @@ #include "components/jump_action.h" #include "components/live_component.h" #include "components/kill_component.h" +#include "components/win_component.h" #include "systems/gravity_system.h" #include "systems/walk_system.h" #include "systems/jump_system.h" @@ -28,6 +29,7 @@ int register_customcmps(gc_engine *engine) engine->finish_physics(engine); engine->add_component(engine, &live_component); engine->add_component(engine, &kill_component); + engine->add_component(engine, &win_component); return (0); }