summaryrefslogtreecommitdiff
path: root/src/being.cpp
diff options
context:
space:
mode:
authorPhilipp Sehmisch <tmw@crushnet.org>2007-05-04 13:09:25 +0000
committerPhilipp Sehmisch <tmw@crushnet.org>2007-05-04 13:09:25 +0000
commit00fb4bde7974a20aacfc1c52e48fff2faee2d385 (patch)
tree2097ef003495d7e6b4a8cf697ad7896039aac113 /src/being.cpp
parentb3376bfe4e26591e1dc1066d8f2270baf4f9f759 (diff)
downloadMana-00fb4bde7974a20aacfc1c52e48fff2faee2d385.tar.gz
Mana-00fb4bde7974a20aacfc1c52e48fff2faee2d385.tar.bz2
Mana-00fb4bde7974a20aacfc1c52e48fff2faee2d385.tar.xz
Mana-00fb4bde7974a20aacfc1c52e48fff2faee2d385.zip
Merged particle engine into main eAthena branch.
Diffstat (limited to 'src/being.cpp')
-rw-r--r--src/being.cpp98
1 files changed, 60 insertions, 38 deletions
diff --git a/src/being.cpp b/src/being.cpp
index 930c2d24..db7751bf 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -30,12 +30,16 @@
#include "graphics.h"
#include "log.h"
#include "map.h"
+#include "particle.h"
#include "resources/resourcemanager.h"
#include "resources/imageset.h"
#include "gui/gui.h"
+#include "resources/resourcemanager.h"
+#include "resources/imageset.h"
+
#include "utils/dtor.h"
#include "utils/tostring.h"
@@ -58,7 +62,6 @@ Being::Being(Uint32 id, Uint16 job, Map *map):
mHairStyle(0), mHairColor(0),
mSex(2),
mSpeechTime(0),
- mDamageTime(0),
mPx(0), mPy(0),
mSprites(VECTOREND_SPRITE, NULL),
mEquipmentSpriteIDs(VECTOREND_SPRITE, 0)
@@ -82,6 +85,13 @@ Being::~Being()
clearPath();
setMap(NULL);
+ for ( std::list<Particle *>::iterator i = mChildParticleEffects.begin();
+ i != mChildParticleEffects.end();
+ i++)
+ {
+ (*i)->kill();
+ }
+
instances--;
if (instances == 0)
@@ -154,8 +164,34 @@ Being::setSpeech(const std::string &text, Uint32 time)
void
Being::takeDamage(int amount)
{
- mDamage = amount ? toString(amount) : "miss";
- mDamageTime = 300;
+ gcn::Font* font;
+ std::string damage = amount ? toString(amount) : "miss";
+
+ // Selecting the right color
+ if (damage == "miss")
+ {
+ font = hitYellowFont;
+ }
+ else
+ {
+ // hit particle effect
+ controlParticle(particleEngine->addEffect("graphics/particles/hit.particle.xml", 0, 0));
+
+ if (getType() == MONSTER)
+ {
+ font = hitBlueFont;
+ }
+ else
+ {
+ font = hitRedFont;
+ }
+ }
+
+ // show damage number
+ particleEngine->addTextSplashEffect(damage,
+ font,
+ gcn::Color(255, 255, 255),
+ mPx + 16, mPy + 16);
}
void
@@ -182,6 +218,19 @@ Being::setMap(Map *map)
{
mSpriteIterator = mMap->addSprite(this);
}
+
+ //clear particle effect list because child particles became invalid
+ mChildParticleEffects.clear();
+}
+
+void
+Being::controlParticle(Particle *particle)
+{
+ if (particle)
+ {
+ particle->disableAutoDelete(); //the effect may not die without the beings permission or we segvault
+ mChildParticleEffects.push_back(particle);
+ }
}
void
@@ -321,10 +370,6 @@ Being::logic()
if (mSpeechTime > 0)
mSpeechTime--;
- // Reduce the time that damage is still displayed
- if (mDamageTime > 0)
- mDamageTime--;
-
// Update pixel coordinates
mPx = mX * 32 + getXOffset();
mPy = mY * 32 + getYOffset();
@@ -345,6 +390,14 @@ Being::logic()
mSprites[i]->update(tick_time * 10);
}
}
+
+ //Update particle effects
+ for ( std::list<Particle *>::iterator i = mChildParticleEffects.begin();
+ i != mChildParticleEffects.end();
+ i++)
+ {
+ (*i)->setPosition((float)mPx + 16.0f, (float)mPy + 32.0f);
+ }
}
void
@@ -387,37 +440,6 @@ Being::drawSpeech(Graphics *graphics, Sint32 offsetX, Sint32 offsetY)
graphics->setColor(gcn::Color(255, 255, 255));
graphics->drawText(mSpeech, px + 18, py - 60, gcn::Graphics::CENTER);
}
-
- // Draw damage above this being
- if (mDamageTime > 0 && mDamageTime < 275)
- {
- // Selecting the right color
- if (mDamage == "miss")
- {
- graphics->setFont(hitYellowFont);
- }
- else if (getType() == MONSTER)
- {
- graphics->setFont(hitBlueFont);
- }
- else
- {
- graphics->setFont(hitRedFont);
- }
-
- int textY = (getType() == MONSTER) ? 32 : 70;
- int ft = 150 - mDamageTime;
- float a = (ft > 0) ? 1.0 - ft / 150.0 : 1.0;
-
- graphics->setColor(gcn::Color(255, 255, 255, (int)(255 * a)));
- graphics->drawText(mDamage,
- px + 16,
- py - textY - (300 - mDamageTime) / 10,
- gcn::Graphics::CENTER);
-
- // Reset alpha value
- graphics->setColor(gcn::Color(255, 255, 255));
- }
}
Being::Type