summaryrefslogtreecommitdiff
path: root/src/being.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/being.cpp')
-rw-r--r--src/being.cpp50
1 files changed, 31 insertions, 19 deletions
diff --git a/src/being.cpp b/src/being.cpp
index 1880e7c0..dca87677 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -34,6 +34,7 @@
#include "particle.h"
#include "sound.h"
#include "localplayer.h"
+#include "text.h"
#include "resources/resourcemanager.h"
#include "resources/imageset.h"
@@ -51,6 +52,9 @@
int Being::instances = 0;
ImageSet *Being::emotionSet = NULL;
+static const int X_SPEECH_OFFSET = 18;
+static const int Y_SPEECH_OFFSET = 60;
+
Being::Being(int id, int job, Map *map):
mJob(job),
mX(0), mY(0),
@@ -83,6 +87,7 @@ Being::Being(int id, int job, Map *map):
}
instances++;
+ mSpeech = 0;
}
Being::~Being()
@@ -106,6 +111,8 @@ Being::~Being()
emotionSet->decRef();
emotionSet = NULL;
}
+
+ delete mSpeech;
}
void
@@ -153,7 +160,12 @@ Being::setSprite(int slot, int id, std::string color)
void
Being::setSpeech(const std::string &text, Uint32 time)
{
- mSpeech = text;
+ // don't introduce a memory leak
+ delete mSpeech;
+
+ mSpeech = new Text(text, mPx + X_SPEECH_OFFSET, mPy - Y_SPEECH_OFFSET,
+ gcn::Graphics::CENTER, speechFont,
+ gcn::Color(255, 255, 255));
mSpeechTime = 500;
}
@@ -361,13 +373,28 @@ void
Being::logic()
{
// Reduce the time that speech is still displayed
- if (mSpeechTime > 0)
- mSpeechTime--;
+ if (mSpeechTime > 0 && mSpeech)
+ {
+ if (--mSpeechTime == 0)
+ {
+ delete mSpeech;
+ mSpeech = 0;
+ }
+ }
+ int oldPx = mPx;
+ int oldPy = mPy;
// Update pixel coordinates
mPx = mX * 32 + getXOffset();
mPy = mY * 32 + getYOffset();
-
+ if (mPx != oldPx || mPy != oldPy)
+ {
+ if (mSpeech)
+ {
+ mSpeech->adviseXY(mPx + X_SPEECH_OFFSET, mPy - Y_SPEECH_OFFSET);
+ }
+ updateCoords();
+ }
if (mEmotion != 0)
{
mEmotionTime--;
@@ -432,21 +459,6 @@ Being::drawEmotion(Graphics *graphics, int offsetX, int offsetY)
graphics->drawImage(emotionSet->get(emotionIndex), px, py);
}
-void
-Being::drawSpeech(Graphics *graphics, int offsetX, int offsetY)
-{
- int px = mPx + offsetX;
- int py = mPy + offsetY;
-
- // Draw speech above this being
- if (mSpeechTime > 0)
- {
- graphics->setFont(speechFont);
- graphics->setColor(gcn::Color(255, 255, 255));
- graphics->drawText(mSpeech, px + 18, py - 60, gcn::Graphics::CENTER);
- }
-}
-
Being::Type
Being::getType() const
{