21 : config(config), particles(maxParticles) {}
28 for (
int i = 0; i < count; ++i) {
56 if (p.age >= p.lifetime) {
63 p.position += p.velocity * deltaTime;
71 float t = p.age / p.lifetime;
77 auto r =
static_cast<Uint8
>(
80 auto g =
static_cast<Uint8
>(
83 auto b =
static_cast<Uint8
>(
86 auto a =
static_cast<Uint8
>(
91 const Color color{r, g, b, a};
95 p.position.y - size / 2.0F, size, size);
123 p.velocity =
Vec2<float>(std::cos(angle) * speed, std::sin(angle) * speed);
void draw() override
Draw alive particles.
std::vector< Particle > particles
int getAliveCount() const
Get the number of alive particles.
void setEmissionRate(float rate)
Set emission rate (particles per second), 0 to disable auto-emit.
ParticleEmitter()=default
Create a default ParticleEmitter with no particles.
void start()
Start continuous emission.
float emissionAccumulator
void emit(int count)
Emit a burst of particles at current position.
void stop()
Stop continuous emission.
void update(float deltaTime) override
Update particles.
Vec2< T > position
The position of the rectangle.
float alpha
Opacity of the object.
asw::Quad< float > transform
The transform of the object.
Routines for drawing sprites and primitives to the screen.
void stretchSprite(const asw::Texture &tex, const asw::Quad< float > &position)
Draw a sprite with the option to stretch it.
void setAlpha(const asw::Texture &texture, float alpha)
Set the alpha of a texture.
void circleFill(const asw::Vec2< float > &position, float radius, asw::Color color)
Draw a filled circle.
int between(int min, int max)
Generate a random integer between min and max.
T lerp(const T &a, const T &b, float t)
Lerp between two values.
Lightweight particle emitter system.
Random module for the ASW library.
RGBA color struct with 8-bit channels.
Configuration for particle emitters.
General utility functions.