From afe095e2929c4bf2e3f52011145b48111f28b2fa Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Wed, 31 Aug 2011 19:08:55 -0300 Subject: [PATCH] fix a walk glitch --- src/otclient/core/creature.cpp | 17 ++++++++--------- src/otclient/core/creature.h | 1 + src/otclient/core/tile.cpp | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/otclient/core/creature.cpp b/src/otclient/core/creature.cpp index adf9b09c..66d21eb3 100644 --- a/src/otclient/core/creature.cpp +++ b/src/otclient/core/creature.cpp @@ -39,6 +39,7 @@ Creature::Creature() : Thing() m_walking = false; m_walkOffsetX = 0; m_walkOffsetY = 0; + m_lastWalkAnim = 1; m_informationFont = g_fonts.getFont("tibia-12px-rounded"); } @@ -112,7 +113,6 @@ void Creature::draw(int x, int y) // Update animation and position if(m_walking && type.animationPhases > 1) { - if(g_platform.getTicks() - m_lastTicks >= m_walkTimePerPixel) { int pixelsWalked = std::floor((g_platform.getTicks() - m_lastTicks) / m_walkTimePerPixel); int remainingTime = (g_platform.getTicks() - m_lastTicks) % (int)m_walkTimePerPixel; @@ -129,11 +129,12 @@ void Creature::draw(int x, int y) int walkOffset = std::max(std::abs(m_walkOffsetX), std::abs(m_walkOffsetY)); if(walkOffset % (int)std::ceil(32 / (float)type.animationPhases) == 0) { - if((m_animation+1) % type.animationPhases == 0) - m_animation = 1; + if((m_lastWalkAnim+1) % type.animationPhases == 0) + m_lastWalkAnim = 1; else - m_animation++; + m_lastWalkAnim++; } + m_animation = m_lastWalkAnim; if(((m_walkOffsetX == 0 && m_walkOffsetY == 0) && m_walkOffsetX != m_walkOffsetY) || ((m_walkOffsetX == 0 || m_walkOffsetY == 0) && m_walkOffsetX == m_walkOffsetY)) { @@ -221,10 +222,8 @@ void Creature::walk(const Position& position) } // update map tiles - TilePtr oldTile = g_map.getTile(m_position); - TilePtr newTile = g_map.getTile(position); - oldTile->removeThing(asThing()); - newTile->addThing(asThing(), -1); + g_map.removeThing(asThing()); + g_map.addThing(asThing(), position); if(m_walking) { // Calculate xPattern @@ -241,7 +240,7 @@ void Creature::walk(const Position& position) // get walk speed int groundSpeed = 0; - ItemPtr ground = newTile->getGround(); + ItemPtr ground = g_map.getTile(position)->getGround(); if(ground) groundSpeed = ground->getType().groundSpeed; diff --git a/src/otclient/core/creature.h b/src/otclient/core/creature.h index 63d46afe..639cbace 100644 --- a/src/otclient/core/creature.h +++ b/src/otclient/core/creature.h @@ -96,6 +96,7 @@ private: bool m_walking; float m_walkTimePerPixel; Position m_walkingFromPosition; + int m_lastWalkAnim; int m_walkOffsetX, m_walkOffsetY; }; diff --git a/src/otclient/core/tile.cpp b/src/otclient/core/tile.cpp index b4f45d49..4de916d1 100644 --- a/src/otclient/core/tile.cpp +++ b/src/otclient/core/tile.cpp @@ -54,7 +54,7 @@ void Tile::draw(int x, int y) for(auto it = m_things.rbegin(); it != m_things.rend(); ++it) { const ThingPtr& thing = *it; const ThingType& type = thing->getType(); - if(type.isOnTop || type.isOnBottom || type.isGround || type.isGroundClip) + if(thing->asCreature() || type.isOnTop || type.isOnBottom || type.isGroundClip || type.isGround) break; thing->draw(x - m_drawElevation, y - m_drawElevation); m_drawElevation += type.elevation;