Making teams messages disapear

This commit is contained in:
AnonymusRaccoon
2020-03-06 17:28:30 +01:00
parent 27950654f0
commit ac1b41df02
22 changed files with 319 additions and 129 deletions
+16 -1
View File
@@ -211,7 +211,22 @@ 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 src/systems/teams_system.c include/systems/teams_system.h include/components/teams_component.h src/components/teams_component.c lib/gamacon/src/components/tag_component.c lib/gamacon/include/components/tag_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
lib/gamacon/src/components/tag_component.c
lib/gamacon/include/components/tag_component.h
src/components/game_manager.c
include/components/game_manager.h
include/dpr_errors.h
include/components/game_display.h
src/components/game_display.c
src/systems/game_display_system.c src/components/teams_pm_component.cpp)
add_compile_options(-W -Wall -Wextra -Wshadow)
Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

+24
View File
@@ -0,0 +1,24 @@
//
// Created by anonymus-raccoon on 3/3/20.
//
#ifndef _TEAMS_COMPONENT_C_
#define _TEAMS_COMPONENT_H_
#include "component.h"
typedef enum display_type
{
HAPPINESS_DISPLAY
} display_type;
struct game_display
{
gc_component base;
display_type type;
};
const struct game_display game_display;
const struct gc_system game_display_system;
#endif //_TEAMS_COMPONENT_C_
+18
View File
@@ -0,0 +1,18 @@
//
// Created by anonymus-raccoon on 3/3/20.
//
#ifndef _TEAMS_COMPONENT_C_
#define _TEAMS_COMPONENT_H_
#include "component.h"
struct game_manager
{
gc_component base;
int happiness;
};
const struct game_manager game_manager;
#endif //_TEAMS_COMPONENT_C_
+1
View File
@@ -13,6 +13,7 @@ struct teams_component
float next_teams;
float delay;
char **prefabs;
int *prefabs_size;
int prefab_count;
};
+11
View File
@@ -0,0 +1,11 @@
//
// Created by anonymus-raccoon on 3/6/20.
//
#ifndef _DPR_ERRORS_H_
#define _DPR_ERRORS_H_
#define MULTIPLE_GAME_MGR_ERROR "Warning: two game manager exists, \
behaviors are undefined.\n"
#endif //_DPR_ERRORS_H_
+3 -1
View File
@@ -55,7 +55,7 @@ int my_getnbr(const char *str)
int start_index = -1;
char c;
for (int i = 0; 1; i++) {
for (int i = 0; str[i]; i++) {
c = str[i];
if ((c >= '0' && c <= '9') || c == '-' || c == '+') {
if (start_index == -1)
@@ -65,5 +65,7 @@ int my_getnbr(const char *str)
else if (count > 0 || c == '\0')
break;
}
if (count <= 0)
return (0);
return init_print(str, count, start_index);
}
+2
View File
@@ -14,6 +14,8 @@ char *my_strdup(const char *src)
int length = my_strlen(src);
char *ret = malloc(sizeof(char) * (length + 1));
if (!ret)
return (NULL);
for (int i = 0; i < length; i++)
ret[i] = src[i];
ret[length] = '\0';
+3
View File
@@ -54,6 +54,9 @@ char *tostr(int n)
int count = get_new_size(n);
char *ret = malloc(sizeof(char) * (count + 1));
if (!ret)
return (NULL);
putnbr_in(n, base, ret, count);
ret[count] = '\0';
return (ret);
-95
View File
@@ -1,95 +0,0 @@
/*
** EPITECH PROJECT, 2019
** Sum stdarg
** File description:
** sum_stdarg
*/
#include "formaters.h"
#include "my.h"
#include <stdarg.h>
#include <unistd.h>
formater_t formaters[] = {{string_formater, 's'},
{string_nonprintable_formater, 'S'},
{char_formater, 'c'},
{int_formater, 'i'},
{int_formater, 'd'},
{octal_formater, 'o'},
{hexa_formater, 'x'},
{big_hexa_formater, 'X'},
{uint_formater, 'u'},
{ptr_formater, 'p'},
{ubinary_formater, 'b'},
{float_formater, 'f'},
{float_formater, 'F'},
{no_format, '%'},
{0, 0}};
const char modifiersCst[] = "#0-+ hl";
int format(va_list ap, char flag, char modifiers[MODIFIERS_SIZE])
{
for (int i = 0; formaters[i].flag; i++) {
if (formaters[i].flag == flag) {
return (formaters[i].func(ap, modifiers));
}
}
return (0);
}
int is_flag(char c)
{
for (int i = 0; formaters[i].flag; i++) {
if (formaters[i].flag == c) {
return (1);
}
}
return (0);
}
int is_modifier(char c)
{
for (int i = 0; modifiersCst[i]; i++) {
if (modifiersCst[i] == c)
return (1);
}
return (0);
}
int get_modifiers(const char *str, char flags[MODIFIERS_SIZE])
{
int i;
for (i = 0; !is_flag(str[i]); i++) {
if (!is_modifier(str[i]) && !is_num(str[i]))
return (-1);
flags[i] = str[i];
}
flags[i] = '\0';
return (i);
}
int my_printf(const char *str, ...)
{
int count = 0;
va_list ap;
char modifiers[MODIFIERS_SIZE];
int next_is_flag;
va_start(ap, str);
for (int i = 0; str[i]; i++) {
if (str[i] == '%') {
next_is_flag = 1;
i++;
i += get_modifiers(&str[i], modifiers);
} else
next_is_flag = 0;
if (next_is_flag && is_flag(str[i]))
count += format(ap, str[i], modifiers);
else
count += write(1, &str[i], 1);
}
va_end(ap);
return (count);
}
+15 -14
View File
@@ -11,20 +11,21 @@
#include <unistd.h>
formater_t formaters[] = {{string_formater, 's'},
{string_nonprintable_formater, 'S'},
{char_formater, 'c'},
{int_formater, 'i'},
{int_formater, 'd'},
{octal_formater, 'o'},
{hexa_formater, 'x'},
{big_hexa_formater, 'X'},
{uint_formater, 'u'},
{ptr_formater, 'p'},
{ubinary_formater, 'b'},
{float_formater, 'f'},
{float_formater, 'F'},
{no_format, '%'},
{0, 0}};
{string_nonprintable_formater, 'S'},
{char_formater, 'c'},
{int_formater, 'i'},
{int_formater, 'd'},
{octal_formater, 'o'},
{hexa_formater, 'x'},
{big_hexa_formater, 'X'},
{uint_formater, 'u'},
{ptr_formater, 'p'},
{ubinary_formater, 'b'},
{float_formater, 'f'},
{float_formater, 'F'},
{no_format, '%'},
{0, 0}
};
const char modifiersCst[] = "#0-+ hl";
+11 -6
View File
@@ -5,10 +5,12 @@
<sprite name="cross" src="assets/ui/cross.png" />
<sprite name="front_panel" src="assets/ui/front_panel.png" />
<sprite name="button_background" src="assets/ui/button_background.png" />
<sprite name="happiness" src="assets/ui/happiness.png" />
<sprite name="cobblestone" src="assets/sprites/cobblestone.png" />
<sprite name="mossy_cobblestone" src="assets/sprites/cobblestone_mossy.png" />
<sprite name="command_block" src="assets/sprites/command_block.png" />
<sprite name="crafting_table" src="assets/sprites/crafting_table_top.png" />
<music src="assets/musics/music.ogg"/>
<font src="assets/fonts/roboto.ttf" />
</data>
<gc_entities>
@@ -24,17 +26,20 @@
</gc_entity>
<gc_entity>
<teams_component delay="10">
<prefab src="prefabs/teams/forgot_register.gcprefab" />
<game_manager happiness="50%" />
<teams_component delay="5">
<prefab src="prefabs/teams/forgot_register.gcprefab" height="20%" />
<prefab src="prefabs/teams/absent.gcprefab" height="20%" />
</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="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="%" />
<panel src="cross" x="93%" y="75%" width="3%" height="%" />
<panel src="panel" x="50%" y="98%" width="120%" height="4%"/>
<panel src="happiness" x="3%" y="98%" width="%" height="3%"/>
<text text="100%" x="6%" y="98%" size="13">
<game_display stats="happiness" />
</text>
</gc_entities>
</gc_scene>
+6
View File
@@ -0,0 +1,6 @@
<gc_entities>
<panel src="front_panel" x="89%" y="80%" width="20%" height="8%" tag="teams" />
<text text="I was absent today at the talk.\nCould you set my status as present?" x="89%" y="82%" color="black" size="9" tag="teams" />
<panel src="check" x="85%" y="85%" width="3%" height="%" tag="teams" />
<panel src="cross" x="93%" y="85%" width="3%" height="%" tag="teams" />
</gc_entities>
+6 -6
View File
@@ -1,8 +1,8 @@
<gc_entities>
<panel src="front_panel" x="89%" y="50%" width="20%" height="8%" tag="teams" />
<text text="I forgot to register for the module,\n could you register me?" x="89%" y="52%" color="black" size="9" tag="teams"/>
<panel src="front_panel" x="89%" y="56%" width="17%" height="5%" tag="teams" />
<text text="LMFAO" x="89%" y="56%" color="black" size="9" tag="teams" />
<panel src="front_panel" x="89%" y="60%" width="17%" height="5%" tag="teams" />
<text text="It's the first and the last time." x="89%" y="60%" color="black" size="9" tag="teams" />
<panel src="front_panel" x="89%" y="80%" width="20%" height="8%" tag="teams" />
<text text="I forgot to register for the module,\n could you register me?" x="89%" y="82%" color="black" size="9" tag="teams" />
<panel src="front_panel" x="89%" y="86%" width="17%" height="5%" tag="teams" />
<text text="LMFAO" x="89%" y="86%" color="black" size="9" tag="teams" />
<panel src="front_panel" x="89%" y="90%" width="17%" height="5%" tag="teams" />
<text text="It's the first and the last time." x="89%" y="90%" color="black" size="9" tag="teams" />
</gc_entities>
+63
View File
@@ -0,0 +1,63 @@
/*
** EPITECH PROJECT, 2020
** DPR
** File description:
** game_stats
*/
#include <components/renderer.h>
#include <text.h>
#include "dpr_errors.h"
#include "xml.h"
#include "component.h"
#include "utility.h"
#include "components/game_display.h"
#include <malloc.h>
static void ctr(void *component, va_list args)
{
struct game_display *cmp = (struct game_display *)component;
cmp->type = va_arg(args, display_type);
}
static void fdctr(gc_entity *entity, gc_scene *scene, void *component, node *n)
{
struct game_display *cmp = (struct game_display *)component;
struct renderer *rend = GETCMP(entity, renderer);
cmp->type = HAPPINESS_DISPLAY;
if (!rend || rend->type != GC_TXTREND) {
my_printf("Using a game display without a text renderer.\n");
return;
}
((gc_text *)rend->data)->text = malloc(sizeof(char) * 10);
if (((gc_text *)rend->data)->text)
((gc_text *)rend->data)->text[0] = '\0';
}
static void dtr(void *component)
{
(void)component;
}
static char *serialize(void *component)
{
(void)component;
return (NULL);
}
const struct game_display game_display = {
base: {
name: "game_display",
size: sizeof(struct game_display),
dependencies: (char *[]) {
NULL
},
ctr: &ctr,
fdctr: &fdctr,
dtr: &dtr,
serialize: &serialize,
destroy: &component_destroy
}
};
+54
View File
@@ -0,0 +1,54 @@
/*
** EPITECH PROJECT, 2020
** DPR
** File description:
** game_stats
*/
#include "dpr_errors.h"
#include "xml.h"
#include "component.h"
#include "utility.h"
#include "components/game_manager.h"
static void ctr(void *component, va_list args)
{
struct game_manager *cmp = (struct game_manager *)component;
cmp->happiness = va_arg(args, int);
}
static void fdctr(gc_entity *entity, gc_scene *scene, void *component, node *n)
{
struct game_manager *cmp = (struct game_manager *)component;
cmp->happiness = xml_getintprop(n, "happiness");
if (scene->get_entity_by_cmp(scene, "game_manager"))
my_printf(MULTIPLE_GAME_MGR_ERROR);
}
static void dtr(void *component)
{
(void)component;
}
static char *serialize(void *component)
{
(void)component;
return (NULL);
}
const struct game_manager game_manager = {
base: {
name: "game_manager",
size: sizeof(struct game_manager),
dependencies: (char *[]) {
NULL
},
ctr: &ctr,
fdctr: &fdctr,
dtr: &dtr,
serialize: &serialize,
destroy: &component_destroy
}
};
+8
View File
@@ -27,9 +27,17 @@ static void fdctr(gc_entity *entity, gc_scene *scene, void *component, node *n)
cmp->next_teams = cmp->delay;
cmp->prefab_count = xml_getchildcount_filtered(n, "prefab");
cmp->prefabs = malloc(sizeof(char *) * cmp->prefab_count);
cmp->prefabs_size = malloc(sizeof(int) * cmp->prefab_count);
n = n->child;
if (!cmp->prefabs || !cmp->prefab_count) {
cmp->prefabs = NULL;
cmp->prefabs_size = NULL;
cmp->prefab_count = 0;
return;
}
for (int i = 0; i < cmp->prefab_count; i++) {
cmp->prefabs[i] = xml_getproperty(n, "src");
cmp->prefabs_size[i] = xml_getintprop(n, "height");
n = n->next;
}
}
+5
View File
@@ -10,9 +10,14 @@
#include "components/teams_component.h"
#include "systems/teams_system.h"
#include <SFML/System.h>
#include "components/game_display.h"
#include "components/game_manager.h"
int register_customcmps(gc_engine *engine)
{
engine->add_component(engine, &game_manager);
engine->add_component(engine, &game_display);
engine->add_system(engine, &game_display_system);
engine->add_component(engine, &teams_component);
engine->add_system(engine, &teams_system);
engine->finish_physics(engine);
+49
View File
@@ -0,0 +1,49 @@
/*
** EPITECH PROJECT, 2019
** MUL_my_runner_2019
** File description:
** teams_system
*/
#include "entity.h"
#include "system.h"
#include <stddef.h>
#include "components/game_display.h"
#include "components/game_manager.h"
#include "text.h"
#include "components/renderer.h"
#include <malloc.h>
static void update_entity(gc_engine *engine, void *system, gc_entity *entity, \
float dtime)
{
struct game_display *disp = GETCMP(entity, game_display);
struct renderer *rend = GETCMP(entity, renderer);
struct game_manager *manager;
gc_scene *scene = engine->scene;
gc_list *entities = scene->get_entity_by_cmp(scene, "game_manager");
if (!entities)
return;
manager = GETCMP(entities->data, game_manager);
if (rend->type != GC_TXTREND)
return;
if (disp->type == HAPPINESS_DISPLAY)
sprintf(((gc_text *)rend->data)->text, "%d%%", manager->happiness);
}
static void destroy(void *system)
{
(void)system;
}
const gc_system game_display_system = {
name: "game_display_system",
component_name: "game_display",
size: sizeof(gc_system),
ctr: NULL,
dtr: NULL,
check_dependencies: &system_check_dependencies,
update_entity: &update_entity,
destroy: &destroy
};
+22 -4
View File
@@ -11,23 +11,41 @@
#include "components/teams_component.h"
#include <stddef.h>
#include <stdlib.h>
#include <components/tag_component.h>
#include <components/fixed_to_cam_component.h>
#include "my.h"
static void move_teams_up(gc_scene *scene)
static void move_teams_up(gc_scene *scene, float amount)
{
gc_list *list = scene->get_entity_by_cmp(scene, "tag_component");
//Should filter components by the tag teams and move them up.
struct fixed_to_cam *fc;
struct tag_component *tc;
for (; list; list = list->next) {
tc = GETCMP(list->data, tag_component);
if (my_strcmp(tc->tag, "teams"))
continue;
fc = GETCMP(list->data, fixed_to_cam);
if (!fc)
continue;
fc->pos.y -= amount;
if (fc->pos.y < 15)
((gc_entity *)list->data)->destroy(list->data, scene);
}
}
static void update_entity(gc_engine *engine, void *system, gc_entity *entity, \
float dtime)
{
struct teams_component *team = GETCMP(entity, teams_component);
int index;
team->next_teams -= dtime;
if (team->next_teams < 0 && team->prefab_count) {
index = random() % team->prefab_count;
team->next_teams = team->delay;
move_teams_up(engine->scene);
prefab_load(engine, team->prefabs[random() % team->prefab_count]);
move_teams_up(engine->scene, team->prefabs_size[index]);
prefab_load(engine, team->prefabs[index]);
}
}