36#define SIN45 0.707106781f
37#define DEG_RAD_FACTOR 0.017453293f
40 Map *map,
int rotation,
41 const std::string &dyePalettes)
67 for (
auto propertyNode : emitterNode.
children())
69 if (propertyNode.name() ==
"property")
71 std::string name = propertyNode.getProperty(
"name",
"");
73 if (name ==
"position-x")
77 else if (name ==
"position-y")
85 else if (name ==
"position-z")
92 else if (name ==
"image")
94 std::string image = propertyNode.getProperty(
"value",
"");
98 if (!dyePalettes.empty())
105 else if (name ==
"horizontal-angle")
114 else if (name ==
"vertical-angle")
121 else if (name ==
"power")
125 else if (name ==
"gravity")
129 else if (name ==
"randomnes" || name ==
"randomness")
133 else if (name ==
"bounce")
137 else if (name ==
"lifetime")
142 else if (name ==
"output")
147 else if (name ==
"output-pause")
152 else if (name ==
"acceleration")
156 else if (name ==
"die-distance")
160 else if (name ==
"momentum")
164 else if (name ==
"fade-out")
168 else if (name ==
"fade-in")
172 else if (name ==
"alpha")
176 else if (name ==
"follow-parent")
182 Log::info(
"Particle Engine: Warning, unknown emitter property \"%s\"",
186 else if (propertyNode.name() ==
"emitter")
189 rotation, dyePalettes);
192 else if (propertyNode.name() ==
"rotation")
196 else if (propertyNode.name() ==
"animation")
200 else if (propertyNode.name() ==
"deatheffect")
204 if (propertyNode.getBoolProperty(
"on-floor",
true))
208 if (propertyNode.getBoolProperty(
"on-sky",
true))
212 if (propertyNode.getBoolProperty(
"on-other",
false))
216 if (propertyNode.getBoolProperty(
"on-impact",
true))
220 if (propertyNode.getBoolProperty(
"on-timeout",
true))
279 std::string change = propertyNode.
getProperty(
"change-func",
"none");
281 int period = propertyNode.
getProperty(
"change-period", 0);
282 int phase = propertyNode.
getProperty(
"change-phase", 0);
283 if (change ==
"saw" || change ==
"sawtooth")
285 else if (change ==
"sine" || change ==
"sinewave")
287 else if (change ==
"triangle")
289 else if (change ==
"square")
298 std::list<Particle *> newParticles;
333 newParticle->
moveTo(position);
339 cos(angleH) * cos(angleV) * power,
340 sin(angleH) * cos(angleV) * power,
341 sin(angleV) * power);
369 newParticles.push_back(newParticle);
377 if (w == 0 || h == 0)
return;
382 int oldArea = oldWidth * oldHeight;
395 float outputFactor = (float)newArea / (
float)oldArea;
int getLength() const
Returns the length of this animation in frames.
static Animation fromXML(XML::Node node, const std::string &dyePalettes={})
Loads an animation from XML.
static void instantiate(std::string &target, const std::string &palettes)
Fills the blank in a dye placeholder with some palette names.
A particle that uses an image for its visualization.
Every Particle can have one or more particle emitters that create new particles when they are updated...
Particle * mParticleTarget
ParticleEmitterProp< float > mParticlePosZ
ParticleEmitterProp< int > mOutput
Number of particles spawned per update.
ParticleEmitterProp< float > mParticleAngleHorizontal
initial vector of particles:
ParticleEmitterProp< float > mParticleDieDistance
ParticleEmitterProp< int > mParticleFadeIn
std::list< ParticleEmitter > mParticleChildEmitters
List of emitters the spawned particles are equipped with.
ResourceRef< Image > mParticleImage
Particle image, if used.
char mDeathEffectConditions
ParticleEmitterProp< int > mParticleRandomness
ParticleEmitterProp< float > mParticlePower
Initial velocity of particles.
ParticleEmitterProp< int > mParticleLifetime
std::list< Particle * > createParticles(int tick)
Spawns new particles.
ParticleEmitterProp< float > mParticleAngleVertical
ParticleEmitterProp< float > mParticleAcceleration
ParticleEmitterProp< float > mParticleGravity
ParticleEmitter & operator=(const ParticleEmitter &o)
Assignment operator that calls the copy constructor.
ParticleEmitterProp< int > mParticleFadeOut
ParticleEmitterProp< float > mParticleAlpha
Opacity of the graphical representation of the particles.
Animation mParticleAnimation
Filename of particle animation file.
ParticleEmitterProp< T > readParticleEmitterProp(XML::Node propertyNode, T def)
ParticleEmitterProp< float > mParticlePosX
initial position of particles:
ParticleEmitterProp< float > mParticleBounce
Animation mParticleRotation
Filename of particle rotation file.
Map * mMap
Map the particles are spawned on.
void adjustSize(int w, int h)
Changes the size of the emitter so that the effect fills a rectangle of this size.
ParticleEmitterProp< float > mParticleMomentum
ParticleEmitter(XML::Node emitterNode, Particle *target, Map *map, int rotation=0, const std::string &dyePalettes=std::string())
ParticleEmitterProp< float > mParticlePosY
ParticleEmitterProp< int > mOutputPause
Pause in frames between two spawns.
A particle spawned by a ParticleEmitter.
void setVelocity(float x, float y, float z)
Sets the current velocity in 3 dimensional space.
void setRandomness(int r)
Sets the ammount of random vector changes.
void setAlpha(float alpha) override
Sets the alpha value used to draw the actor.
virtual void setDeathEffect(const std::string &effectFile, char conditions)
static int particleCount
Current number of particles.
static int maxCount
Maximum number of particles.
void addEmitter(ParticleEmitter *emitter)
Adds an emitter to the particle.
void setFadeIn(int fadeIn)
Sets the remaining particle lifetime where the particle starts to fade out.
void setGravity(float gravity)
Sets the downward acceleration.
void moveTo(const Vector &pos)
Sets the position in 3 dimensional space in pixels relative to map.
void setDieDistance(float dist)
Sets the distance in pixel the particle can come near the target particle before it is destroyed.
void setLifetime(int lifetime)
Sets the time in game ticks until the particle is destroyed.
void setDestination(Particle *target, float accel, float moment)
Makes the particle move toward another particle with a given acceleration and momentum.
void setBounce(float bouncieness)
Sets the ammount of velocity particles retain after hitting the ground.
void setFadeOut(int fadeOut)
Sets the age of the pixel in game ticks where the particle has faded in completely.
void setFollow(bool follow)
Sets the flag if the particle is supposed to be moved by its parent.
A class for loading and managing resources.
static ResourceManager * getInstance()
Returns an instance of the class, creating one if it does not already exist.
ResourceRef< Image > getImage(const std::string &idPath)
Loads the Image resource found at the given identifier path.
int getProperty(const char *name, int def) const
double getFloatProperty(const char *name, double def) const
Children children() const
void info(const char *log_text,...) LOG_PRINTF_ATTR
void setFunction(ChangeFunc func, T amplitude, int period, int phase)