From ac01c186d37b14da92314ff44b4e043b0c0ee31b Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 5 Sep 2013 21:31:10 +0300 Subject: add support for additinional diagonal moving speed. --- src/being/being.cpp | 23 +++++++++++++---------- src/being/being.h | 3 ++- 2 files changed, 15 insertions(+), 11 deletions(-) (limited to 'src/being') diff --git a/src/being/being.cpp b/src/being/being.cpp index 252de4c3b..73652bb1a 100644 --- a/src/being/being.cpp +++ b/src/being/being.cpp @@ -137,6 +137,7 @@ Being::Being(const int id, const Type type, const uint16_t subtype, mType(type), mSpeechBubble(new SpeechBubble), mWalkSpeed(Net::getPlayerHandler()->getDefaultWalkSpeed()), + mSpeed(Net::getPlayerHandler()->getDefaultWalkSpeed().x), mIp(), mSpriteRemap(new int[20]), mSpriteHide(new int[20]), @@ -1345,10 +1346,15 @@ void Being::nextTile() return; } + mActionTime += static_cast(mSpeed / 10); + if (mX != pos.x && mY != pos.y) + mSpeed = mWalkSpeed.x * 1.4; + else + mSpeed = mWalkSpeed.x; + mX = pos.x; mY = pos.y; setAction(MOVE); - mActionTime += static_cast(mWalkSpeed.x / 10); } void Being::logic() @@ -1481,8 +1487,8 @@ void Being::logic() case MOVE: { - if (static_cast(get_elapsed_time(mActionTime) - >= getWalkSpeed().x)) + if (static_cast(get_elapsed_time( + mActionTime)) >= mSpeed) { nextTile(); } @@ -1528,10 +1534,9 @@ void Being::logic() if (frameCount < 10) frameCount = 10; - if (!isAlive() && getWalkSpeed().x - && Net::getGameHandler()->removeDeadBeings() + if (!isAlive() && mSpeed && Net::getGameHandler()->removeDeadBeings() && static_cast ((static_cast(get_elapsed_time(mActionTime)) - / static_cast(getWalkSpeed().x))) >= frameCount) + / mSpeed)) >= frameCount) { if (mType != PLAYER && actorSpriteManager) actorSpriteManager->destroy(this); @@ -1627,11 +1632,9 @@ int Being::getOffset(const signed char pos, const signed char neg) const const int time = get_elapsed_time(mActionTime); offset = (pos == LEFT && neg == RIGHT) ? static_cast((static_cast(time) - * static_cast(mMap->getTileWidth())) - / static_cast(mWalkSpeed.x)) : + * static_cast(mMap->getTileWidth())) / mSpeed) : static_cast((static_cast(time) - * static_cast(mMap->getTileHeight())) - / static_cast(mWalkSpeed.y)); + * static_cast(mMap->getTileHeight())) / mSpeed); } // We calculate the offset _from_ the _target_ location diff --git a/src/being/being.h b/src/being/being.h index b08cba443..e373ec5e3 100644 --- a/src/being/being.h +++ b/src/being/being.h @@ -476,7 +476,7 @@ class Being : public ActorSprite, public ConfigListener * in tiles per second for Manaserv. */ void setWalkSpeed(const Vector &speed) - { mWalkSpeed = speed; } + { mWalkSpeed = speed; mSpeed = speed.x; } /** * Gets the walk speed. @@ -1000,6 +1000,7 @@ class Being : public ActorSprite, public ConfigListener * @see MILLISECONDS_IN_A_TICK */ Vector mWalkSpeed; + float mSpeed; std::string mIp; int *mSpriteRemap; int *mSpriteHide; -- cgit v1.2.3-70-g09d2