diff --git a/Makefile b/Makefile index 8d4275f..14f1833 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,7 @@ SRC = src/engine/engine.c \ src/components/gravity_component.c \ src/components/friction_component.c \ src/components/actions/walk_component.c \ + src/components/actions/jump_component.c \ src/components/controllers/keyboard_controller.c \ src/scene/scene.c \ src/utility/arraylen.c \ @@ -33,6 +34,7 @@ SRC = src/engine/engine.c \ src/systems/parallax_system.c \ src/systems/gravity_system.c \ src/systems/actions/walk_system.c \ + src/systems/actions/jump_system.c \ src/systems/controllers/keyboard_controller_system.c \ src/systems/friction_system.c \ src/engine/engine_system_builder.c \ diff --git a/include/components/actions/jump_action.h b/include/components/actions/jump_action.h new file mode 100644 index 0000000..30486b3 --- /dev/null +++ b/include/components/actions/jump_action.h @@ -0,0 +1,19 @@ +/* +** EPITECH PROJECT, 2019 +** MUL_my_runner_2019 +** File description: +** walk_action +*/ + +#pragma once + +#include "component.h" +#include + +struct jump_action +{ + gc_component base; + int acceleration; +}; + +extern const struct jump_action jump_action; \ No newline at end of file diff --git a/include/systems/actions/jump_system.h b/include/systems/actions/jump_system.h new file mode 100644 index 0000000..7ee66f3 --- /dev/null +++ b/include/systems/actions/jump_system.h @@ -0,0 +1,12 @@ +/* +** EPITECH PROJECT, 2019 +** MUL_my_runner_2019 +** File description: +** texture_renderer_system +*/ + +#pragma once + +#include "system.h" + +const gc_system jump_system; \ No newline at end of file diff --git a/src/components/actions/jump_component.c b/src/components/actions/jump_component.c new file mode 100644 index 0000000..cc7baa1 --- /dev/null +++ b/src/components/actions/jump_component.c @@ -0,0 +1,58 @@ +/* +** EPITECH PROJECT, 2019 +** MUL_my_runner_2019 +** File description: +** walk_action +*/ + +#include "xml.h" +#include "component.h" +#include "components/controllable_component.h" +#include "components/actions/jump_action.h" +#include "utility.h" +#include + +static void ctr(void *component, va_list args) +{ + struct jump_action *cmp = (struct jump_action *)component; + + cmp->acceleration = va_arg(args, int); +} + +static void fdctr(gc_engine *engine, void *component, node *n) +{ + struct jump_action *cmp = (struct jump_action *)component; + + cmp->acceleration = xml_getintprop(n, "acceleration"); + (void)engine; +} + +static void dtr(void *component) +{ + (void)component; +} + +static char *serialize(void *component) +{ + (void)component; + return (NULL); +} + +const struct jump_action jump_action = { + base: { + name: "jump_action", + size: sizeof(struct jump_action), + dependencies: (char *[]){ + "controllable_component", + "movable_component", + "transform_component", + NULL + }, + ctr: &ctr, + fdctr: &fdctr, + dtr: &dtr, + serialize: &serialize, + destroy: &component_destroy + }, + acceleration: 0 +}; \ No newline at end of file diff --git a/src/engine/engine_component_builder.c b/src/engine/engine_component_builder.c index 1e96b71..a2d9da4 100644 --- a/src/engine/engine_component_builder.c +++ b/src/engine/engine_component_builder.c @@ -14,6 +14,7 @@ #include "components/controllable_component.h" #include "components/gravity_component.h" #include "components/actions/walk_action.h" +#include "components/actions/jump_action.h" #include "components/controllers/keyboard_controller.h" #include "components/friction_component.h" #include @@ -34,6 +35,7 @@ void engine_add_buildin_components(gc_engine *engine) engine->add_component(engine, ¶llax_component); engine->add_component(engine, &controllable_component); engine->add_component(engine, &walk_action); + engine->add_component(engine, &jump_action); engine->add_component(engine, &keyboard_controller); engine->add_component(engine, &gravity_component); engine->add_component(engine, &friction_component); diff --git a/src/engine/engine_system_builder.c b/src/engine/engine_system_builder.c index 15de9c1..efb7948 100644 --- a/src/engine/engine_system_builder.c +++ b/src/engine/engine_system_builder.c @@ -13,6 +13,7 @@ #include "systems/gravity_system.h" #include "systems/controllers/keyboard_controller_system.h" #include "systems/actions/walk_system.h" +#include "systems/actions/jump_system.h" #include "systems/friction_system.h" #include @@ -30,6 +31,7 @@ void engine_add_buildin_systems(gc_engine *engine) engine->add_system(engine, &keyboard_controller_system); engine->add_system(engine, &friction_system); engine->add_system(engine, &walk_system); + engine->add_system(engine, &jump_system); engine->add_system(engine, &gravity_system); engine->add_system(engine, new_system(&movable_system)); } diff --git a/src/systems/actions/jump_system.c b/src/systems/actions/jump_system.c new file mode 100644 index 0000000..9225e6f --- /dev/null +++ b/src/systems/actions/jump_system.c @@ -0,0 +1,46 @@ +/* +** EPITECH PROJECT, 2019 +** MUL_my_runner_2019 +** File description: +** walk_action +*/ + +#include "entity.h" +#include "system.h" +#include "texture.h" +#include "vector2.h" +#include "component.h" +#include "components/movable_component.h" +#include "components/controllable_component.h" +#include "components/actions/jump_action.h" +#include "utility.h" +#include + +void update_entity(gc_engine *engine, void *system, \ +gc_entity *entity, float dtime) +{ + struct controllable_component *con = GETCMP(controllable_component); + struct movable_component *mov = GETCMP(movable_component); + struct jump_action *jump = GETCMP(jump_action); + + mov->acceleration.y += con->jumping * jump->acceleration; + (void)system; + (void)dtime; + (void)engine; +} + +void destroy(void *system) +{ + (void)system; +} + +const gc_system jump_system = { + name: "JumpSystem", + component_name: "jump_action", + 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