summaryrefslogtreecommitdiff
path: root/src/monster.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/monster.cpp')
-rw-r--r--src/monster.cpp45
1 files changed, 43 insertions, 2 deletions
diff --git a/src/monster.cpp b/src/monster.cpp
index e2a07e86..bea37b3f 100644
--- a/src/monster.cpp
+++ b/src/monster.cpp
@@ -27,14 +27,21 @@
#include "game.h"
#include "sound.h"
#include "particle.h"
+#include "text.h"
+#include "localplayer.h"
+
+#include "gui/gui.h"
#include "resources/monsterdb.h"
#include "utils/tostring.h"
+static const int NAME_X_OFFSET = 16;
+static const int NAME_Y_OFFSET = 16;
Monster::Monster(Uint32 id, Uint16 job, Map *map):
- Being(id, job, map)
+ Being(id, job, map),
+ mText(0)
{
const MonsterInfo& info = MonsterDB::get(job - 1002);
@@ -59,6 +66,14 @@ Monster::Monster(Uint32 id, Uint16 job, Map *map):
}
}
+Monster::~Monster()
+{
+ if (mText)
+ {
+ player_node->setTarget(0);
+ }
+}
+
void
Monster::logic()
{
@@ -120,7 +135,8 @@ Monster::handleAttack(Being *victim, int damage)
Being::handleAttack(victim, damage);
const MonsterInfo &mi = getInfo();
- sound.playSfx(mi.getSound((damage > 0) ? MONSTER_EVENT_HIT : MONSTER_EVENT_MISS));
+ sound.playSfx(mi.getSound((damage > 0) ?
+ MONSTER_EVENT_HIT : MONSTER_EVENT_MISS));
}
void
@@ -141,3 +157,28 @@ Monster::getInfo() const
{
return MonsterDB::get(mJob - 1002);
}
+
+void Monster::showName(bool show)
+{
+ delete mText;
+ if (show)
+ {
+ mText = new Text(getInfo().getName(), mPx + NAME_X_OFFSET,
+ mPy + NAME_Y_OFFSET - getHeight(),
+ gcn::Graphics::CENTER,
+ speechFont, gcn::Color(255, 32, 32));
+ }
+ else
+ {
+ mText = 0;
+ }
+}
+
+void Monster::updateCoords()
+{
+ if (mText)
+ {
+ mText->adviseXY(mPx + NAME_X_OFFSET,
+ mPy + NAME_Y_OFFSET - getHeight());
+ }
+}