ASW Lib
A.D.S. Games SDL Wrapper Library. A library targeted at Allegro4 users who want to switch to SDL3 and use modern c++.
Loading...
Searching...
No Matches
particles.h
Go to the documentation of this file.
1
8
9#ifndef ASW_PARTICLES_H
10#define ASW_PARTICLES_H
11
12#include <vector>
13
14#include "./color.h"
15#include "./game.h"
16#include "./geometry.h"
17#include "./types.h"
18
19namespace asw {
20
24 // Lifetime in seconds
25 float lifetimeMin{1.0F};
26 float lifetimeMax{2.0F};
27
28 // Speed in pixels per second
29 float speedMin{50.0F};
30 float speedMax{100.0F};
31
32 // Direction (radians)
33 float angleMin{0.0F};
34 float angleMax{6.2832F}; // Full circle
35
36 // Visual
37 Color colorStart{255, 255, 255, 255};
38 Color colorEnd{255, 255, 255, 0};
39 float alphaStart{1.0F};
40 float alphaEnd{0.0F};
41 float sizeStart{4.0F};
42 float sizeEnd{1.0F};
43
44 // Physics in pixels per second squared
45 Vec2<float> gravity{0.0F, 0.0F};
46
47 // Optional texture (nullptr = use circleFill)
48 Texture texture{nullptr};
49 };
50
54 public:
57 ParticleEmitter() = default;
58
65 int maxParticles = 256);
66
71 void setEmissionRate(float rate);
72
77 void emit(int count);
78
81 void start();
82
85 void stop();
86
91 void update(float deltaTime) override;
92
95 void draw() override;
96
101 int getAliveCount() const;
102
103 private:
104 struct Particle {
107 float lifetime{0.0F};
108 float age{0.0F};
109 float size{0.0F};
110 float rotation{0.0F};
111 bool alive{false};
112 };
113
114 void spawnParticle();
115
117 std::vector<Particle> particles;
119
120 // Emission rate in particles per second
121 float emissionRate{0.0F};
123 bool emitting{false};
124 };
125
126} // namespace asw
127
128#endif // ASW_PARTICLES_H
Particle emitter that integrates with the scene system.
Definition particles.h:53
void draw() override
Draw alive particles.
Definition particles.cpp:68
std::vector< Particle > particles
Definition particles.h:117
ParticleConfig config
Definition particles.h:116
int getAliveCount() const
Get the number of alive particles.
void setEmissionRate(float rate)
Set emission rate (particles per second), 0 to disable auto-emit.
Definition particles.cpp:23
ParticleEmitter()=default
Create a default ParticleEmitter with no particles.
void start()
Start continuous emission.
Definition particles.cpp:33
void emit(int count)
Emit a burst of particles at current position.
Definition particles.cpp:27
void stop()
Stop continuous emission.
Definition particles.cpp:37
void update(float deltaTime) override
Update particles.
Definition particles.cpp:41
A 2D vector in space.
Definition geometry.h:22
Game Object.
Definition game.h:42
Common geometry types.
std::shared_ptr< SDL_Texture > Texture
Alias for a shared pointer to an SDL_Texture.
Definition types.h:31
RGBA color struct with 8-bit channels.
Definition color.h:11
Configuration for particle emitters.
Definition particles.h:23
Vec2< float > gravity
Definition particles.h:45
Types used throughout the ASW library.