mirror of
https://github.com/zoriya/ForecastingVillage.git
synced 2026-06-03 02:51:45 +00:00
adding particule component and adding it to the player (one big particule)
This commit is contained in:
+1
-1
@@ -298,7 +298,7 @@ add_executable(my_rpg
|
||||
include/components/attack_component.h
|
||||
src/systems/combat_methods.c
|
||||
src/combat/attacks.c
|
||||
src/player_utilities.c include/player_utilities.h src/systems/inventory.c include/systems/inventory.h src/systems/game_over.c include/systems/game_over.h src/npc/mia.c lib/gamacon/src/scene/scene_constructor.c src/npc/fisherman.c src/npc/lumberjack.c src/npc/smith.c)
|
||||
src/player_utilities.c include/player_utilities.h src/systems/inventory.c include/systems/inventory.h src/systems/game_over.c include/systems/game_over.h src/npc/mia.c lib/gamacon/src/scene/scene_constructor.c src/npc/fisherman.c src/npc/lumberjack.c src/npc/smith.c src/components/particule_component.c include/components/particule_component.h src/systems/particule_system.c include/systems/particule_system.h)
|
||||
|
||||
add_compile_options(-W -Wall -Wextra -Wshadow)
|
||||
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2020
|
||||
** my_rpg
|
||||
** File description:
|
||||
** particule_component.c
|
||||
*/
|
||||
|
||||
#ifndef MY_RPG_PARTICULE_COMPONENT_H
|
||||
#define MY_RPG_PARTICULE_COMPONENT_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "sprite.h"
|
||||
#include "component.h"
|
||||
|
||||
struct particule
|
||||
{
|
||||
unsigned int lifetime;
|
||||
gc_sprite *sprite;
|
||||
};
|
||||
|
||||
struct particule_component
|
||||
{
|
||||
gc_component base;
|
||||
int type;
|
||||
unsigned int lifetime;
|
||||
int nb_max_particules;
|
||||
void *texture;
|
||||
struct particule *particules;
|
||||
};
|
||||
|
||||
|
||||
|
||||
extern const struct particule_component particule_component;
|
||||
|
||||
#endif //MY_RPG_PARTICULE_COMPONENT_H
|
||||
@@ -16,6 +16,6 @@ struct game_manager_system {
|
||||
bool has_message;
|
||||
};
|
||||
|
||||
const struct game_manager_system game_manager_system;
|
||||
extern const struct game_manager_system game_manager_system;
|
||||
|
||||
#endif //_MAP_MOVEMENT_SYSTEM_H__
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** MUL_my_runner_2019
|
||||
** File description:
|
||||
** particule_system
|
||||
*/
|
||||
|
||||
#ifndef MY_RPG_PARTICULE_SYSTEM_H
|
||||
#define MY_RPG_PARTICULE_SYSTEM_H
|
||||
|
||||
#include "engine.h"
|
||||
|
||||
void particule_update_entity(gc_engine *engine, void *system, \
|
||||
gc_entity *entity, float dt);
|
||||
|
||||
extern const struct gc_system particule_system;
|
||||
|
||||
#endif //MY_RPG_PARTICULE_SYSTEM_H
|
||||
@@ -39,5 +39,6 @@
|
||||
<xp_component xp="20"/>
|
||||
<health_component max_health="25"/>
|
||||
<player_component fight_rate="5%" />
|
||||
<particule_component type="1" nb_particules_max="5" lifetime="60" />
|
||||
</gc_entity>
|
||||
</gc_entities>
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2020
|
||||
** my_rpg
|
||||
** File description:
|
||||
** particule_component.c
|
||||
*/
|
||||
|
||||
#include "xml.h"
|
||||
#include "components/particule_component.h"
|
||||
#include "components/map_linker.h"
|
||||
#include "component.h"
|
||||
#include <malloc.h>
|
||||
#include "utility.h"
|
||||
#include "tile.h"
|
||||
|
||||
static void ctr(void *component, va_list args)
|
||||
{
|
||||
struct particule_component *cmp = (struct particule_component *)\
|
||||
component;
|
||||
gc_sprite *sprites;
|
||||
|
||||
cmp->type = va_arg(args, int);
|
||||
cmp->nb_max_particules = va_arg(args, int);
|
||||
cmp->lifetime = va_arg(args, int);
|
||||
cmp->texture = va_arg(args, void *);
|
||||
cmp->particules = malloc(sizeof(struct particule_component) * \
|
||||
(cmp->nb_max_particules + 1));
|
||||
sprites = malloc(sizeof(gc_sprite) * (cmp->nb_max_particules));
|
||||
if (!cmp->particules || !sprites)
|
||||
return;
|
||||
for (int i = 0; i < cmp->nb_max_particules; i++) {
|
||||
cmp->particules[i].sprite = &sprites[i];
|
||||
cmp->particules[i].lifetime = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void fdctr(gc_entity *entity, gc_scene *scene, \
|
||||
void *component, node *n)
|
||||
{
|
||||
struct particule_component *cmp = (struct particule_component *)\
|
||||
component;
|
||||
struct map_linker *ml = GETCMP(entity, map_linker);
|
||||
gc_sprite *sprites;
|
||||
|
||||
if (!ml) {
|
||||
my_printf("No linker\n");
|
||||
return;
|
||||
}
|
||||
cmp->type = xml_getintprop(n, "type");
|
||||
cmp->nb_max_particules = xml_getintprop(n, "nb_particules_max");
|
||||
cmp->texture = ml->tile->texture;
|
||||
cmp->lifetime = xml_getintprop(n, "lifetime");
|
||||
cmp->particules = malloc(sizeof(struct particule_component) * \
|
||||
(cmp->nb_max_particules + 1));
|
||||
sprites = malloc(sizeof(gc_sprite) * (cmp->nb_max_particules));
|
||||
if (!cmp->particules || !sprites)
|
||||
return;
|
||||
for (int i = 0; i < cmp->nb_max_particules; i++) {
|
||||
cmp->particules[i].sprite = &sprites[i];
|
||||
cmp->particules[i].lifetime = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void dtr(void *component)
|
||||
{
|
||||
struct particule_component *cmp = (struct particule_component *)\
|
||||
component;
|
||||
if (!cmp->particules)
|
||||
return;
|
||||
free(cmp->particules[0].sprite);
|
||||
free(cmp->particules);
|
||||
}
|
||||
|
||||
static char *serialize(void *component)
|
||||
{
|
||||
(void)component;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
const struct particule_component particule_component = {
|
||||
base: {
|
||||
name: "particule_component",
|
||||
size: sizeof(struct particule_component),
|
||||
dependencies: (char *[]){
|
||||
"transform_component",
|
||||
"map_linker",
|
||||
NULL
|
||||
},
|
||||
ctr: &ctr,
|
||||
fdctr: &fdctr,
|
||||
dtr: &dtr,
|
||||
serialize: &serialize,
|
||||
destroy: &component_destroy
|
||||
}
|
||||
};
|
||||
@@ -27,6 +27,8 @@
|
||||
#include "map_editor.h"
|
||||
#include "components/xp_component.h"
|
||||
#include "systems/game_over.h"
|
||||
#include "systems/particule_system.h"
|
||||
#include "components/particule_component.h"
|
||||
#include <malloc.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
@@ -144,6 +146,8 @@ int register_customcmps(gc_engine *engine, bool map_editor)
|
||||
engine->add_component(engine, &combat_holder);
|
||||
engine->add_system(engine, new_system(&combat_manager, engine));
|
||||
engine->add_component(engine, &health_component);
|
||||
engine->add_system(engine, &particule_system);
|
||||
engine->add_component(engine, &particule_component);
|
||||
engine->finish_physics(engine);
|
||||
engine->add_dataloader(engine, "enemies", &enemies_dataloader);
|
||||
for (int i = 0; callbacks[i].func; i++)
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** MUL_my_runner_2019
|
||||
** File description:
|
||||
** particule_system
|
||||
*/
|
||||
|
||||
#include "engine.h"
|
||||
#include "renderer.h"
|
||||
#include "sprite.h"
|
||||
#include "systems/sfml_renderer_system.h"
|
||||
#include "sfml_renderer.h"
|
||||
#include "components/particule_component.h"
|
||||
#include "system.h"
|
||||
|
||||
void create_particule(struct particule *particule, int lifetime, \
|
||||
void *texture, gc_vector2 pos)
|
||||
{
|
||||
if (!particule || !particule->sprite)
|
||||
return;
|
||||
particule->lifetime = lifetime;
|
||||
particule->sprite->texture = texture;
|
||||
particule->sprite->pos = pos;
|
||||
particule->sprite->rect = (gc_int_rect){10, 10,0,0};
|
||||
particule->sprite->scale = (gc_vector2){0.5, 0.5};
|
||||
}
|
||||
|
||||
void particule_draw(gc_engine *engine, void *system, \
|
||||
gc_entity *entity, float dt)
|
||||
{
|
||||
struct particule_component *pm = GETCMP(entity, particule_component);
|
||||
|
||||
if (!pm || !entity)
|
||||
return;
|
||||
for (int i = 0; i < pm->nb_max_particules; i++) {
|
||||
if (!pm->particules[i].sprite)
|
||||
continue;
|
||||
sfmlrenderer_draw_texture(engine, entity, pm->particules[i].sprite, dt);
|
||||
}
|
||||
}
|
||||
|
||||
void particule_update_entity(gc_engine *engine, void *system, gc_entity *entity, \
|
||||
float dtime)
|
||||
{
|
||||
struct map_linker *ml = GETCMP(entity, map_linker);
|
||||
struct particule_component *cmp = GETCMP(entity, particule_component);
|
||||
struct transform_component *tc = GETCMP(entity, transform_component);
|
||||
|
||||
if (!ml || !tc || !cmp)
|
||||
return;
|
||||
for (int i = 0; i < cmp->nb_max_particules; i++)
|
||||
cmp->particules[i].lifetime -= (cmp->particules[i].lifetime) ? 1 : 0;
|
||||
for (int i = 0; i < cmp->nb_max_particules; i++) {
|
||||
if (!cmp->particules[i].lifetime)
|
||||
create_particule(&cmp->particules[i], cmp->lifetime, cmp->texture, tc->position);
|
||||
}
|
||||
particule_draw(engine, system, entity, dtime);
|
||||
}
|
||||
|
||||
void particule_destroy(void *system, gc_engine *engine)
|
||||
{
|
||||
(void)system;
|
||||
}
|
||||
|
||||
const struct gc_system particule_system = {
|
||||
name: "particule_system",
|
||||
component_name: "particule_component",
|
||||
size: sizeof(gc_system),
|
||||
ctr: NULL,
|
||||
dtr: NULL,
|
||||
check_dependencies: &system_check_dependencies,
|
||||
update_entity: &particule_update_entity,
|
||||
destroy: &particule_destroy
|
||||
};
|
||||
Reference in New Issue
Block a user