From c30a5581ad0f89e25bc34e294a7afd59f86ecffb Mon Sep 17 00:00:00 2001 From: Ragot mathis <5OLE1L@localhost.localdomain> Date: Wed, 15 Apr 2020 15:20:51 +0200 Subject: [PATCH] adding component xp --- Makefile | 4 ++- include/components/xp_component.h | 28 ++++++++++++++++ prefabs/player.gcprefab | 1 + src/components/xp_component.c | 54 +++++++++++++++++++++++++++++++ src/components/xp_methods.c | 27 ++++++++++++++++ 5 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 include/components/xp_component.h create mode 100644 src/components/xp_component.c create mode 100644 src/components/xp_methods.c diff --git a/Makefile b/Makefile index 4e01a6b..b5b652e 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,9 @@ SRC = src/main.c \ src/map_editor/selectors.c \ src/map_editor/toolbar.c \ src/components/health_component.c \ - src/components/health_methods.c + src/components/health_methods.c \ + src/components/xp_component.c \ + src/components/xp_methods.c OBJ = $(SRC:%.c=%.o) diff --git a/include/components/xp_component.h b/include/components/xp_component.h new file mode 100644 index 0000000..6292435 --- /dev/null +++ b/include/components/xp_component.h @@ -0,0 +1,28 @@ +/* +** EPITECH PROJECT, 2019 +** Gamacon +** File description: +** xp_component +*/ + +#ifndef MY_RPG_HEALTH_COMPONENT_H +#define MY_RPG_HEALTH_COMPONENT_H + +#include +#include "component.h" + +struct xp_component +{ + gc_component base; + int xp; + bool full; +}; + +void add_xp(struct xp_component *this, gc_engine *engine, \ +unsigned int amount); +void rem_xp(struct xp_component *this, gc_engine *engine, \ +unsigned int amount); + +extern const struct xp_component xp_component; + +#endif //MY_RPG_HEALTH_COMPONENT_H diff --git a/prefabs/player.gcprefab b/prefabs/player.gcprefab index ddd6f0c..aa53be2 100644 --- a/prefabs/player.gcprefab +++ b/prefabs/player.gcprefab @@ -37,5 +37,6 @@ + \ No newline at end of file diff --git a/src/components/xp_component.c b/src/components/xp_component.c new file mode 100644 index 0000000..a5b5687 --- /dev/null +++ b/src/components/xp_component.c @@ -0,0 +1,54 @@ +/* +** EPITECH PROJECT, 2020 +** My3D +** File description: +** xp component +*/ + +#include "xml.h" +#include "component.h" +#include "components/xp_component.h" + +static void ctr(void *component, va_list args) +{ + struct xp_component *cmp = (struct xp_component *)\ +component; + cmp->xp = va_arg(args, int); + cmp->full = false; +} + +static void fdctr(gc_entity *entity, gc_scene *scene, \ +void *component, node *n) +{ + struct xp_component *cmp = (struct xp_component *)\ +component; + + cmp->xp = xml_getintprop(n, "xp"); + cmp->full = false; +} + +static void dtr(void *component) +{ + (void)component; +} + +static char *serialize(void *component) +{ + (void)component; + return (NULL); +} + +const struct xp_component xp_component = { + base: { + name: "xp_component", + size: sizeof(struct xp_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/components/xp_methods.c b/src/components/xp_methods.c new file mode 100644 index 0000000..8a1a4ff --- /dev/null +++ b/src/components/xp_methods.c @@ -0,0 +1,27 @@ +/* +** EPITECH PROJECT, 2020 +** My3D +** File description: +** xp methods +*/ + +#include "components/xp_component.h" +#include "engine.h" + +void add_xp(struct xp_component *this, gc_engine *engine, \ +unsigned int amount) +{ + if (this->full) + return; + this->xp += amount; + if (this->xp >= 100) + this->full = true; + engine->trigger_event(engine, "add_xp", this->xp, amount); +} + +void rem_xp(struct xp_component *this, gc_engine *engine, \ +unsigned int amount) +{ + this->xp -= amount; + engine->trigger_event(engine, "rem_xp", this->xp, amount); +} \ No newline at end of file