walk perfect?
This commit is contained in:
parent
ee5180b9c5
commit
361b28c6d6
|
@ -244,10 +244,10 @@ public:
|
||||||
b2 = r.y2;
|
b2 = r.y2;
|
||||||
|
|
||||||
TRect<T> tmp;
|
TRect<T> tmp;
|
||||||
tmp.x1 = std::min(l1, l2);
|
tmp.x1 = std::max(l1, l2);
|
||||||
tmp.x2 = std::max(r1, r2);
|
tmp.x2 = std::min(r1, r2);
|
||||||
tmp.y1 = std::min(t1, t2);
|
tmp.y1 = std::max(t1, t2);
|
||||||
tmp.y2 = std::max(b1, b2);
|
tmp.y2 = std::min(b1, b2);
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,6 +75,8 @@ public:
|
||||||
int getWalkOffsetX() { return m_walkOffsetX; }
|
int getWalkOffsetX() { return m_walkOffsetX; }
|
||||||
int getWalkOffsetY() { return m_walkOffsetY; }
|
int getWalkOffsetY() { return m_walkOffsetY; }
|
||||||
|
|
||||||
|
bool isWalking() { return m_walking; }
|
||||||
|
|
||||||
CreaturePtr asCreature() { return std::static_pointer_cast<Creature>(shared_from_this()); }
|
CreaturePtr asCreature() { return std::static_pointer_cast<Creature>(shared_from_this()); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -62,32 +62,16 @@ void Tile::draw(int x, int y)
|
||||||
m_drawElevation = MAX_DRAW_ELEVATION;
|
m_drawElevation = MAX_DRAW_ELEVATION;
|
||||||
}
|
}
|
||||||
|
|
||||||
// creatures, check for walking creatures in 2x2 tiles
|
// we can render creatures in 3x3 range
|
||||||
for(int xi = -1; xi <= 0; ++xi) {
|
for(int xi = -1; xi <= 1; ++xi) {
|
||||||
for(int yi = -1; yi <= 0; ++yi) {
|
for(int yi = -1; yi <= 1; ++yi) {
|
||||||
TilePtr tile = g_map.getTile(m_position + Position(xi, yi, 0));
|
|
||||||
for(CreaturePtr creature : g_map.getTile(m_position + Position(xi, yi, 0))->getCreatures()) {
|
for(CreaturePtr creature : g_map.getTile(m_position + Position(xi, yi, 0))->getCreatures()) {
|
||||||
bool draw = false;
|
Rect creatureRect(x + xi*32 + creature->getWalkOffsetX(), y + yi*32 + creature->getWalkOffsetY(), 24, 24);
|
||||||
// own creature not walking
|
Rect thisTileRect(x, y, 32, 32);
|
||||||
if(creature->getWalkOffsetX() == 0 && creature->getWalkOffsetY() == 0 && xi == 0 && yi == 0)
|
|
||||||
draw = true;
|
// only render creatures where bottom right is inside our rect
|
||||||
// own creature walking on any direction
|
if(thisTileRect.contains(creatureRect.bottomRight()))
|
||||||
else if(xi == 0 && yi == 0 &&
|
creature->draw(x + xi*32 - m_drawElevation, y + yi*32 - m_drawElevation);
|
||||||
creature->getWalkOffsetX() <= 8 && creature->getWalkOffsetY() <= 8 &&
|
|
||||||
creature->getWalkOffsetX() > -24 && creature->getWalkOffsetY() > -24)
|
|
||||||
draw = true;
|
|
||||||
// creature walking north/south to neighbour tile
|
|
||||||
else if(xi == 0 && yi != 0 && (creature->getWalkOffsetY() > 8 || creature->getWalkOffsetY() <= -24) && creature->getWalkOffsetX() == 0)
|
|
||||||
draw = true;
|
|
||||||
// creature walking west/east to neighbour tile
|
|
||||||
else if(xi != 0 && yi == 0 && (creature->getWalkOffsetX() > 8 || creature->getWalkOffsetX() <= -24) && creature->getWalkOffsetY() == 0)
|
|
||||||
draw = true;
|
|
||||||
// creature walking in diagonal
|
|
||||||
else if(xi != 0 && yi != 0 && ((creature->getWalkOffsetY() > 8 || creature->getWalkOffsetY() <= -24) ||
|
|
||||||
(creature->getWalkOffsetX() > 8 || creature->getWalkOffsetX() <= -24)))
|
|
||||||
draw = true;
|
|
||||||
if(draw)
|
|
||||||
creature->draw(x - m_drawElevation + xi*32, y - m_drawElevation + yi*32);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,8 @@ public:
|
||||||
ItemPtr getGround();
|
ItemPtr getGround();
|
||||||
bool isFullyOpaque();
|
bool isFullyOpaque();
|
||||||
|
|
||||||
|
TilePtr asTile() { return std::static_pointer_cast<Tile>(shared_from_this()); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<EffectPtr> m_effects;
|
std::vector<EffectPtr> m_effects;
|
||||||
std::vector<ThingPtr> m_things;
|
std::vector<ThingPtr> m_things;
|
||||||
|
|
Loading…
Reference in New Issue