walk improvements, still have some bugs

master
Henrique 13 years ago
parent 94cdfb1856
commit 0c4d0632c2

@ -39,34 +39,24 @@ void Creature::draw(int x, int y)
// 1000 * groundSpeed / playerSpeed
// TODO 1: ADD 2 NEW RENDER STEPS, CREATURE AND TOP 3
// TODO 2: CONSIDER STRETCH FACTOR ON drawInformation
// TODO 3: FIX MAP BUGGY TILES ??
// TODO 1: FIX RENDER STEP 2
// TODO 2: FIX SHAKY EFFECT
// TODO 3: ADD ANIMATION
const ThingAttributes& attributes = getAttributes();
// we must walk 32 pixels in m_speed miliseconds
if(m_walking && attributes.animcount > 1) {
int groundSpeed = 0;
ThingPtr ground = g_map.getThing(m_walkingPosition, 0);
if(ground)
groundSpeed = ground->getAttributes().speed;
float walkTime = 1000.0 * (float)groundSpeed / m_speed;
//dump << walkTime << (g_platform.getTicks() - m_lastTicks+1);
double offset = (32.0 / m_walkTime) * (g_platform.getTicks() - m_lastTicks);
if(m_direction == DIRECTION_NORTH)
m_walkOffsetY -= (32.0 / walkTime) * (g_platform.getTicks() - m_lastTicks+1);
m_walkOffsetY = std::max(m_walkOffsetY - offset, 0.0);
else if(m_direction == DIRECTION_EAST)
m_walkOffsetX += (32.0 / walkTime) * (g_platform.getTicks() - m_lastTicks+1);
m_walkOffsetX = std::min(m_walkOffsetX + offset, 0.0);
else if(m_direction == DIRECTION_SOUTH)
m_walkOffsetY += (32.0 / walkTime) * (g_platform.getTicks() - m_lastTicks+1);
m_walkOffsetY = std::min(m_walkOffsetY + offset, 0.0);
else if(m_direction == DIRECTION_WEST)
m_walkOffsetX -= (32.0 / walkTime) * (g_platform.getTicks() - m_lastTicks+1);
m_walkOffsetX = std::max(m_walkOffsetX - offset, 0.0);
/*if(g_platform.getTicks() - m_lastTicks > m_speed / 4) {
if(m_animation+1 == attributes.animcount)
@ -77,16 +67,10 @@ void Creature::draw(int x, int y)
m_lastTicks = g_platform.getTicks();
}*/
dump << m_walkOffsetY;
if(fabs(m_walkOffsetY) >= 32) {
g_map.removeThingByPtr(asThing());
// calc newpos
m_position = m_walkingPosition;
g_map.addThing(asThing());
if(((m_walkOffsetX == 0 && m_walkOffsetY == 0) && m_walkOffsetX != m_walkOffsetY) ||
((m_walkOffsetX == 0 || m_walkOffsetY == 0) && m_walkOffsetX == m_walkOffsetY)) {
m_walking = false;
m_walkOffsetX = 0;
m_walkOffsetY = 0;
}
@ -136,9 +120,6 @@ void Creature::draw(int x, int y)
void Creature::drawInformation(int x, int y, bool useGray)
{
x += m_walkOffsetX;
y += m_walkOffsetY;
Color fillColor = Color(96, 96, 96);
if(!useGray) {
@ -189,26 +170,48 @@ void Creature::drawInformation(int x, int y, bool useGray)
void Creature::walk(const Position& position)
{
// set walking state
m_walking = true;
m_walkOffsetX = 0;
m_walkOffsetY = 0;
m_walkingPosition = position;
m_walkingFromPosition = m_position;
// update map tiles
g_map.removeThingByPtr(asThing());
m_position = position;
g_map.addThing(asThing());
if(m_position + Position(0, -1, 0) == m_walkingPosition)
// set new direction
if(m_walkingFromPosition + Position(0, -1, 0) == m_position) {
m_direction = DIRECTION_NORTH;
else if(m_position + Position(1, 0, 0) == m_walkingPosition)
m_walkOffsetY = 32;
}
else if(m_walkingFromPosition + Position(1, 0, 0) == m_position) {
m_direction = DIRECTION_EAST;
else if(m_position + Position(0, 1, 0) == m_walkingPosition)
m_walkOffsetX = -32;
}
else if(m_walkingFromPosition + Position(0, 1, 0) == m_position) {
m_direction = DIRECTION_SOUTH;
else if(m_position + Position(-1, 0, 0) == m_walkingPosition)
m_walkOffsetY = -32;
}
else if(m_walkingFromPosition + Position(-1, 0, 0) == m_position) {
m_direction = DIRECTION_WEST;
m_walkOffsetX = 32;
}
else { // Teleport
g_map.removeThingByPtr(asThing());
m_position = m_walkingPosition;
g_map.addThing(asThing());
// we teleported, dont walk or change direction
m_walking = false;
}
// get walk speed
int groundSpeed = 0;
ThingPtr ground = g_map.getThing(m_position, 0);
if(ground)
groundSpeed = ground->getAttributes().speed;
m_walkTime = 1000.0 * (float)groundSpeed / m_speed;
m_walkTime = m_walkTime == 0 ? 1000 : m_walkTime;
}
const ThingAttributes& Creature::getAttributes()

@ -44,6 +44,8 @@ public:
bool getImpassable() { return m_impassable; }
void walk(const Position& position);
double getWalkOffsetX() { return m_walkOffsetX; }
double getWalkOffsetY() { return m_walkOffsetY; }
const ThingAttributes& getAttributes();
@ -63,8 +65,9 @@ private:
int m_lastTicks;
bool m_walking;
Position m_walkingPosition;
float m_walkOffsetX, m_walkOffsetY;
double m_walkTime;
Position m_walkingFromPosition;
double m_walkOffsetX, m_walkOffsetY;
int m_animation;
};

@ -14,7 +14,10 @@ void Map::draw(const Rect& rect)
g_graphics.bindColor(Color::white);
m_framebuffer->bind();
Position playerPos = g_game.getLocalPlayer()->getPosition();
LocalPlayerPtr player = g_game.getLocalPlayer();
Position playerPos = player->getPosition();
double walkOffsetX = player->getWalkOffsetX();
double walkOffsetY = player->getWalkOffsetY();
// player is above 7
@ -53,11 +56,13 @@ void Map::draw(const Rect& rect)
// +1 in draws cause 64x64 items may affect view.
for(int ix = -7+(playerPos.z-iz); ix < + 8+7; ++ix) {
for(int iy = -5+(playerPos.z-iz); iy < + 6+7; ++iy) {
Position itemPos = Position(playerPos.x + ix, playerPos.y + iy, iz);
if(const TilePtr& tile = m_tiles[itemPos])
tile->draw((ix + 7 - (playerPos.z-iz))*32, (iy + 5 - (playerPos.z-iz))*32);
for(int step = 0; step < 2; ++step) {
for(int ix = -8+(playerPos.z-iz); ix < + 8+7; ++ix) {
for(int iy = -6+(playerPos.z-iz); iy < + 6+7; ++iy) {
Position itemPos = Position(playerPos.x + ix, playerPos.y + iy, iz);
if(const TilePtr& tile = m_tiles[itemPos])
tile->draw((ix + 7 - (playerPos.z-iz))*32 - walkOffsetX, (iy + 5 - (playerPos.z-iz))*32 - walkOffsetY, step);
}
}
}
}
@ -89,6 +94,13 @@ void Map::draw(const Rect& rect)
int x = (ix + 7)*32 + 10 - tile->getDrawNextOffset();
int y = (iy + 5)*32 - 10 - tile->getDrawNextOffset();
if(creature != player) {
x += creature->getWalkOffsetX() - walkOffsetX;
y += creature->getWalkOffsetY() - walkOffsetY;
}
// TODO: create isCovered function.
bool useGray = (drawFloorStop != playerPos.z-1);

@ -11,64 +11,61 @@ Tile::Tile()
m_drawNextOffset = 0;
}
void Tile::draw(int x, int y)
void Tile::draw(int x, int y, int step)
{
FontPtr font = g_fonts.getDefaultFont();
if(step == 0) {
m_drawNextOffset = 0;
m_drawNextOffset = 0;
if(m_ground)
m_ground->draw(x, y);
if(m_ground)
m_ground->draw(x, y);
for(auto it = m_itemsTop.rbegin(), end = m_itemsTop.rend(); it != end; ++it) {
const ThingPtr& thing = *it;
const ThingAttributes& thingAttributes = thing->getAttributes();
for(auto it = m_itemsTop.rbegin(), end = m_itemsTop.rend(); it != end; ++it) {
const ThingPtr& thing = *it;
const ThingAttributes& thingAttributes = thing->getAttributes();
if(thingAttributes.alwaysOnTopOrder == 1) {
thing->draw(x - m_drawNextOffset, y - m_drawNextOffset);
m_drawNextOffset += thingAttributes.drawNextOffset;
}
}
if(thingAttributes.alwaysOnTopOrder == 1) {
thing->draw(x - m_drawNextOffset, y - m_drawNextOffset);
//font->renderText("T1", Rect(x + 5, y+5, 100, 100));
for(auto it = m_itemsTop.rbegin(), end = m_itemsTop.rend(); it != end; ++it) {
const ThingPtr& thing = *it;
const ThingAttributes& thingAttributes = thing->getAttributes();
m_drawNextOffset += thingAttributes.drawNextOffset;
if(thingAttributes.alwaysOnTopOrder == 2) {
thing->draw(x - m_drawNextOffset, y - m_drawNextOffset);
m_drawNextOffset += thingAttributes.drawNextOffset;
}
}
}
for(auto it = m_itemsTop.rbegin(), end = m_itemsTop.rend(); it != end; ++it) {
const ThingPtr& thing = *it;
const ThingAttributes& thingAttributes = thing->getAttributes();
if(thingAttributes.alwaysOnTopOrder == 2) {
for(auto it = m_itemsBottom.rbegin(), end = m_itemsBottom.rend(); it != end; ++it) {
const ThingPtr& thing = *it;
const ThingAttributes& thingAttributes = thing->getAttributes();
thing->draw(x - m_drawNextOffset, y - m_drawNextOffset);
//font->renderText("T2", Rect(x + 5, y+5, 100, 100));
m_drawNextOffset += thingAttributes.drawNextOffset;
}
}
else if(step == 1) {
for(auto it = m_itemsBottom.rbegin(), end = m_itemsBottom.rend(); it != end; ++it) {
const ThingPtr& thing = *it;
const ThingAttributes& thingAttributes = thing->getAttributes();
thing->draw(x - m_drawNextOffset, y - m_drawNextOffset);
//font->renderText("B0", Rect(x + 5, y+5, 100, 100));
m_drawNextOffset += thingAttributes.drawNextOffset;
}
for(auto it = m_creatures.rbegin(), end = m_creatures.rend(); it != end; ++it) {
const ThingPtr& thing = *it;
thing->draw(x - m_drawNextOffset, y - m_drawNextOffset);
}
for(auto it = m_creatures.rbegin(), end = m_creatures.rend(); it != end; ++it) {
const ThingPtr& thing = *it;
thing->draw(x - m_drawNextOffset, y - m_drawNextOffset);
}
for(auto it = m_itemsTop.rbegin(), end = m_itemsTop.rend(); it != end; ++it) {
const ThingPtr& thing = *it;
const ThingAttributes& thingAttributes = thing->getAttributes();
for(auto it = m_itemsTop.rbegin(), end = m_itemsTop.rend(); it != end; ++it) {
const ThingPtr& thing = *it;
const ThingAttributes& thingAttributes = thing->getAttributes();
if(thingAttributes.alwaysOnTopOrder == 3) {
thing->draw(x, y);
//font->renderText("T3", Rect(x + 5, y+5, 100, 100));
if(thingAttributes.alwaysOnTopOrder == 3) {
thing->draw(x, y);
}
}
}
for(auto it = m_effects.rbegin(), end = m_effects.rend(); it != end; ++it) {
const ThingPtr& thing = *it;
thing->draw(x - m_drawNextOffset, y - m_drawNextOffset);
for(auto it = m_effects.rbegin(), end = m_effects.rend(); it != end; ++it) {
const ThingPtr& thing = *it;
thing->draw(x - m_drawNextOffset, y - m_drawNextOffset);
}
}
}

@ -9,7 +9,7 @@ class Tile : public LuaObject
public:
Tile();
void draw(int x, int y);
void draw(int x, int y, int step);
void addThing(ThingPtr thing, int stackpos);
ThingPtr getThing(unsigned int stackpos);

Loading…
Cancel
Save