Cleaning up controllable things

This commit is contained in:
Anonymus Raccoon
2020-03-30 15:22:43 +02:00
parent 146fbb43db
commit 469eeeb144
10 changed files with 9 additions and 241 deletions
@@ -1,21 +0,0 @@
/*
** EPITECH PROJECT, 2019
** Gamacon
** File description:
** movable_component
*/
#pragma once
#include "component.h"
#include <stdbool.h>
struct controllable_component
{
gc_component base;
bool moving_left;
bool moving_right;
bool jumping;
};
extern const struct controllable_component controllable_component;
@@ -1,21 +0,0 @@
/*
** EPITECH PROJECT, 2019
** Gamacon
** File description:
** keyboard_component
*/
#pragma once
#include "component.h"
#include <stdbool.h>
struct keyboard_controller
{
gc_component base;
int left_key;
int right_key;
int jump_key;
};
extern const struct keyboard_controller keyboard_controller;
+1 -1
View File
@@ -9,7 +9,7 @@
#include <stdbool.h>
#include "components/vertex_component.h"
#define ANGLE_X 45
#define ANGLE_X 25
#define ANGLE_Y 35
#define ADD_VALUE 10
@@ -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 keyboard_controller_system;
+8
View File
@@ -23,6 +23,14 @@ typedef struct gc_vector2i
int y;
} gc_vector2i;
typedef struct gc_vector3
{
int x;
int y;
int z;
} gc_vector3;
float gcvector_magnitude(gc_vector2 vec);
gc_vector2 gcvector2_normilize(gc_vector2 vec);
-68
View File
@@ -1,68 +0,0 @@
/*
** EPITECH PROJECT, 2019
** MUL_my_runner_2019
** File description:
** controllable_component
*/
#include "xml.h"
#include "component.h"
#include "components/controllable_component.h"
#include "utility.h"
#include <stdlib.h>
static void controllable_ctr(void *component, va_list args)
{
struct controllable_component *cmp = (struct controllable_component *)\
component;
cmp->moving_left = false;
cmp->moving_right = false;
cmp->jumping = false;
(void)args;
}
static void controllable_fdctr(gc_entity *entity, gc_scene *scene, \
void *component, node *n)
{
struct controllable_component *cmp = (struct controllable_component *)\
component;
cmp->moving_left = false;
cmp->moving_right = false;
cmp->jumping = false;
(void)scene;
(void)entity;
(void)n;
}
static void controllable_dtr(void *component)
{
(void)component;
}
static char *controllable_serialize(void *component)
{
(void)component;
return (NULL);
}
const struct controllable_component controllable_component = {
base: {
name: "controllable_component",
size: sizeof(struct controllable_component),
dependencies: (char *[]){
"movable_component",
"transform_component",
NULL
},
ctr: &controllable_ctr,
fdctr: &controllable_fdctr,
dtr: &controllable_dtr,
serialize: &controllable_serialize,
destroy: &component_destroy
},
moving_left: false,
moving_right: false,
jumping: false
};
@@ -1,68 +0,0 @@
/*
** EPITECH PROJECT, 2019
** MUL_my_runner_2019
** File description:
** keyboard_controller
*/
#include "xml.h"
#include "component.h"
#include "components/controllable_component.h"
#include "components/controllers/keyboard_controller.h"
#include "utility.h"
#include <stdlib.h>
static void ctr(void *component, va_list args)
{
struct keyboard_controller *cmp = (struct keyboard_controller *)\
component;
cmp->left_key = va_arg(args, int);
cmp->right_key = va_arg(args, int);
cmp->jump_key = va_arg(args, int);
}
static void fdctr(gc_entity *entity, gc_scene *scene, void *component, node *n)
{
struct keyboard_controller *cmp = (struct keyboard_controller *)\
component;
cmp->left_key = xml_getintprop(n, "left");
cmp->right_key = xml_getintprop(n, "right");
cmp->jump_key = xml_getintprop(n, "jump");
(void)scene;
(void)entity;
}
static void dtr(void *component)
{
(void)component;
}
static char *serialize(void *component)
{
(void)component;
return (NULL);
}
const struct keyboard_controller keyboard_controller = {
base: {
name: "keyboard_controller",
size: sizeof(struct keyboard_controller),
dependencies: (char *[]){
"movable_component",
"transform_component",
"controllable_component",
NULL
},
ctr: &ctr,
fdctr: &fdctr,
dtr: &dtr,
serialize: &serialize,
destroy: &component_destroy
},
left_key: 16,
right_key: 3,
jump_key: 57
};
-4
View File
@@ -12,8 +12,6 @@
#include "components/renderer.h"
#include "components/camerafollow_component.h"
#include "components/transform_component.h"
#include "components/controllable_component.h"
#include "components/controllers/keyboard_controller.h"
#include "components/friction_component.h"
#include "components/friction_giver.h"
#include "components/collision_component.h"
@@ -39,8 +37,6 @@ void engine_add_buildin_components(gc_engine *engine)
engine->add_component(engine, &camerafollow_component);
engine->add_component(engine, &fixed_to_cam);
engine->add_component(engine, &parallax_component);
engine->add_component(engine, &controllable_component);
engine->add_component(engine, &keyboard_controller);
engine->add_component(engine, &friction_giver);
engine->add_component(engine, &friction_component);
engine->add_component(engine, &collision_component);
-2
View File
@@ -10,7 +10,6 @@
#include "systems/sfml_renderer_system.h"
#include "systems/movable_system.h"
#include "systems/parallax_system.h"
#include "systems/controllers/keyboard_controller_system.h"
#include "systems/friction_system.h"
#include "systems/collision_system.h"
#include "systems/camerafollow_system.h"
@@ -35,7 +34,6 @@ void engine_add_builtin_systems(gc_engine *engine)
engine->get_system = &engine_get_system;
engine->finish_physics = &engine_finish_physics;
engine->add_system(engine, &parallax_system);
engine->add_system(engine, &keyboard_controller_system);
engine->add_system(engine, &friction_system);
engine->add_system(engine, new_system(&tooltip_system));
engine->add_system(engine, new_system(&collision_system, engine->scene));
@@ -1,44 +0,0 @@
/*
** EPITECH PROJECT, 2019
** MUL_my_runner_2019
** File description:
** movable_system
*/
#include "entity.h"
#include "system.h"
#include "vector2.h"
#include "components/movable_component.h"
#include "components/controllable_component.h"
#include "components/controllers/keyboard_controller.h"
#include "components/renderer.h"
#include <stddef.h>
void keyboard_update_entity(gc_engine *engine, void *system, \
gc_entity *entity, float dtime)
{
struct controllable_component *con = GETCMP(entity, controllable_component);
struct keyboard_controller *key = GETCMP(entity, keyboard_controller);
con->moving_left = engine->is_keypressed(key->left_key);
con->moving_right = engine->is_keypressed(key->right_key);
con->jumping = engine->is_keypressed(key->jump_key);
(void)system;
(void)dtime;
}
void keyboard_destroy(void *system)
{
(void)system;
}
const gc_system keyboard_controller_system = {
name: "keyboard_controller_system",
component_name: "keyboard_controller",
size: sizeof(gc_system),
ctr: NULL,
dtr: NULL,
check_dependencies: &system_check_dependencies,
update_entity: &keyboard_update_entity,
destroy: &keyboard_destroy
};