RogueLife/src/comp/particle.h

71 lines
1.9 KiB
C

//---
// particle: Lightweight, standalone component for particles
//
// This component if for basic visual particles with simple rendering. The
// particles can carry extra data and might be rendered above the rest of the
// scene.
//---
#pragma once
#include "comp/entity.h"
#include "fixed.h"
/* Particle types */
enum {
PARTICLE_GENERIC = 0,
PARTICLE_DAMAGE,
PARTICLE_DASH,
PARTICLE_HPBAR,
PARTICLE_BUFF,
};
typedef struct
{
/* Type of particle */
uint8_t type;
/* Plane of rendering */
uint8_t plane;
/* Whether the particle's position is bound to an entity, or absolute */
bool bound_to_entity;
/* Location on screen and in the air */
union {
struct { fixed_t x, y; };
entity_t *bound_entity;
};
fixed_t z;
/* Age (milliseconds) */
int age;
/* 8 bytes of data */
union {
/* Generic particles or with a lot of extra data */
struct { void *data1, *data2; } GENERIC;
/* PARTICLE_DAMAGE: Value and color (can be C_WHITE or C_RED only) */
struct { int damage; uint16_t color; } DAMAGE;
/* PARTICLE_DASH: No extra data */
/* PARTICLE_HPBAR: Pointer to entity */
struct { entity_t *entity; } HPBAR;
/* PARTICLE_BUFF: Buff animation */
struct { uint16_t color; } BUFF;
};
} particle_t;
/* Make a damage particle for the specified target */
entity_t *particle_make_damage(entity_t *target, int damage, int color);
/* Make a dashing particle at the specified target's position */
entity_t *particle_make_dash(entity_t *target);
/* Make a buff particle of the specified color bound to the specified target */
entity_t *particle_make_buff(entity_t *target, int color);
/* Update time and layout for a particle (type-generic). */
bool particle_update(particle_t *p, fixed_t dt);
/* Render a particle through the map and camera. */
void particle_render(int x, int y, particle_t const *p);