From 01e2baa778318150bdd1829836cfff9e677cf72c Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 17 Sep 2013 17:53:47 +0300 Subject: add walking on map height. using collisions from actual and not drawing tile. still have issue with fringe layer objects. --- src/being/being.cpp | 20 ++++++++++++++++++-- src/being/being.h | 6 +++++- src/map.cpp | 7 +++++++ src/map.h | 2 ++ src/mapheights.h | 3 +++ 5 files changed, 35 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/being/being.cpp b/src/being/being.cpp index 1b3d8f15e..00df60848 100644 --- a/src/being/being.cpp +++ b/src/being/being.cpp @@ -147,6 +147,9 @@ Being::Being(const int id, const Type type, const uint16_t subtype, mSpecialParticle(nullptr), mX(0), mY(0), + mOffsetX(0), + mOffsetY(0), + mOldHeight(0), mDamageTaken(0), mHP(0), mMaxHP(0), @@ -1352,8 +1355,12 @@ void Being::nextTile() else mSpeed = mWalkSpeed.x; + if (mX != pos.x || mY != pos.y) + mOldHeight = mMap->getHeightOffset(mX, mY); mX = pos.x; mY = pos.y; + const uint8_t height = mMap->getHeightOffset(mX, mY); + mOffsetY = height - mOldHeight; setAction(MOVE); } @@ -1514,9 +1521,18 @@ void Being::logic() } } + const int xOffset = getXOffset(); + const int yOffset = getYOffset(); + int offset = xOffset; + if (!offset) + offset = yOffset; + + const int yOffset2 = getYOffset() - (mOldHeight * 16) + - (mOffsetY * 16) * (32 - abs(offset)) / 32; + // Update pixel coordinates - setPosition(static_cast(mX * 32 + 16 + getXOffset()), - static_cast(mY * 32 + 32 + getYOffset())); + setPosition(static_cast(mX * 32 + 16 + xOffset), + static_cast(mY * 32 + 32 + yOffset2)); } if (mEmotionSprite) diff --git a/src/being/being.h b/src/being/being.h index ff40186bc..8ac288137 100644 --- a/src/being/being.h +++ b/src/being/being.h @@ -1001,7 +1001,11 @@ class Being : public ActorSprite, public ConfigListener Being *mOwner; Particle *mSpecialParticle; - int mX, mY; /**< Position in tile */ + int mX; // position in tiles + int mY; // position in tiles + int mOffsetX; // offset in pixels + int mOffsetY; // offset in pixels + uint8_t mOldHeight; int mDamageTaken; int mHP; diff --git a/src/map.cpp b/src/map.cpp index 86d2171e9..df49b2eb9 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -1585,3 +1585,10 @@ void Map::addHeights(MapHeights *const heights) delete mHeights; mHeights = heights; } + +uint8_t Map::getHeightOffset(const int x, const int y) const +{ + if (!mHeights) + return 0; + return mHeights->getHeight(x, y); +} diff --git a/src/map.h b/src/map.h index a6eef01bf..37990752b 100644 --- a/src/map.h +++ b/src/map.h @@ -424,6 +424,8 @@ class Map final : public Properties, public ConfigListener void addHeights(MapHeights *const heights); + uint8_t getHeightOffset(const int x, const int y) const; + protected: friend class Actor; friend class Minimap; diff --git a/src/mapheights.h b/src/mapheights.h index 51ea885c9..2fd4c44ab 100644 --- a/src/mapheights.h +++ b/src/mapheights.h @@ -36,6 +36,9 @@ class MapHeights final void setHeight(const int x, const int y, const uint8_t height); + uint8_t getHeight(const int x, const int y) const + { return mTiles[x + y * mWidth]; } + private: int mWidth; int mHeight; -- cgit v1.2.3-70-g09d2