diff options
Diffstat (limited to 'src/particle.cpp')
-rw-r--r-- | src/particle.cpp | 54 |
1 files changed, 36 insertions, 18 deletions
diff --git a/src/particle.cpp b/src/particle.cpp index c6e242bd..f021f6e5 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -1,34 +1,35 @@ /* * The Mana World - * Copyright 2006 The Mana World Development Team + * Copyright (C) 2006 The Mana World Development Team * * This file is part of The Mana World. * - * The Mana World is free software; you can redistribute it and/or modify + * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * any later version. * - * The Mana World is distributed in the hope that it will be useful, + * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with The Mana World; if not, write to the Free Software + * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <algorithm> #include <cmath> -#include "particle.h" +#include <guichan/color.hpp> #include "animationparticle.h" #include "configuration.h" #include "imageparticle.h" #include "log.h" #include "map.h" +#include "particle.h" #include "particleemitter.h" #include "textparticle.h" @@ -188,13 +189,13 @@ bool Particle::update() e++ ) { - Particles newParticles = (*e)->createParticles(); + Particles newParticles = (*e)->createParticles(mLifetimePast); for ( ParticleIterator p = newParticles.begin(); p != newParticles.end(); p++ ) { - (*p)->moveBy(mPos.x, mPos.y, mPos.z); + (*p)->moveBy(mPos); mChildParticles.push_back (*p); } } @@ -231,6 +232,25 @@ bool Particle::update() return true; } +void Particle::moveBy(const Vector &change) +{ + mPos += change; + for (ParticleIterator p = mChildParticles.begin(); + p != mChildParticles.end(); + p++) + { + if ((*p)->doesFollow()) + { + (*p)->moveBy(change); + } + } +} + +void Particle::moveTo(float x, float y) +{ + moveTo(Vector(x, y, mPos.z)); +} + Particle *Particle::addEffect(const std::string &particleEffectFile, int pixelX, int pixelY, int rotation) { @@ -276,17 +296,15 @@ Particle *Particle::addEffect(const std::string &particleEffectFile, } // Read and set the basic properties of the particle - int offsetX = XML::getProperty(effectChildNode, "position-x", 0); - int offsetY = XML::getProperty(effectChildNode, "position-y", 0); - int offsetZ = XML::getProperty(effectChildNode, "position-z", 0); - - int particleX = (int) mPos.x + pixelX + offsetX; - int particleY = (int) mPos.y + pixelY + offsetY; - int particleZ = (int) mPos.z + offsetZ; + float offsetX = XML::getFloatProperty(effectChildNode, "position-x", 0); + float offsetY = XML::getFloatProperty(effectChildNode, "position-y", 0); + float offsetZ = XML::getFloatProperty(effectChildNode, "position-z", 0); + Vector position (mPos.x + (float)pixelX + offsetX, + mPos.y + (float)pixelY + offsetY, + mPos.z + offsetZ); + newParticle->moveTo(position); int lifetime = XML::getProperty(effectChildNode, "lifetime", -1); - - newParticle->setPosition(particleX, particleY, particleZ); newParticle->setLifetime(lifetime); // Look for additional emitters for this particle @@ -312,7 +330,7 @@ Particle *Particle::addTextSplashEffect(const std::string &text, { Particle *newParticle = new TextParticle(mMap, text, colorR, colorG, colorB, font); - newParticle->setPosition(x, y, 0); + newParticle->moveTo(x, y); newParticle->setVelocity(((rand() % 100) - 50) / 200.0f, // X ((rand() % 100) - 50) / 200.0f, // Y ((rand() % 100) / 200.0f) + 4.0f); // Z @@ -332,7 +350,7 @@ Particle *Particle::addTextRiseFadeOutEffect(const std::string &text, int x, int y) { Particle *newParticle = new TextParticle(mMap, text, colorR, colorG, colorB, font); - newParticle->setPosition(x, y, 0); + newParticle->moveTo(x, y); newParticle->setVelocity(0.0f, 0.0f, 0.5f); newParticle->setGravity(0.0015f); newParticle->setLifetime(300); |