Add Floaty text particles
This commit is contained in:
@@ -6,6 +6,49 @@
|
||||
#include <raymath.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static inline int lerpInt(int start, int end, f32 alpha)
|
||||
{
|
||||
float result = start + alpha * (end - start);
|
||||
return result;
|
||||
}
|
||||
static inline Color lerpColor(Color start, Color end, f32 alpha) {
|
||||
return (Color) {
|
||||
.r = lerpInt(start.r, end.r, alpha),
|
||||
.g = lerpInt(start.g, end.g, alpha),
|
||||
.b = lerpInt(start.b, end.b, alpha),
|
||||
.a = lerpInt(start.a, end.a, alpha),
|
||||
};
|
||||
}
|
||||
|
||||
void renderFloatyTextParticle(ecs_iter_t *it) {
|
||||
Game *game = ecs_singleton_get_mut(ECS, Game);
|
||||
FloatyTextParticle *floaty = ecs_field(it, FloatyTextParticle, 1);
|
||||
f32 dt = GetFrameTime();
|
||||
|
||||
for (i32 i = 0; i < it->count; i++) {
|
||||
ecs_entity_t entity = it->entities[i];
|
||||
|
||||
f32 alpha = floaty[i].elapsed / floaty[i].duration;
|
||||
Color color = lerpColor(floaty[i].color, floaty[i].targetColor, alpha);
|
||||
Font font = game->font;
|
||||
// Shadow
|
||||
Vector2 shadowPos = floaty[i].pos;
|
||||
shadowPos.x += 0.4f;
|
||||
shadowPos.y += 0.4f;
|
||||
Color shadowColor = DARKGRAY;
|
||||
shadowColor.a = color.a;
|
||||
DrawTextEx(font, floaty[i].text, shadowPos, floaty[i].txtSize, 1.0f, shadowColor);
|
||||
DrawTextEx(font, floaty[i].text, floaty[i].pos, floaty[i].txtSize, 1.0f, color);
|
||||
|
||||
// pos += speed * dt
|
||||
floaty[i].pos = Vector2Add(floaty[i].pos, Vector2Scale(floaty[i].speed, dt));
|
||||
|
||||
floaty[i].elapsed += dt;
|
||||
if (floaty[i].elapsed >= floaty[i].duration)
|
||||
ecs_delete(ECS, entity);
|
||||
}
|
||||
}
|
||||
|
||||
void updateParticleEmitter(ecs_iter_t *it) {
|
||||
ParticleEmitter *emitter = ecs_field(it, ParticleEmitter, 1);
|
||||
f32 dt = GetFrameTime();
|
||||
@@ -29,12 +72,6 @@ void updateParticleEmitter(ecs_iter_t *it) {
|
||||
}
|
||||
}
|
||||
|
||||
static inline int lerpInt(int start, int end, int amount)
|
||||
{
|
||||
float result = start + amount*(end - start);
|
||||
|
||||
return result;
|
||||
}
|
||||
bool updateParticle(const Texture2D tex, Particle *particle, f32 dt) {
|
||||
f32 alpha = particle->elapsed / particle->lifetime;
|
||||
|
||||
@@ -43,12 +80,7 @@ bool updateParticle(const Texture2D tex, Particle *particle, f32 dt) {
|
||||
f32 rot = Lerp(particle->startRotSpeed, particle->endRotSpeed, alpha);
|
||||
Color startC = particle->startColor;
|
||||
Color endC = particle->endColor;
|
||||
Color color = {
|
||||
.r = lerpInt(startC.r, endC.r, alpha),
|
||||
.g = lerpInt(startC.g, endC.g, alpha),
|
||||
.b = lerpInt(startC.b, endC.b, alpha),
|
||||
.a = lerpInt(startC.a, endC.a, alpha)
|
||||
};
|
||||
Color color = lerpColor(startC, endC, alpha);
|
||||
|
||||
BeginBlendMode(particle->blend);
|
||||
f32 hSize = size * 0.5f;
|
||||
|
||||
Reference in New Issue
Block a user