diff --git a/game/components.h b/game/components.h index ecb0455..31a55c3 100644 --- a/game/components.h +++ b/game/components.h @@ -64,6 +64,11 @@ typedef struct ParticleEmitter { Vector2 pos; struct ParticleEmitterData { + // emission + f32 emmitRate; + f32 emmitVariance; + f32 emmitVarianceMin, emmitVarianceMax; + // offset Vector2 minOffset, maxOffset; // startVel diff --git a/game/main.c b/game/main.c index 762e20d..ef82f8b 100644 --- a/game/main.c +++ b/game/main.c @@ -567,6 +567,30 @@ static void renderGame(Game *game, float dt) { drawPlayerInputUI(); EndMode2D(); + + InputState *input = ecs_singleton_get_mut(ECS, InputState); + if (IsKeyReleased(KEY_SPACE)) { + ParticleEmitter emitter = { + .emitterLifetime = 2.0f, + .targetParticles = ecs_id(ParticleLayer1), + .data.emmitRate = 1.2f, + .data.emmitVariance = 1.0f, + .data.emmitVarianceMin = 0.0f, + .data.emmitVarianceMax = 1.0f, + .pos = input->mouseWorld, + .data.startColor = { 210, 0, 0, 210 }, + .data.endColor = { 110, 10, 10, 110 }, + .data.minLifetime = 1.0f, + .data.maxLifetime = 2.2f, + .data.minStartSize = 4.0f, + .data.maxStartSize = 6.0f, + .data.tileID = getParticleTypeTile(PARTICLE_CIRCLE), + .data.blend = BLEND_ADDITIVE + }; + ecs_entity_t e = entityCreateEmpty(); + ecs_set_ptr(ECS, e, ParticleEmitter, &emitter); + + } } void render(float dt, void *userData) { diff --git a/game/systems/s_animation.c b/game/systems/s_animation.c index 315f305..a6ba8ed 100644 --- a/game/systems/s_animation.c +++ b/game/systems/s_animation.c @@ -2,6 +2,7 @@ #include "../game_state.h" #include "../utils.h" +#include "../entity_factory.h" #include #include @@ -57,13 +58,21 @@ void updateParticleEmitter(ecs_iter_t *it) { ecs_entity_t entity = it->entities[i]; if (ecs_has(ECS, entity, EmitterAttachment)) { EmitterAttachment attachment = *ecs_get(ECS, entity, EmitterAttachment); - if (!ecs_is_alive(ECS, attachment.baseEntity)) { - ecs_delete(ECS, entity); - continue; + if (ecs_is_alive(ECS, attachment.baseEntity)) { + Vector2 pos = *ecs_get(ECS, entity, Position); + pos = Vector2Add(pos, attachment.offset); + emitter[i].pos = pos; } - Vector2 pos = *ecs_get(ECS, entity, Position); - pos = Vector2Add(pos, attachment.offset); - emitter->pos = pos; + } + + const struct ParticleEmitterData data = emitter[i].data; + + i32 emmit = data.emmitRate + data.emmitVariance * randFloatRange(data.emmitVarianceMin, data.emmitVarianceMax); + for (i32 pIdx = 0; pIdx < emmit; pIdx++) { + ecs_entity_t pEntity = entityCreateEmpty(); + ecs_set_ptr(ECS, pEntity, ParticleLayer0, NULL); + Particle particle = spawnParticle(&emitter[i]); + ecs_set_id(ECS, pEntity, emitter[i].targetParticles, sizeof(particle), &particle); } emitter[i].emitterElapsed += dt; diff --git a/game/systems/systems.c b/game/systems/systems.c index c152592..afbbc00 100644 --- a/game/systems/systems.c +++ b/game/systems/systems.c @@ -192,6 +192,8 @@ void setupSystems() { ECS_SYSTEM(ECS, renderHealthBar, EcsOnUpdate, Position, HitBox, Health); ECS_SYSTEM(ECS, renderFloatyTextParticle, EcsOnUpdate, FloatyTextParticle); + ECS_SYSTEM(ECS, updateParticleEmitter, EcsOnUpdate, ParticleEmitter); + ECS_SYSTEM(ECS, renderDebugPath, EcsOnUpdate, Path); ECS_SYSTEM(ECS, renderColliders, EcsOnUpdate, Position, HitBox);