Creating different system types

Let's add a new type of particle system in addition to our current one that doesn't move. Let's call it Moving and our previous one, Static. To differentiate between the two, let's add an enum:

enum ParticleType 
{
PS_Static,
PS_Moving
};

We can now modify the original ParticleComponent class, by removing the previously created variables and instead including a reference to the kind of ParticleSystem we wish to use:

class ParticleComponent : public M5Component 
{
public:
ParticleComponent();
virtual void Update(float dt);
virtual M5Component* Clone(void);
virtual void FromFile(M5IniFile& iniFile);
bool activated;
float lifeLeft;

private:
ParticleType particleType;
};

The ParticleComponent class acts as our extrinsic state, holding information about how much time it has left and the properties from the M5Component class, such as a reference to the object we want to create.

At this point, we need to create two classes to refer to each of these:

class StaticParticleSystem : public ParticleSystem 
{
void Init(M5Object * obj);

void Update(M5Object *, float, float);

};

class MovingParticleSystem : public ParticleSystem
{
void Init(M5Object * obj);

void Update(M5Object *, float, float);

};
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.14.132