walk changes, not done yet

This commit is contained in:
Henrique 2011-08-30 11:37:48 -03:00
parent b6b823aa9c
commit 4d90b674ac
7 changed files with 84 additions and 43 deletions

View File

@ -136,10 +136,7 @@ void Creature::draw(int x, int y)
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;
m_animation = 0;
cancelWalk(m_direction);
}
m_lastTicks = g_platform.getTicks() - remainingTime;
@ -174,50 +171,44 @@ void Creature::walk(const Position& position)
m_walking = true;
m_walkOffsetX = 0;
m_walkOffsetY = 0;
m_walkingFromPosition = m_position;
int walkTimeFactor = 1;
// update map tiles
g_map.removeThingByPtr(asThing());
m_position = position;
g_map.addThing(asThing());
// set new direction
if(m_walkingFromPosition + Position(0, -1, 0) == m_position) {
if(m_position + Position(0, -1, 0) == position) {
m_direction = Otc::North;
m_walkOffsetY = 32;
}
else if(m_walkingFromPosition + Position(1, 0, 0) == m_position) {
else if(m_position + Position(1, 0, 0) == position) {
m_direction = Otc::East;
m_walkOffsetX = -32;
}
else if(m_walkingFromPosition + Position(0, 1, 0) == m_position) {
else if(m_position + Position(0, 1, 0) == position) {
m_direction = Otc::South;
m_walkOffsetY = -32;
}
else if(m_walkingFromPosition + Position(-1, 0, 0) == m_position) {
else if(m_position + Position(-1, 0, 0) == position) {
m_direction = Otc::West;
m_walkOffsetX = 32;
}
else if(m_walkingFromPosition + Position(1, -1, 0) == m_position) {
else if(m_position + Position(1, -1, 0) == position) {
m_direction = Otc::NorthEast;
m_walkOffsetX = -32;
m_walkOffsetY = 32;
walkTimeFactor = 2;
}
else if(m_walkingFromPosition + Position(1, 1, 0) == m_position) {
else if(m_position + Position(1, 1, 0) == position) {
m_direction = Otc::SouthEast;
m_walkOffsetX = -32;
m_walkOffsetY = -32;
walkTimeFactor = 2;
}
else if(m_walkingFromPosition + Position(-1, 1, 0) == m_position) {
else if(m_position + Position(-1, 1, 0) == position) {
m_direction = Otc::SouthWest;
m_walkOffsetX = 32;
m_walkOffsetY = -32;
walkTimeFactor = 2;
}
else if(m_walkingFromPosition + Position(-1, -1, 0) == m_position) {
else if(m_position + Position(-1, -1, 0) == position) {
m_direction = Otc::NorthWest;
m_walkOffsetX = 32;
m_walkOffsetY = 32;
@ -228,30 +219,46 @@ void Creature::walk(const Position& position)
m_walking = false;
}
// Calculate xDiv
if(m_direction >= 4) {
if(m_direction == Otc::NorthEast || m_direction == Otc::SouthEast)
m_xDiv = Otc::East;
else if(m_direction == Otc::NorthWest || m_direction == Otc::SouthWest)
m_xDiv = Otc::West;
}
else {
m_xDiv = m_direction;
// update map tiles
g_map.removeThingByPtr(asThing());
m_position = position;
g_map.addThing(asThing());
if(m_walking) {
// Calculate xDiv
if(m_direction >= 4) {
if(m_direction == Otc::NorthEast || m_direction == Otc::SouthEast)
m_xDiv = Otc::East;
else if(m_direction == Otc::NorthWest || m_direction == Otc::SouthWest)
m_xDiv = Otc::West;
}
else {
m_xDiv = m_direction;
}
// get walk speed
int groundSpeed = 0;
ThingPtr ground = g_map.getThing(m_position, 0);
if(ground)
groundSpeed = ground->getAttributes().speed;
float walkTime = walkTimeFactor * 1000.0 * (float)groundSpeed / m_speed;
walkTime = walkTime == 0 ? 1000 : walkTime;
m_walkTimePerPixel = walkTime / 32.0;
m_lastTicks = g_platform.getTicks();
}
}
// get walk speed
int groundSpeed = 0;
ThingPtr ground = g_map.getThing(m_position, 0);
if(ground)
groundSpeed = ground->getAttributes().speed;
float walkTime = walkTimeFactor * 1000.0 * (float)groundSpeed / m_speed;
walkTime = walkTime == 0 ? 1000 : walkTime;
m_walkTimePerPixel = walkTime / 32.0;
m_lastTicks = g_platform.getTicks();
void Creature::cancelWalk(Otc::Direction direction)
{
m_walking = false;
m_walkOffsetX = 0;
m_walkOffsetY = 0;
m_animation = 0;
m_direction = direction;
}
void Creature::setHealthPercent(uint8 healthPercent)

View File

@ -71,6 +71,7 @@ public:
void onHealthPercentChange(int);
void walk(const Position& position);
void cancelWalk(Otc::Direction direction);
int getWalkOffsetX() { return m_walkOffsetX; }
int getWalkOffsetY() { return m_walkOffsetY; }

View File

@ -102,7 +102,7 @@ void Game::walk(Otc::Direction direction)
// TODO: check if we can walk.
//m_localPlayer->setDirection(direction);
m_localPlayer->walk(direction);
switch(direction) {
case Otc::North:

View File

@ -22,3 +22,9 @@
#include "localplayer.h"
void LocalPlayer::walk(Otc::Direction direction)
{
//Position newPos = m_position + Position::getPositionFromDirection(direction);
//asCreature()->walk(newPos);
}

View File

@ -39,6 +39,8 @@ public:
void setSkill(Otc::Skill skill, Otc::SkillType skillType, int value) { m_skills[skill][skillType] = value; }
int getSkill(Otc::Skill skill, Otc::SkillType skillType) { return m_skills[skill][skillType]; }
void walk(Otc::Direction direction);
LocalPlayerPtr asLocalPlayer() { return std::static_pointer_cast<LocalPlayer>(shared_from_this()); }
private:

View File

@ -34,7 +34,7 @@ void ProtocolGame::parseMessage(InputMessage& msg)
{
while(!msg.eof()) {
uint8 opt = msg.getU8();
//dump << "protocol id:" << std::hex << (int)opt;
dump << "protocol id:" << std::hex << (int)opt;
switch(opt) {
case 0x0A:
@ -763,7 +763,7 @@ void ProtocolGame::parseTextMessage(InputMessage& msg)
void ProtocolGame::parseCancelWalk(InputMessage& msg)
{
Otc::Direction direction = (Otc::Direction)msg.getU8();
g_game.getLocalPlayer()->setDirection(direction);
m_localPlayer->cancelWalk(direction);
}
void ProtocolGame::parseFloorChangeUp(InputMessage& msg)
@ -1008,6 +1008,7 @@ ThingPtr ProtocolGame::internalGetThing(InputMessage& msg)
creature->setShield(shield);
creature->setEmblem(emblem);
creature->setImpassable(impassable);
creature->cancelWalk(direction);
thing = creature;

View File

@ -23,6 +23,7 @@
#ifndef POSITION_H
#define POSITION_H
#include <otclient/const.h>
#include <framework/util/types.h>
class Position
@ -31,6 +32,29 @@ public:
Position() : x(-1), y(-1), z(-1) { }
Position(int x, int y, int z) : x(x), y(y), z(z) { }
static Position getPositionFromDirection(Otc::Direction direction) {
switch(direction) {
case Otc::North:
return Position( 0, -1, 0);
case Otc::East:
return Position( 1, 0, 0);
case Otc::South:
return Position( 0, 1, 0);
case Otc::West:
return Position(-1, 0, 0);
case Otc::NorthEast:
return Position( 1, -1, 0);
case Otc::SouthEast:
return Position( 1, 1, 0);
case Otc::SouthWest:
return Position(-1, 1, 0);
case Otc::NorthWest:
return Position(-1, -1, 0);
default:
return Position();
}
}
bool isValid() const { return x >= 0 && y >= 0 && z >= 0 && x < 65536 && y < 65536 && z < 15; }
Position operator+(const Position& other) const { return Position(x + other.x, y + other.y, z + other.z); }