mirror of
https://github.com/zoriya/ForecastingVillage.git
synced 2026-06-02 02:35:05 +00:00
adding a firecamp and it's particules adding random for particules
This commit is contained in:
+1
-1
@@ -324,7 +324,7 @@ add_executable(my_rpg
|
||||
src/npc/mage.c
|
||||
src/combat/boss.c
|
||||
src/components/combat_holder.c
|
||||
src/systems/combat_utility.c)
|
||||
src/systems/combat_utility.c src/systems/particule_methods.c)
|
||||
|
||||
add_compile_options(-W -Wall -Wextra -Wshadow)
|
||||
|
||||
|
||||
@@ -50,7 +50,8 @@ SRC = src/main.c \
|
||||
src/combat/boss.c \
|
||||
src/components/particule_component.c \
|
||||
src/systems/particule_system.c \
|
||||
src/systems/combat_utility.c
|
||||
src/systems/combat_utility.c \
|
||||
src/systems/particule_methods.c
|
||||
|
||||
OBJ = $(SRC:%.c=%.o)
|
||||
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 7.4 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 976 B |
@@ -15,6 +15,9 @@ void particule_update_entity(gc_engine *engine, void *system, \
|
||||
gc_entity *entity, float dt);
|
||||
void create_particule(struct particule *particule, int lifetime, \
|
||||
void *texture, gc_vector2 pos);
|
||||
void create_particule(struct particule *particule, int lifetime, \
|
||||
void *texture, gc_vector2 pos);
|
||||
void particule_draw(gc_engine *engine, gc_entity *entity, float dt);
|
||||
|
||||
extern const struct gc_system particule_system;
|
||||
|
||||
|
||||
@@ -122,6 +122,8 @@
|
||||
<sprite name="chest" src="assets/sprites/items/generic-rpg-treasure-closed.png" />
|
||||
|
||||
<sprite name="npc_interact" src="assets/tiles/interaction_tile.png" />
|
||||
<sprite name="firecamp" src="assets/sprites/items/firecamp.png" />
|
||||
<sprite name="smoke_particule" src="assets/sprites/items/smoke_particule.png" />
|
||||
|
||||
|
||||
<sprite name="empty_slot" src="assets/sprites/inventory/empty_48x48.png" />
|
||||
@@ -229,6 +231,18 @@
|
||||
</dialog_holder>
|
||||
</gc_entity>
|
||||
|
||||
<gc_entity>
|
||||
<transform_component>
|
||||
<Position x="0" y="0" />
|
||||
<Size x="60" y="60" />
|
||||
</transform_component>
|
||||
<renderer src="firecamp">
|
||||
<Rect height="auto" left="0" top="0" width="auto" />
|
||||
</renderer>
|
||||
<map_linker x="48" y="40" centered="true" />
|
||||
<particule_component type="2" nb_particules_max="10" lifetime="30" texture="smoke_particule" />
|
||||
</gc_entity>
|
||||
|
||||
<gc_entity>
|
||||
<transform_component>
|
||||
<Position x="0" y="0" />
|
||||
|
||||
@@ -39,6 +39,6 @@
|
||||
<xp_component xp="0"/>
|
||||
<health_component max_health="25"/>
|
||||
<player_component fight_rate="5%" />
|
||||
<particule_component type="1" nb_particules_max="15" lifetime="60" texture="stone" />
|
||||
<particule_component type="1" nb_particules_max="8" lifetime="30" texture="stone" />
|
||||
</gc_entity>
|
||||
</gc_entities>
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
** EPITECH PROJECT, 2019
|
||||
** MUL_my_runner_2019
|
||||
** File description:
|
||||
** particule_system
|
||||
*/
|
||||
|
||||
#include "engine.h"
|
||||
#include "sprite.h"
|
||||
#include "sfml_renderer.h"
|
||||
#include "components/particule_component.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
void create_particule(struct particule *particule, int lifetime, \
|
||||
void *texture, gc_vector2 pos)
|
||||
{
|
||||
if (!particule || !particule->sprite)
|
||||
return;
|
||||
pos.x += (rand() % 2) ? rand() % 20 : (rand() % 20) * -1;
|
||||
pos.y += (rand() % 2) ? rand() % 20 : (rand() % 20) * -1;
|
||||
particule->lifetime = lifetime;
|
||||
particule->sprite->texture = texture;
|
||||
particule->sprite->pos = (gc_vector2){pos.x, pos.y};
|
||||
particule->sprite->rect = (gc_int_rect){16, 16,0,0};
|
||||
particule->sprite->scale = (gc_vector2){0.1, 0.1};
|
||||
}
|
||||
|
||||
void particule_draw(gc_engine *engine, gc_entity *entity, float dt)
|
||||
{
|
||||
struct particule_component *pm = GETCMP(entity, particule_component);
|
||||
struct transform_component *tc = GETCMP(entity, transform_component);
|
||||
gc_vector2 player_pos;
|
||||
|
||||
if (!pm || !entity || !tc)
|
||||
return;
|
||||
player_pos = tc->position;
|
||||
for (int i = 0; i < pm->nb_max_particules; i++) {
|
||||
if (!pm->particules[i].sprite || !pm->particules[i].sprite->texture)
|
||||
continue;
|
||||
if (!pm->particules[i].lifetime)
|
||||
continue;
|
||||
tc->position = pm->particules[i].sprite->pos;
|
||||
sfmlrenderer_draw_texture(engine, entity, pm->particules[i].sprite, dt);
|
||||
}
|
||||
tc->position = player_pos;
|
||||
}
|
||||
@@ -7,67 +7,80 @@
|
||||
|
||||
#include "engine.h"
|
||||
#include "sprite.h"
|
||||
#include "systems/sfml_renderer_system.h"
|
||||
#include "sfml_renderer.h"
|
||||
#include "components/controllable_component.h"
|
||||
#include "components/particule_component.h"
|
||||
#include "components/map_linker.h"
|
||||
#include "systems/particule_system.h"
|
||||
#include "system.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
void create_particule(struct particule *particule, int lifetime, \
|
||||
void *texture, gc_vector2 pos)
|
||||
void update_entity_type_one(gc_engine *engine, gc_entity *entity, \
|
||||
struct particule_component *cmp, float dtime)
|
||||
{
|
||||
if (!particule || !particule->sprite)
|
||||
struct map_linker *ml = GETCMP(entity, map_linker);
|
||||
struct transform_component *tc = GETCMP(entity, transform_component);
|
||||
struct controllable_component *cc = GETCMP(entity, controllable_component);
|
||||
|
||||
if (!ml || !tc || !cmp || !cc)
|
||||
return;
|
||||
particule->lifetime = lifetime;
|
||||
particule->sprite->texture = texture;
|
||||
particule->sprite->pos = pos;
|
||||
particule->sprite->rect = (gc_int_rect){16, 16,0,0};
|
||||
particule->sprite->scale = (gc_vector2){0.2, 0.2};
|
||||
for (int i = 0; i < cmp->nb_max_particules; i++) {
|
||||
cmp->particules[i].lifetime -= (cmp->particules[i].lifetime) ? 1 : 0;
|
||||
if (!cmp->particules[i].lifetime && \
|
||||
(cc->movement_x || cc->movement_y) && \
|
||||
(!i || cmp->particules[i - 1].lifetime == cmp->lifetime - 20)) {
|
||||
create_particule(&cmp->particules[i], cmp->lifetime, \
|
||||
cmp->texture, tc->position);
|
||||
}
|
||||
}
|
||||
particule_draw(engine, entity, dtime);
|
||||
}
|
||||
|
||||
void particule_draw(gc_engine *engine, gc_entity *entity, float dt)
|
||||
void update_entity_type_two(gc_engine *engine, gc_entity *entity, \
|
||||
struct particule_component *cmp, float dtime)
|
||||
{
|
||||
struct particule_component *pm = GETCMP(entity, particule_component);
|
||||
struct map_linker *ml = GETCMP(entity, map_linker);
|
||||
struct transform_component *tc = GETCMP(entity, transform_component);
|
||||
gc_vector2 player_pos;
|
||||
gc_vector2 sprite_pos;
|
||||
|
||||
if (!pm || !entity || !tc)
|
||||
if (!ml || !tc || !cmp || !cmp->particules || !cmp->particules[0].sprite)
|
||||
return;
|
||||
player_pos = tc->position;
|
||||
for (int i = 0; i < pm->nb_max_particules; i++) {
|
||||
if (!pm->particules[i].sprite || !pm->particules[i].sprite->texture)
|
||||
continue;
|
||||
tc->position = pm->particules[i].sprite->pos;
|
||||
sfmlrenderer_draw_texture(engine, entity, pm->particules[i].sprite, dt);
|
||||
sprite_pos = (gc_vector2){tc->position.x, tc->position.y + 50};
|
||||
for (int i = 0; i < cmp->nb_max_particules; i++) {
|
||||
cmp->particules[i].lifetime -= (cmp->particules[i].lifetime) ? 1 : 0;
|
||||
cmp->particules[i].sprite->pos.y += 1;
|
||||
if (!cmp->particules[i].lifetime && \
|
||||
(!i || cmp->particules[i - 1].lifetime == cmp->lifetime - 20)) {
|
||||
create_particule(&cmp->particules[i], cmp->lifetime, \
|
||||
cmp->texture, sprite_pos);
|
||||
}
|
||||
}
|
||||
tc->position = player_pos;
|
||||
particule_draw(engine, entity, dtime);
|
||||
}
|
||||
|
||||
static void update_entity(gc_engine *engine, va_list args)
|
||||
{
|
||||
gc_entity *entity = va_arg(args, gc_entity *);
|
||||
float dtime = va_arg(args, double);
|
||||
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)
|
||||
if (!cmp)
|
||||
return;
|
||||
//ml->tile->texture
|
||||
for (int i = 0; i < cmp->nb_max_particules; i++) {
|
||||
cmp->particules[i].lifetime -= (cmp->particules[i].lifetime) ? 1 : 0;
|
||||
if (!cmp->particules[i].lifetime) {
|
||||
create_particule(&cmp->particules[i], cmp->lifetime, cmp->texture, tc->position);
|
||||
}
|
||||
switch (cmp->type) {
|
||||
case 1:
|
||||
return (update_entity_type_one(engine, entity, cmp, dtime));
|
||||
case 2:
|
||||
return (update_entity_type_two(engine, entity, cmp, dtime));
|
||||
default:
|
||||
break;
|
||||
}
|
||||
particule_draw(engine, entity, dtime);
|
||||
}
|
||||
|
||||
void ctr(void *system, va_list args)
|
||||
{
|
||||
gc_engine *engine = va_arg(args, gc_engine *);
|
||||
|
||||
engine->add_event_listener(engine, "linked_entity_draw",&update_entity);
|
||||
engine->add_event_listener(engine, "linked_entity_draw", &update_entity);
|
||||
}
|
||||
|
||||
const struct gc_system particule_system = {
|
||||
|
||||
Reference in New Issue
Block a user