fix a walk glitch
This commit is contained in:
parent
3b5dd3ecf9
commit
afe095e292
|
@ -39,6 +39,7 @@ Creature::Creature() : Thing()
|
||||||
m_walking = false;
|
m_walking = false;
|
||||||
m_walkOffsetX = 0;
|
m_walkOffsetX = 0;
|
||||||
m_walkOffsetY = 0;
|
m_walkOffsetY = 0;
|
||||||
|
m_lastWalkAnim = 1;
|
||||||
|
|
||||||
m_informationFont = g_fonts.getFont("tibia-12px-rounded");
|
m_informationFont = g_fonts.getFont("tibia-12px-rounded");
|
||||||
}
|
}
|
||||||
|
@ -112,7 +113,6 @@ void Creature::draw(int x, int y)
|
||||||
|
|
||||||
// Update animation and position
|
// Update animation and position
|
||||||
if(m_walking && type.animationPhases > 1) {
|
if(m_walking && type.animationPhases > 1) {
|
||||||
|
|
||||||
if(g_platform.getTicks() - m_lastTicks >= m_walkTimePerPixel) {
|
if(g_platform.getTicks() - m_lastTicks >= m_walkTimePerPixel) {
|
||||||
int pixelsWalked = std::floor((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;
|
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));
|
int walkOffset = std::max(std::abs(m_walkOffsetX), std::abs(m_walkOffsetY));
|
||||||
if(walkOffset % (int)std::ceil(32 / (float)type.animationPhases) == 0) {
|
if(walkOffset % (int)std::ceil(32 / (float)type.animationPhases) == 0) {
|
||||||
if((m_animation+1) % type.animationPhases == 0)
|
if((m_lastWalkAnim+1) % type.animationPhases == 0)
|
||||||
m_animation = 1;
|
m_lastWalkAnim = 1;
|
||||||
else
|
else
|
||||||
m_animation++;
|
m_lastWalkAnim++;
|
||||||
}
|
}
|
||||||
|
m_animation = m_lastWalkAnim;
|
||||||
|
|
||||||
if(((m_walkOffsetX == 0 && m_walkOffsetY == 0) && m_walkOffsetX != m_walkOffsetY) ||
|
if(((m_walkOffsetX == 0 && m_walkOffsetY == 0) && m_walkOffsetX != m_walkOffsetY) ||
|
||||||
((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
|
// update map tiles
|
||||||
TilePtr oldTile = g_map.getTile(m_position);
|
g_map.removeThing(asThing());
|
||||||
TilePtr newTile = g_map.getTile(position);
|
g_map.addThing(asThing(), position);
|
||||||
oldTile->removeThing(asThing());
|
|
||||||
newTile->addThing(asThing(), -1);
|
|
||||||
|
|
||||||
if(m_walking) {
|
if(m_walking) {
|
||||||
// Calculate xPattern
|
// Calculate xPattern
|
||||||
|
@ -241,7 +240,7 @@ void Creature::walk(const Position& position)
|
||||||
// get walk speed
|
// get walk speed
|
||||||
int groundSpeed = 0;
|
int groundSpeed = 0;
|
||||||
|
|
||||||
ItemPtr ground = newTile->getGround();
|
ItemPtr ground = g_map.getTile(position)->getGround();
|
||||||
if(ground)
|
if(ground)
|
||||||
groundSpeed = ground->getType().groundSpeed;
|
groundSpeed = ground->getType().groundSpeed;
|
||||||
|
|
||||||
|
|
|
@ -96,6 +96,7 @@ private:
|
||||||
bool m_walking;
|
bool m_walking;
|
||||||
float m_walkTimePerPixel;
|
float m_walkTimePerPixel;
|
||||||
Position m_walkingFromPosition;
|
Position m_walkingFromPosition;
|
||||||
|
int m_lastWalkAnim;
|
||||||
int m_walkOffsetX, m_walkOffsetY;
|
int m_walkOffsetX, m_walkOffsetY;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ void Tile::draw(int x, int y)
|
||||||
for(auto it = m_things.rbegin(); it != m_things.rend(); ++it) {
|
for(auto it = m_things.rbegin(); it != m_things.rend(); ++it) {
|
||||||
const ThingPtr& thing = *it;
|
const ThingPtr& thing = *it;
|
||||||
const ThingType& type = thing->getType();
|
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;
|
break;
|
||||||
thing->draw(x - m_drawElevation, y - m_drawElevation);
|
thing->draw(x - m_drawElevation, y - m_drawElevation);
|
||||||
m_drawElevation += type.elevation;
|
m_drawElevation += type.elevation;
|
||||||
|
|
Loading…
Reference in New Issue