diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/being.cpp | 17 | ||||
-rw-r--r-- | src/being.h | 8 | ||||
-rw-r--r-- | src/monster.cpp | 20 | ||||
-rw-r--r-- | src/npc.cpp | 14 |
4 files changed, 29 insertions, 30 deletions
diff --git a/src/being.cpp b/src/being.cpp index 3570fe30..9a0e6d2f 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -22,15 +22,12 @@ */ #include "being.h" -#include <algorithm> #include <sstream> #include "game.h" #include "graphics.h" #include "log.h" #include "map.h" -#include "monster.h" -#include "player.h" #include "graphic/spriteset.h" @@ -58,7 +55,8 @@ Being::Being(Uint32 id, Uint16 job, Map *map): hairStyle(1), hairColor(1), speech_time(0), damage_time(0), - showSpeech(false), showDamage(false) + showSpeech(false), showDamage(false), + mSpriteset(NULL), mSpriteFrame(0) { setMap(map); } @@ -217,6 +215,17 @@ Being::logic() } } +void Being::draw(Graphics *graphics, int offsetX, int offsetY) +{ + if (!mSpriteset) + return; + + int px = mPx + offsetX; + int py = mPy + offsetY; + + graphics->drawImage(mSpriteset->spriteset[mSpriteFrame], px, py); +} + void Being::drawEmotion(Graphics *graphics, Sint32 offsetX, Sint32 offsetY) { diff --git a/src/being.h b/src/being.h index edc25c09..9b6596e5 100644 --- a/src/being.h +++ b/src/being.h @@ -36,6 +36,7 @@ class Map; class Graphics; +class Spriteset; struct PATH_NODE { @@ -260,8 +261,8 @@ class Being : public Sprite * * @see Sprite::draw(Graphics, int, int) */ - void - draw(Graphics *graphics, Sint32 offsetX, Sint32 offsetY) {}; + virtual void + draw(Graphics *graphics, Sint32 offsetX, Sint32 offsetY); /** * Returns the pixel X coordinate. @@ -311,6 +312,9 @@ class Being : public Sprite Uint32 damage_time; bool showSpeech, showDamage; Sint32 mPx, mPy; /**< Pixel coordinates */ + + Spriteset *mSpriteset; + int mSpriteFrame; }; #endif diff --git a/src/monster.cpp b/src/monster.cpp index f3b58d46..f07f7447 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -26,13 +26,11 @@ #include <sstream> #include "game.h" -#include "graphics.h" #include "log.h" -#include "graphic/spriteset.h" - #include "resources/resourcemanager.h" +class Spriteset; extern std::map<int, Spriteset*> monsterset; Monster::Monster(Uint32 id, Uint16 job, Map *map): @@ -54,6 +52,7 @@ Monster::Monster(Uint32 id, Uint16 job, Map *map): monsterset[job - 1002] = tmp; } } + mSpriteset = monsterset[job-1002]; } void Monster::logic() @@ -78,24 +77,17 @@ Being::Type Monster::getType() const void Monster::draw(Graphics *graphics, int offsetX, int offsetY) { - unsigned char dir = direction / 2; - int px = mPx + offsetX; - int py = mPy + offsetY; - int frame; - if (mFrame >= 4) { mFrame = 3; } - frame = action; + mSpriteFrame = action; if (action != MONSTER_DEAD) { - frame += mFrame; + mSpriteFrame += mFrame; } - graphics->drawImage( - monsterset[job-1002]->spriteset[dir + 4 * frame], - px - 12, py - 25); + mSpriteFrame = direction / 2 + 4 * mSpriteFrame; - Being::draw(graphics, offsetX, offsetY); + Being::draw(graphics, offsetX - 12, offsetY - 25); } diff --git a/src/npc.cpp b/src/npc.cpp index fd894969..9712a06d 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -23,13 +23,10 @@ #include "npc.h" -#include "graphics.h" - -#include "graphic/spriteset.h" - #include "net/messageout.h" #include "net/protocol.h" +class Spriteset; extern Spriteset *npcset; NPC *current_npc = 0; @@ -37,6 +34,8 @@ NPC *current_npc = 0; NPC::NPC(Uint32 id, Uint16 job, Map *map, Network *network): Being(id, job, map), mNetwork(network) { + mSpriteset = npcset; + mSpriteFrame = job-100; } Being::Type NPC::getType() const @@ -46,12 +45,7 @@ Being::Type NPC::getType() const void NPC::draw(Graphics *graphics, int offsetX, int offsetY) { - int px = mPx + offsetX; - int py = mPy + offsetY; - - graphics->drawImage(npcset->spriteset[job - 100], px - 8, py - 52); - - Being::draw(graphics, offsetX, offsetY); + Being::draw(graphics, offsetX - 8, offsetY - 52); } void NPC::talk() |