This commit is contained in:
Clément Le Bihan
2020-04-01 16:57:55 +02:00
8 changed files with 101 additions and 6 deletions
+10 -1
View File
@@ -263,7 +263,16 @@ add_executable(my_rpg
lib/gamacon/src/systems/map_linker_system.c
src/components/health_component.c
include/components/health_component.h
src/components/health_methods.c)
src/components/health_methods.c
lib/gamacon/src/sfml_renderer/sfml_utilities.c
lib/gamacon/src/components/map_linker.c
lib/gamacon/include/components/map_linker.h
lib/gamacon/src/systems/map_linker_system.c
lib/gamacon/include/tile.h
src/components/dialog_holder.c
include/components/dialog_holder.h
src/systems/dialog_manager.c
)
add_compile_options(-W -Wall -Wextra -Wshadow)
+1
View File
@@ -17,6 +17,7 @@ SRC = src/main.c \
src/components/controllers/keyboard_controller.c \
src/components/dialog_holder.c \
src/systems/map_movement_system.c \
src/systems/dialog_manager.c \
src/systems/controllers/keyboard_controller_system.c
OBJ = $(SRC:%.c=%.o)
+7
View File
@@ -22,4 +22,11 @@ struct dialog_holder {
const struct dialog_holder dialog_holder;
struct dialog_manager {
gc_system base;
bool is_dialog_open;
};
const struct dialog_manager dialog_manager;
#endif //MY_RPG_DIALOG_HOLDER_H
+4
View File
@@ -0,0 +1,4 @@
<gc_entities>
<panel src="panel" x="50%" y="87%" width="100%" height="26%" tag="dialog" />
<text text="glkgnzlkgnalnzfkzllf Hello World" x="7%" y="87%" centered="false" tag="dialog"/>
</gc_entities>
+3 -1
View File
@@ -8,6 +8,7 @@
#include "engine.h"
#include "setup.h"
#include <SFML/System.h>
#include <components/dialog_holder.h>
#include "systems/map_movement_system.h"
#include "systems/game_manager_system.h"
#include "systems/controllers/keyboard_controller_system.h"
@@ -16,7 +17,6 @@
#include "components/controllable_component.h"
#include "callbacks.h"
#include "components/game_manager.h"
#include "systems/game_manager_system.h"
#include "my.h"
const struct callback callbacks[] = {
@@ -41,6 +41,8 @@ int register_customcmps(gc_engine *engine)
engine->add_component(engine, &keyboard_controller);
engine->add_component(engine, &map_movement);
engine->add_system(engine, &map_movement_system);
engine->add_component(engine, &dialog_holder);
engine->add_system(engine, new_system(&dialog_manager, engine));
engine->add_system(engine, new_system(&keyboard_controller_system, engine));
engine->add_component(engine, &game_manager);
engine->add_system(engine, new_system(&game_manager_system, engine));
+66
View File
@@ -0,0 +1,66 @@
/*
** EPITECH PROJECT, 2020
** my_rpg
** File description:
** dialog_manager.c
*/
#include "my.h"
#include "components/dialog_holder.h"
#include "components/tag_component.h"
#include "prefab.h"
#include "engine.h"
static void check_for_dialog(gc_engine *engine, va_list args)
{
struct dialog_manager *dima = GETSYS(engine, dialog_manager);
gc_keybindings key = va_arg(args, gc_keybindings);
gc_scene *scene = engine->scene;
gc_list *list;
if (key != SPACE)
return;
dima->is_dialog_open = !dima->is_dialog_open;
if (dima->is_dialog_open) {
prefab_load(engine, "prefabs/dialog.gcprefab");
return;
}
list = scene->get_entity_by_cmp(scene, "tag_component");
for (gc_list *li = list; li; li = li->next) {
if (!my_strcmp(GETCMP(li->data, tag_component)->tag, "dialog"))
((gc_entity *)li->data)->destroy(li->data, scene);
}
}
static void update_entity(gc_engine *engine, void *system, gc_entity *entity, \
float dtime)
{
}
static void ctr(void *system, va_list list)
{
gc_engine *engine = va_arg(list, gc_engine *);
struct dialog_manager *dima = (struct dialog_manager *)system;
engine->add_event_listener(engine, "key_pressed", &check_for_dialog);
dima->is_dialog_open = false;
}
static void dtr(void *system, gc_engine *engine)
{
engine->remove_event_listener(engine, "key_pressed", &check_for_dialog);
}
const struct dialog_manager dialog_manager = {
base: {
name: "dialog_manager",
component_name: "dialog_holder",
size: sizeof(gc_system),
ctr: &ctr,
dtr: &dtr,
check_dependencies: &system_check_dependencies,
update_entity: &update_entity,
destroy: &system_destroy
},
};
+7 -2
View File
@@ -51,12 +51,17 @@ static void ctr(void *system, va_list list)
engine->add_event_listener(engine, "key_pressed", &key_pressed);
}
static void dtr(void *system, gc_engine *engine)
{
engine->remove_event_listener(engine, "key_pressed", &key_pressed);
}
const gc_system game_manager_system = {
name: "game_cycle",
component_name: "game_manager",
size: sizeof(gc_system),
ctr: ctr,
dtr: NULL,
ctr: &ctr,
dtr: &dtr,
check_dependencies: &system_check_dependencies,
update_entity: &update_entity,
destroy: &system_destroy
+3 -2
View File
@@ -43,7 +43,8 @@ float dtime)
return;
map = GETCMP(maps->data, vertex_component);
new_tile = get_tile_at(map, map_pos);
if (new_tile && !new_tile->solid && ctl->move_callback <= 0) {
if (new_tile && !new_tile->solid && ctl->move_callback <= 0 \
&& new_tile != link->tile) {
link->tile->entity = NULL;
new_tile->entity = entity;
engine->trigger_event(engine, "entity_moved", entity, link->tile);
@@ -56,7 +57,7 @@ static void ctr(void *system, va_list list)
{
}
static void destroy(void *system)
static void destroy(void *system, gc_engine *engine)
{
}