Add Floaty text particles
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
#include <stdio.h>
|
||||
#include "systems.h"
|
||||
|
||||
#include "../game_state.h"
|
||||
#include "../sounds.h"
|
||||
#include "../utils.h"
|
||||
#include "../entity_factory.h"
|
||||
|
||||
void damageEvent(ecs_entity_t entity, DamageEvent event) {
|
||||
BZ_ASSERT(ecs_has(ECS, entity, Health));
|
||||
@@ -9,6 +12,24 @@ void damageEvent(ecs_entity_t entity, DamageEvent event) {
|
||||
Health *health = ecs_get_mut(ECS, entity, Health);
|
||||
health->hp -= event.amount;
|
||||
|
||||
Vector2 pos = {
|
||||
event.hitbox.x + event.hitbox.width * 0.5f + randFloatRange(-2, 2),
|
||||
event.hitbox.y + randFloatRange(2, 4)
|
||||
};
|
||||
|
||||
FloatyTextParticle floatyText = {
|
||||
.pos = pos,
|
||||
.speed = { randFloatRange(-12, 12), -randFloatRange(26, 32) },
|
||||
.color = {255, 0, 0, 255},
|
||||
.targetColor = {255, 0, 0, GetRandomValue(60, 120)},
|
||||
.txtSize = 6.5f,
|
||||
.duration = randFloatRange(0.3, 0.68f),
|
||||
.elapsed = 0
|
||||
};
|
||||
snprintf(floatyText.text, sizeof(floatyText.text), "-%.1f", event.amount);
|
||||
ecs_entity_t floaty = entityCreateEmpty();
|
||||
ecs_set_ptr(ECS, floaty, FloatyTextParticle, &floatyText);
|
||||
|
||||
bool hasAnimation = ecs_has(ECS, entity, Animation);
|
||||
if (hasAnimation && health->hp > 0) {
|
||||
// Still alive, just play hurt anim
|
||||
|
||||
Reference in New Issue
Block a user