Dragonfly 4.20
A text-based game engine
Particle.h
1///
2/// A particle
3///
4
5#ifndef __PARTICLE_H__
6#define __PARTICLE_H__
7
8// Engine include.
9#include "Object.h"
10
11namespace df {
12
13/// Particle types.
15 UNDEFINED_PARTICLE_TYPE = -1,
16 SMOKE,
17 SPARKS,
18 RINGS,
19 FIREWORKS,
20};
21
22/// Particle classes.
24 UNDEFINED_PARTICLE_CLASS = -1,
25 PARTICLE,
26 FIREWORK,
27};
28
29/// Directions.
31 UNDEFINED_DIRECTION = -1,
32 UP,
33 DOWN,
34 LEFT,
35 RIGHT,
36};
37
38class Particle : public Object {
39
40 private:
41 int m_age; ///< Age to live (in ticks).
42
43 void init(float size, int age, unsigned char opacity,
44 unsigned char r, unsigned char g, unsigned char b);
45
46 public:
47 /// Create particle with size (pixels), age (in ticks), opacity
48 /// (0-255) and rgb color.
49 Particle(float size, int age, unsigned char opacity,
50 unsigned char r, unsigned char g, unsigned char b);
51
52 /// Create particle with size (pixels), age (in ticks), opacity
53 /// (0-255) and Dragonfly color.
54 Particle(float size, int age, unsigned char opacity, Color color);
55
56 /// Set colors.
57 void setRGB(Color color);
58 void setRGB(unsigned char r, unsigned char g, unsigned char b);
59
60 /// Set age.
61 void setAge(int new_age);
62
63 /// Get age.
64 int getAge() const;
65
66 /// Handle event (handles step to age and out delete).
67 /// Return 0 if ignored, else 1.
68 int eventHandler(const Event *p_e) override;
69
70 /// Log warning if trying to serialize particles.
71 virtual int serialize(std::stringstream *p_ss, unsigned int attr=0) override;
72
73 /// Log warning if trying to deserialize particles.
74 virtual int deserialize(std::stringstream *p_ss, unsigned int *p_a) override;
75};
76
77} // end of namespace df
78#endif //__PARTICLE_H__
Definition: Event.h:15
Definition: Object.h:57
Definition: Particle.h:38
Particle(float size, int age, unsigned char opacity, unsigned char r, unsigned char g, unsigned char b)
Create particle with size (pixels), age (in ticks), opacity (0-255) and rgb color.
void setRGB(Color color)
Set colors.
virtual int serialize(std::stringstream *p_ss, unsigned int attr=0) override
Log warning if trying to serialize particles.
void setAge(int new_age)
Set age.
int getAge() const
Get age.
int m_age
Age to live (in ticks).
Definition: Particle.h:41
int eventHandler(const Event *p_e) override
Handle event (handles step to age and out delete).
virtual int deserialize(std::stringstream *p_ss, unsigned int *p_a) override
Log warning if trying to deserialize particles.
Particle(float size, int age, unsigned char opacity, Color color)
Create particle with size (pixels), age (in ticks), opacity (0-255) and Dragonfly color.
An animation for a sprite.
Definition: Animation.h:15
Color
Colors Dragonfly recognizes.
Definition: Color.h:11
ParticleClass
Particle classes.
Definition: Particle.h:23
ParticleType
Particle types.
Definition: Particle.h:14
Direction
Directions.
Definition: Particle.h:30