Adding a teams system

This commit is contained in:
AnonymusRaccoon
2020-03-03 17:32:10 +01:00
parent 1bbd73c6c6
commit bbbf859973
9 changed files with 160 additions and 9 deletions

View File

@@ -211,7 +211,7 @@ add_executable(My3D
lib/my/my/my_str_replace.c
lib/gamacon/src/sfml_renderer/sfml_init.c
lib/gamacon/src/sfml_renderer/sfml_events.c
lib/xmlparser/src/otherget.c src/options.c lib/gamacon/src/components/input_component.c lib/gamacon/include/components/input_component.h)
lib/xmlparser/src/otherget.c src/options.c lib/gamacon/src/components/input_component.c lib/gamacon/include/components/input_component.h src/systems/teams_system.c include/systems/teams_system.h include/components/teams_component.h src/components/teams_component.c)
add_compile_options(-W -Wall -Wextra -Wshadow)

View File

@@ -0,0 +1,21 @@
//
// Created by anonymus-raccoon on 3/3/20.
//
#ifndef _TEAMS_COMPONENT_C_
#define _TEAMS_COMPONENT_H_
#include "component.h"
struct teams_component
{
gc_component base;
float next_teams;
float delay;
char **prefabs;
int prefab_count;
};
const struct teams_component teams_component;
#endif //_TEAMS_COMPONENT_C_

View File

@@ -0,0 +1,12 @@
//
// Created by anonymus-raccoon on 3/3/20.
//
#ifndef _TEAMS_SYSTEM_H_
#define _TEAMS_SYSTEM_H_
#include "system.h"
const gc_system teams_system;
#endif //_TEAMS_SYSTEM_H_

View File

@@ -22,16 +22,16 @@
<Rect height="auto" width="auto" top="0" left="0" />
</renderer>
</gc_entity>
<gc_entity>
<teams_component delay="10">
<prefab src="prefabs/teams/forgot_register.gcprefab" />
</teams_component>
</gc_entity>
<panel src="panel" x="100%" y="50%" width="50%" height="120%"/>
<text text="TEAMS" x="88%" y="40"/>
<panel src="front_panel" x="89%" y="50%" width="20%" height="8%" />
<text text="I forgot to register for the module,\n could you register me?" x="89%" y="52%" color="black" size="9"/>
<panel src="front_panel" x="89%" y="56%" width="17%" height="5%" />
<text text="LMFAO" x="89%" y="56%" color="black" size="9"/>
<panel src="front_panel" x="89%" y="60%" width="17%" height="5%" />
<text text="It's the first and the last time." x="89%" y="60%" color="black" size="9"/>
<panel src="front_panel" x="89%" y="70%" width="20%" height="8%" />
<text text="I was absent today at the talk.\nCould you set my status as present?" x="89%" y="72%" color="black" size="9" />
<panel src="check" x="85%" y="75%" width="3%" height="%" />

View File

@@ -0,0 +1,8 @@
<gc_entities>
<panel src="front_panel" x="89%" y="50%" width="20%" height="8%" />
<text text="I forgot to register for the module,\n could you register me?" x="89%" y="52%" color="black" size="9"/>
<panel src="front_panel" x="89%" y="56%" width="17%" height="5%" />
<text text="LMFAO" x="89%" y="56%" color="black" size="9"/>
<panel src="front_panel" x="89%" y="60%" width="17%" height="5%" />
<text text="It's the first and the last time." x="89%" y="60%" color="black" size="9"/>
</gc_entities>

View File

@@ -0,0 +1,61 @@
/*
** EPITECH PROJECT, 2020
** Twac
** File description:
** camera_follow
*/
#include "xml.h"
#include "component.h"
#include "components/teams_component.h"
#include "utility.h"
#include <stdlib.h>
static void ctr(void *component, va_list args)
{
struct teams_component *cmp = (struct teams_component *)component;
cmp->delay = va_arg(args, double);
cmp->next_teams = cmp->delay;
}
static void fdctr(gc_entity *entity, gc_scene *scene, void *component, node *n)
{
struct teams_component *cmp = (struct teams_component *)component;
cmp->delay = xml_getfloatprop(n, "delay");
cmp->next_teams = cmp->delay;
cmp->prefab_count = xml_getchildcount_filtered(n, "prefab");
cmp->prefabs = malloc(sizeof(char *) * cmp->prefab_count);
n = n->child;
for (int i = 0; i < cmp->prefab_count; i++) {
cmp->prefabs[i] = xml_getproperty(n, "src");
n = n->next;
}
}
static void dtr(void *component)
{
(void)component;
}
static char *serialize(void *component)
{
(void)component;
return (NULL);
}
const struct teams_component teams_component = {
base: {
name: "teams_component",
size: sizeof(struct teams_component),
dependencies: (char *[]) {
NULL
},
ctr: &ctr,
fdctr: &fdctr,
dtr: &dtr,
serialize: &serialize,
destroy: &component_destroy
}
};

View File

@@ -7,10 +7,14 @@
#include "engine.h"
#include "setup.h"
#include "components/teams_component.h"
#include "systems/teams_system.h"
#include <SFML/System.h>
int register_customcmps(gc_engine *engine)
{
engine->add_component(engine, &teams_component);
engine->add_system(engine, &teams_system);
engine->finish_physics(engine);
engine->add_callback(engine, "start_button", &start_button);
engine->add_callback(engine, "options", &options);

View File

@@ -0,0 +1,45 @@
/*
** EPITECH PROJECT, 2019
** MUL_my_runner_2019
** File description:
** teams_system
*/
#include "entity.h"
#include "system.h"
#include "sprite.h"
#include "vector2.h"
#include "prefab.h"
#include "components/teams_component.h"
#include "systems/teams_system.h"
#include <stddef.h>
#include <dirent.h>
#include <stdlib.h>
static void update_entity(gc_engine *engine, void *system, gc_entity *entity, \
float dtime)
{
struct teams_component *team = GETCMP(entity, teams_component);
team->next_teams -= dtime;
if (team->next_teams < 0 && team->prefab_count) {
team->next_teams = team->delay;
prefab_load(engine, team->prefabs[random() % team->prefab_count]);
}
}
static void destroy(void *system)
{
(void)system;
}
const gc_system teams_system = {
name: "teams_system",
component_name: "teams_component",
size: sizeof(gc_system),
ctr: NULL,
dtr: NULL,
check_dependencies: &system_check_dependencies,
update_entity: &update_entity,
destroy: &destroy
};