diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-10-09 16:27:05 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2005-10-09 16:27:05 +0000 |
commit | 2327c5a7c3b054e52b69286da906f8e5c4432d1c (patch) | |
tree | 28a566d4d54b8c046b18f18c1fb592c31f83f5dd /src | |
parent | ff4d98eeee5a5a799039549c6df885a5208b792f (diff) | |
download | mana-2327c5a7c3b054e52b69286da906f8e5c4432d1c.tar.gz mana-2327c5a7c3b054e52b69286da906f8e5c4432d1c.tar.bz2 mana-2327c5a7c3b054e52b69286da906f8e5c4432d1c.tar.xz mana-2327c5a7c3b054e52b69286da906f8e5c4432d1c.zip |
Fixed player names overlapping other players and more cleanups.
Diffstat (limited to 'src')
-rw-r--r-- | src/being.cpp | 83 | ||||
-rw-r--r-- | src/being.h | 62 | ||||
-rw-r--r-- | src/engine.cpp | 54 | ||||
-rwxr-xr-x | src/floor_item.cpp | 1 | ||||
-rwxr-xr-x | src/floor_item.h | 2 | ||||
-rw-r--r-- | src/game.cpp | 7 | ||||
-rw-r--r-- | src/item.h | 8 | ||||
-rw-r--r-- | src/map.cpp | 2 |
8 files changed, 78 insertions, 141 deletions
diff --git a/src/being.cpp b/src/being.cpp index 9dccb5f6..72ccd2ad 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -56,7 +56,7 @@ extern Spriteset *weaponset; Being *player_node = NULL; -std::list<Being*> beings; +Beings beings; char hairtable[16][4][2] = { // S(x,y) W(x,y) N(x,y) E(x,y) @@ -131,8 +131,8 @@ void remove_node(Being *being) Being *findNode(Uint32 id) { - std::list<Being*>::iterator i; - for (i = beings.begin(); i != beings.end(); i++) { + for (Beings::iterator i = beings.begin(); i != beings.end(); i++) + { Being *being = (*i); if (being->getId() == id) { return being; @@ -143,8 +143,8 @@ Being *findNode(Uint32 id) Being *findNode(Uint16 x, Uint16 y) { - std::list<Being*>::iterator i; - for (i = beings.begin(); i != beings.end(); i++) { + for (Beings::iterator i = beings.begin(); i != beings.end(); i++) + { Being *being = (*i); // Return being if found and it is not a dead monster if (being->x == x && @@ -160,8 +160,8 @@ Being *findNode(Uint16 x, Uint16 y) Being* findNode(Uint16 x, Uint16 y, Being::Type type) { - std::list<Being *>::iterator i; - for (i = beings.begin(); i != beings.end(); i++) { + for (Beings::iterator i = beings.begin(); i != beings.end(); i++) + { Being *being = (*i); // Check if is a NPC (only low job ids) if (being->x == x && @@ -176,28 +176,17 @@ Being* findNode(Uint16 x, Uint16 y, Being::Type type) return NULL; } -class BeingCompare { - public: - bool operator() (const Being *a, const Being *b) const { - return a->y < b->y; - } -}; - -void sort() { - beings.sort(BeingCompare()); -} - Being::Being(): job(0), x(0), y(0), direction(SOUTH), action(0), mFrame(0), speech_color(0), walk_time(0), - speed(150), emotion(0), emotion_time(0), aspd(350), - mWeapon(0), mId(0), + mWeapon(0), + mWalkSpeed(150), mMap(NULL), hairStyle(1), hairColor(1), speech_time(0), @@ -332,7 +321,7 @@ void Being::nextStep() x = node.x; y = node.y; action = WALK; - walk_time += speed / 10; + walk_time += mWalkSpeed / 10; } void Being::logic() @@ -354,7 +343,7 @@ void Being::logic() { switch (action) { case WALK: - mFrame = (get_elapsed_time(walk_time) * 4) / speed; + mFrame = (get_elapsed_time(walk_time) * 4) / mWalkSpeed; if (mFrame >= 4) { nextStep(); } @@ -379,6 +368,19 @@ void Being::logic() } } + if (getType() == MONSTER) + { + if (action != STAND) + { + mFrame = (get_elapsed_time(walk_time) * 4) / mWalkSpeed; + + if (mFrame >= 4 && action != MONSTER_DEAD) + { + nextStep(); + } + } + } + // Update pixel coordinates mPx = x * 32; mPy = y * 32; @@ -436,13 +438,6 @@ void Being::drawSpeech(Graphics *graphics, Sint32 offsetX, Sint32 offsetY) graphics->drawText("[TARGET]", px + 15, py - dy, gcn::Graphics::CENTER); } - - // Draw player name - if (getType() == PLAYER && this != player_node) - { - graphics->setFont(speechFont); - graphics->drawText(mName, px + 15, py + 30, gcn::Graphics::CENTER); - } } Being::Type Being::getType() const @@ -497,7 +492,7 @@ Being::getXOffset() const { if (direction != NORTH && direction != SOUTH) { - offset = (get_elapsed_time(walk_time) * 32) / speed; + offset = (get_elapsed_time(walk_time) * 32) / mWalkSpeed; if (offset > 32) offset = 32; if (direction == WEST || direction == NW || direction == SW) { @@ -522,7 +517,7 @@ Being::getYOffset() const { if (direction != EAST && direction != WEST) { - offset = (get_elapsed_time(walk_time) * 32) / speed; + offset = (get_elapsed_time(walk_time) * 32) / mWalkSpeed; if (offset > 32) offset = 32; if (direction == NORTH || direction == NW || direction == NE) { @@ -599,43 +594,37 @@ Being::draw(Graphics *graphics, int offsetX, int offsetY) mFrame = 3; } - px -= 42; - py -= 65; - frame = mFrame + action; if (action == MONSTER_DEAD) { graphics->drawImage( monsterset[job - 1002]->spriteset[dir + 4 * MONSTER_DEAD], - px + 30, py + 40); + px - 12, py - 25); } else { graphics->drawImage( monsterset[job-1002]->spriteset[dir + 4 * frame], - px + 30, py + 40); + px - 12, py - 25); /* if (x == mouseTileX && y == mouseTileY) { - graphics->drawImage(attackTarget, px + 30 + 16, py + 32); + graphics->drawImage(attackTarget, px + 4, py - 33); } */ } - - if (action != STAND) - { - mFrame = (get_elapsed_time(walk_time) * 4) / speed; - - if (mFrame >= 4 && action != MONSTER_DEAD) - { - nextStep(); - } - } break; default: break; } + + // Draw player name + if (getType() == PLAYER && this != player_node) + { + graphics->setFont(speechFont); + graphics->drawText(mName, px + 15, py + 30, gcn::Graphics::CENTER); + } } diff --git a/src/being.h b/src/being.h index d5ec7fab..67c8c6b6 100644 --- a/src/being.h +++ b/src/being.h @@ -88,7 +88,6 @@ class Being : public Sprite Uint8 mFrame; Sint32 speech_color; Uint16 walk_time; - Uint16 speed; Uint8 emotion; /**< Currently showing emotion */ Uint8 emotion_time; /**< Time until emotion disappears */ @@ -152,14 +151,14 @@ class Being : public Sprite void setHairColor(Uint16 color); /** - * Sets the hair style for this being. + * Gets the hair color for this being. */ - void setHairStyle(Uint16 style); + Uint16 getHairColor(); /** - * Gets the hair color for this being. + * Sets the hair style for this being. */ - Uint16 getHairColor(); + void setHairStyle(Uint16 style); /** * Gets the hair style for this being. @@ -169,38 +168,32 @@ class Being : public Sprite /** * Makes this being take the next step of his path. */ - void nextStep(); + void + nextStep(); /** * Performs being logic. */ - void logic(); + void + logic(); /** * Draws the speech text above the being. */ - void drawSpeech(Graphics *graphics, Sint32 offsetX, Sint32 offsetY); + void + drawSpeech(Graphics *graphics, Sint32 offsetX, Sint32 offsetY); /** * Returns the type of the being. */ Type getType() const; - // ACCES METHODS - /** * Gets the weapon picture id. */ Uint16 getWeapon() const { return mWeapon; } /** - * Gets the sprite id. - */ - Uint32 getId() const { return mId; } - - // MODIFICATION METHODS - - /** * Sets the weapon picture id. * * @param weapon the picture id @@ -213,7 +206,26 @@ class Being : public Sprite * * @param weapon the weapon id */ - void setWeaponById(Uint16 weapon); + void + setWeaponById(Uint16 weapon); + + /** + * Gets the walk speed. + */ + Uint16 + getWalkSpeed() const { return mWalkSpeed; } + + /** + * Sets the walk speed. + */ + void + setWalkSpeed(Uint16 speed) { mWalkSpeed = speed; } + + /** + * Gets the sprite id. + */ + Uint32 + getId() const { return mId; } /** * Sets the sprite id. @@ -226,8 +238,6 @@ class Being : public Sprite */ void setMap(Map *map); - // SPRITE METHODS - /** * Draws this being to the given graphics context. * @@ -269,8 +279,9 @@ class Being : public Sprite void setPath(std::list<PATH_NODE> path); + Uint32 mId; /**< Unique sprite id */ Uint16 mWeapon; /**< Weapon picture id */ - Uint32 mId; /**< Unique id */ + Uint16 mWalkSpeed; /**< Walking speed */ Map *mMap; /**< Map on which this being resides */ std::string mName; /**< Name of character */ Sprites::iterator mSpriteIterator; @@ -315,14 +326,9 @@ createBeing(Uint32 id, Uint16 job, Map *map); void remove_node(Being *being); -/** - * Sort beings in vertical order - */ -void -sort(); - extern Being *player_node; -extern std::list<Being*> beings; +typedef std::list<Being*> Beings; +extern Beings beings; #endif diff --git a/src/engine.cpp b/src/engine.cpp index 73974edc..2175096d 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -72,58 +72,6 @@ Spriteset *npcset; Spriteset *weaponset; -int get_x_offset(Being *being) -{ - int offset = 0; - char direction = being->direction; - - if (being->action == Being::WALK) - { - if (direction != Being::NORTH && direction != Being::SOUTH) - { - offset = (get_elapsed_time(being->walk_time) * 32) / being->speed; - if (offset > 32) offset = 32; - - if (direction == Being::WEST || direction == Being::NW || - direction == Being::SW) { - offset = -offset; - offset += 32; - } - else { - offset -= 32; - } - } - } - - return offset; -} - -int get_y_offset(Being *being) -{ - int offset = 0; - char direction = being->direction; - - if (being->action == Being::WALK) - { - if (direction != Being::EAST && direction != Being::WEST) - { - offset = (get_elapsed_time(being->walk_time) * 32) / being->speed; - if (offset > 32) offset = 32; - - if (direction == Being::NORTH || direction == Being::NW || - direction == Being::NE) { - offset = -offset; - offset += 32; - } - else { - offset -= 32; - } - } - } - - return offset; -} - Engine::Engine(): mCurrentMap(NULL) { @@ -295,8 +243,6 @@ void Engine::draw() int mouseTileX = mouseX / 32 + camera_x; int mouseTileY = mouseY / 32 + camera_y; - sort(); - frame++; // Draw tiles and sprites diff --git a/src/floor_item.cpp b/src/floor_item.cpp index 32b8aee5..106ad210 100755 --- a/src/floor_item.cpp +++ b/src/floor_item.cpp @@ -22,7 +22,6 @@ */ #include "floor_item.h" -#include "sprite.h" #include "graphic/spriteset.h" #include "resources/itemmanager.h" #include "resources/iteminfo.h" diff --git a/src/floor_item.h b/src/floor_item.h index e004c0a2..abec9840 100755 --- a/src/floor_item.h +++ b/src/floor_item.h @@ -28,8 +28,6 @@ #include "map.h" #include "sprite.h" -class Map; - /** * An item lying on the floor. */ diff --git a/src/game.cpp b/src/game.cpp index 9cac4df0..bc256b7c 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -295,7 +295,6 @@ void do_init() player_node = createBeing(account_ID, 0, engine->getCurrentMap()); player_node->x = startX; player_node->y = startY; - player_node->speed = 150; player_node->setHairColor(player_info->hairColor); player_node->setHairStyle(player_info->hairStyle); @@ -1095,7 +1094,7 @@ void do_parse() // Prevent division by 0 when calculating frame if (speed == 0) { speed = 150; } - being->speed = speed; + being->setWalkSpeed(speed); being->job = job; being->setHairStyle(msg.readShort()); being->setWeapon(msg.readShort()); @@ -1194,7 +1193,7 @@ void do_parse() being = createBeing(id, job, tiledMap); } - being->speed = speed; + being->setWalkSpeed(speed); being->job = job; being->setHairStyle(msg.readShort()); being->setWeaponById(msg.readShort()); // item id 1 @@ -1524,7 +1523,7 @@ void do_parse() switch (type) { //case 0x0000: - // player_node->speed = msg.readLong(); + // player_node->setWalkSpeed(msg.readLong()); // break; case 0x0005: player_info->hp = value; break; case 0x0006: player_info->maxHp = value; break; @@ -80,25 +80,25 @@ class Item getQuantity() const { return mQuantity; } /** - * Sets wether this item is considered equipment. + * Sets whether this item is considered equipment. */ void setEquipment(bool equipment) { mEquipment = equipment; } /** - * Returns wether this item is considered equipment. + * Returns whether this item is considered equipment. */ bool isEquipment() const { return mEquipment; } /** - * Sets wether this item is equipped. + * Sets whether this item is equipped. */ void setEquipped(bool equipped) { mEquipped = equipped; } /** - * Returns wether this item is equipped. + * Returns whether this item is equipped. */ bool isEquipped() const { return mEquipped; } diff --git a/src/map.cpp b/src/map.cpp index 37b7292a..28c52192 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -118,7 +118,7 @@ Map::draw(Graphics *graphics, int scrollX, int scrollY, int layer) // tiles have been drawn if (layer == 1) { - while (si != mSprites.end() && (*si)->getPixelY() <= y * 32 - 32) + while (si != mSprites.end() && (*si)->getPixelY() < y * 32) { (*si)->draw(graphics, -scrollX, -scrollY); si++; |