diff options
Diffstat (limited to 'src/monster.cpp')
-rw-r--r-- | src/monster.cpp | 86 |
1 files changed, 54 insertions, 32 deletions
diff --git a/src/monster.cpp b/src/monster.cpp index 8666fe26..04624b8c 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -19,14 +19,13 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "monster.h" - #include "animatedsprite.h" #include "game.h" -#include "sound.h" +#include "localplayer.h" +#include "monster.h" #include "particle.h" +#include "sound.h" #include "text.h" -#include "localplayer.h" #include "gui/gui.h" @@ -46,6 +45,7 @@ Monster::Monster(Uint32 id, Uint16 job, Map *map): // Setup Monster sprites int c = BASE_SPRITE; const std::list<std::string> &sprites = info.getSprites(); + for (std::list<std::string>::const_iterator i = sprites.begin(); i != sprites.end(); i++) @@ -63,26 +63,28 @@ Monster::Monster(Uint32 id, Uint16 job, Map *map): mSprites[c] = AnimatedSprite::load("graphics/sprites/error.xml"); } - const std::list<std::string> &particleEffects = info.getParticleEffects(); - for ( std::list<std::string>::const_iterator i = particleEffects.begin(); - i != particleEffects.end(); - i++ - ) + if (mParticleEffects) { - controlParticle(particleEngine->addEffect((*i), 0, 0)); + const std::list<std::string> &particleEffects = info.getParticleEffects(); + for ( std::list<std::string>::const_iterator i = particleEffects.begin(); + i != particleEffects.end(); i++ + ) + { + controlParticle(particleEngine->addEffect((*i), 0, 0)); + } } } -Monster::~Monster() +Monster::~Monster() { if (mText) { - player_node->setTarget(0); + delete mText; + player_node->setTarget(NULL); } } -void -Monster::logic() +void Monster::logic() { if (mAction != STAND) { @@ -97,16 +99,16 @@ Monster::logic() Being::logic(); } -Being::Type -Monster::getType() const +Being::Type Monster::getType() const { return MONSTER; } -void -Monster::setAction(Uint8 action) +void Monster::setAction(Action action) { SpriteAction currentAction = ACTION_INVALID; + int rotation = 0; + std::string particleEffect; switch (action) { @@ -120,13 +122,34 @@ Monster::setAction(Uint8 action) case ATTACK: currentAction = ACTION_ATTACK; mSprites[BASE_SPRITE]->reset(); + + //attack particle effect + particleEffect = getInfo().getAttackParticleEffect(); + if (particleEffect != "" && mParticleEffects) + { + switch (mDirection) + { + case DOWN: rotation = 0; break; + case LEFT: rotation = 90; break; + case UP: rotation = 180; break; + case RIGHT: rotation = 270; break; + default: break; + } + Particle *p; + p = particleEngine->addEffect( + particleEffect, 0, 0, rotation); + controlParticle(p); + } break; case STAND: - currentAction = ACTION_STAND; - break; + currentAction = ACTION_STAND; + break; case HURT: - // Not implemented yet - break; + // Not implemented yet + break; + case SIT: + // Also not implemented yet + break; } if (currentAction != ACTION_INVALID) @@ -142,8 +165,7 @@ Monster::setAction(Uint8 action) } } -void -Monster::handleAttack(Being *victim, int damage) +void Monster::handleAttack(Being *victim, int damage) { Being::handleAttack(victim, damage); @@ -152,34 +174,34 @@ Monster::handleAttack(Being *victim, int damage) MONSTER_EVENT_HIT : MONSTER_EVENT_MISS)); } -void -Monster::takeDamage(int amount) +void Monster::takeDamage(int amount) { if (amount > 0) sound.playSfx(getInfo().getSound(MONSTER_EVENT_HURT)); Being::takeDamage(amount); } -Being::TargetCursorSize -Monster::getTargetCursorSize() const +Being::TargetCursorSize Monster::getTargetCursorSize() const { return getInfo().getTargetCursorSize(); } -const MonsterInfo& -Monster::getInfo() const +const MonsterInfo& Monster::getInfo() const { return MonsterDB::get(mJob - 1002); } void Monster::showName(bool show) { - delete mText; + if (mText) + { + 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)); + mobNameFont, gcn::Color(255, 32, 32)); } else { |