mirror of
https://github.com/zoriya/Gamacon.git
synced 2026-05-30 10:11:00 +00:00
Moving out walk and jump components
This commit is contained in:
@@ -19,8 +19,6 @@ SRC = src/engine/engine.c \
|
||||
src/components/controllable_component.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,8 +31,6 @@ SRC = src/engine/engine.c \
|
||||
src/systems/movable_system.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 \
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** MUL_my_runner_2019
|
||||
** File description:
|
||||
** walk_action
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "component.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
struct jump_action
|
||||
{
|
||||
gc_component base;
|
||||
int acceleration;
|
||||
};
|
||||
|
||||
extern const struct jump_action jump_action;
|
||||
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** MUL_my_runner_2019
|
||||
** File description:
|
||||
** walk_action
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "component.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
struct walk_action
|
||||
{
|
||||
gc_component base;
|
||||
int acceleration;
|
||||
int max_acceleration;
|
||||
};
|
||||
|
||||
extern const struct walk_action walk_action;
|
||||
@@ -31,6 +31,7 @@ struct gc_engine
|
||||
gc_list *systems;
|
||||
void (*add_system)(gc_engine *engine, const gc_system *system);
|
||||
const gc_system *(*get_system)(gc_engine *engine, const char *name);
|
||||
void (*finish_physics)(gc_engine *engine);
|
||||
|
||||
gc_list *components;
|
||||
void (*add_component)(gc_engine *engine, const void *component);
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** MUL_my_runner_2019
|
||||
** File description:
|
||||
** texture_renderer_system
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "system.h"
|
||||
|
||||
const gc_system jump_system;
|
||||
@@ -1,12 +0,0 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** MUL_my_runner_2019
|
||||
** File description:
|
||||
** texture_renderer_system
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "system.h"
|
||||
|
||||
extern const gc_system walk_system;
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
** 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 <stdlib.h>
|
||||
|
||||
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_scene *scene, void *component, node *n)
|
||||
{
|
||||
struct jump_action *cmp = (struct jump_action *)component;
|
||||
|
||||
cmp->acceleration = xml_getintprop(n, "acceleration");
|
||||
(void)scene;
|
||||
}
|
||||
|
||||
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
|
||||
};
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
** 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/walk_action.h"
|
||||
#include "utility.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
static void walk_ctr(void *component, va_list args)
|
||||
{
|
||||
struct walk_action *cmp = (struct walk_action *)component;
|
||||
|
||||
cmp->acceleration = va_arg(args, int);
|
||||
cmp->max_acceleration = va_arg(args, int);
|
||||
}
|
||||
|
||||
static void walk_fdctr(gc_scene *scene, void *component, node *n)
|
||||
{
|
||||
struct walk_action *cmp = (struct walk_action *)component;
|
||||
|
||||
cmp->acceleration = xml_getintprop(n, "acceleration");
|
||||
cmp->max_acceleration = xml_getintprop(n, "max_acceleration");
|
||||
(void)scene;
|
||||
}
|
||||
|
||||
static void walk_dtr(void *component)
|
||||
{
|
||||
(void)component;
|
||||
}
|
||||
|
||||
static char *walk_serialize(void *component)
|
||||
{
|
||||
(void)component;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
const struct walk_action walk_action = {
|
||||
base: {
|
||||
name: "walk_action",
|
||||
size: sizeof(struct walk_action),
|
||||
dependencies: (char *[]){
|
||||
"controllable_component",
|
||||
"movable_component",
|
||||
"transform_component",
|
||||
NULL
|
||||
},
|
||||
ctr: &walk_ctr,
|
||||
fdctr: &walk_fdctr,
|
||||
dtr: &walk_dtr,
|
||||
serialize: &walk_serialize,
|
||||
destroy: &component_destroy
|
||||
},
|
||||
acceleration: 0,
|
||||
max_acceleration: 0
|
||||
};
|
||||
@@ -13,8 +13,6 @@
|
||||
#include "components/transform_component.h"
|
||||
#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 <stdlib.h>
|
||||
@@ -34,8 +32,6 @@ void engine_add_buildin_components(gc_engine *engine)
|
||||
engine->add_component(engine, &renderer_component);
|
||||
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);
|
||||
|
||||
@@ -12,8 +12,6 @@
|
||||
#include "systems/parallax_system.h"
|
||||
#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 <stdlib.h>
|
||||
|
||||
@@ -22,18 +20,21 @@ void engine_add_system(gc_engine *engine, const gc_system *system)
|
||||
engine->systems = list_add(engine->systems, (void *)system);
|
||||
}
|
||||
|
||||
void engine_finish_physics(gc_engine *engine)
|
||||
{
|
||||
engine->add_system(engine, new_system(&movable_system));
|
||||
}
|
||||
|
||||
void engine_add_buildin_systems(gc_engine *engine)
|
||||
{
|
||||
engine->systems = NULL;
|
||||
engine->add_system = &engine_add_system;
|
||||
engine->get_system = &engine_get_system;
|
||||
engine->finish_physics = &engine_finish_physics;
|
||||
engine->add_system(engine, ¶llax_system);
|
||||
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));
|
||||
}
|
||||
|
||||
int engine_use_sfml(gc_engine *engine, const char *title, int framerate)
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
** 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 <stddef.h>
|
||||
|
||||
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
|
||||
};
|
||||
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
** 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/walk_action.h"
|
||||
#include "utility.h"
|
||||
#include <stddef.h>
|
||||
|
||||
void walk_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 walk_action *walk = GETCMP(walk_action);
|
||||
bool clamp = mov->acceleration.x < walk->max_acceleration || mov->acceleration.x > -walk->max_acceleration;
|
||||
|
||||
mov->acceleration.x -= con->moving_left * walk->acceleration;
|
||||
mov->acceleration.x += con->moving_right * walk->acceleration;
|
||||
if (clamp)
|
||||
ABSCLAMP(mov->acceleration.x, walk->max_acceleration);
|
||||
(void)system;
|
||||
(void)dtime;
|
||||
(void)engine;
|
||||
}
|
||||
|
||||
void walk_destroy(void *system)
|
||||
{
|
||||
(void)system;
|
||||
}
|
||||
|
||||
const gc_system walk_system = {
|
||||
name: "WalkSystem",
|
||||
component_name: "walk_action",
|
||||
size: sizeof(gc_system),
|
||||
ctr: NULL,
|
||||
dtr: NULL,
|
||||
check_dependencies: &system_check_dependencies,
|
||||
update_entity: &walk_update_entity,
|
||||
destroy: &walk_destroy
|
||||
};
|
||||
Reference in New Issue
Block a user