diagonal walking, there is a map bug

This commit is contained in:
Henrique 2011-08-29 02:54:28 -03:00
parent aacf98b45c
commit b859f66952
7 changed files with 106 additions and 14 deletions

View File

@ -25,7 +25,7 @@ MESSAGE(STATUS "BUILD TYPE: " ${CMAKE_BUILD_TYPE})
# setup compiler options
IF(CMAKE_COMPILER_IS_GNUCXX)
SET(CXX_WARNS "-Wall -Wextra -Werror -Wno-unused-parameter -Wno-unused-but-set-variable -Wno-unused-variable")
SET(CXX_WARNS "-Wall -Wextra -Werror -Wno-unused-parameter -Wno-unused-but-set-variable -Wno-unused-variable -Wno-switch")
SET(CMAKE_CXX_FLAGS "-std=c++0x -pipe ${CXX_WARNS}")
SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3 -ggdb3 -fno-inline")
SET(CMAKE_CXX_FLAGS_RELEASE "-O2")

View File

@ -79,7 +79,11 @@ namespace Otc
North = 0,
East,
South,
West
West,
NorthEast,
SouthEast,
SouthWest,
NorthWest
};
enum SpeakClasses {

View File

@ -62,18 +62,15 @@ void Creature::draw(int x, int y)
// 1000 * groundSpeed / playerSpeed
// TODO 1: FIX RENDER STEP 2
// TODO 2: FIX SHAKY EFFECT
// TODO 2: FIX DIAGONAL WALKING, BUGS MAP
// TODO 3: ADD ANIMATION
// TODO 4: ADD DIAGONAL WALKING
x += m_walkOffsetX;
y += m_walkOffsetY;
const ThingAttributes& attributes = getAttributes();
// Render creature
m_xDiv = m_direction;
for(m_yDiv = 0; m_yDiv < attributes.ydiv; m_yDiv++) {
// continue if we dont have this addon.
@ -117,13 +114,14 @@ void Creature::draw(int x, int y)
int pixelsWalked = std::floor((g_platform.getTicks() - m_lastTicks) / m_walkTimePerPixel);
int remainingTime = (g_platform.getTicks() - m_lastTicks) % (int)m_walkTimePerPixel;
if(m_direction == Otc::North)
if(m_direction == Otc::North || m_direction == Otc::NorthEast || m_direction == Otc::NorthWest)
m_walkOffsetY = std::max(m_walkOffsetY - pixelsWalked, 0);
else if(m_direction == Otc::East)
m_walkOffsetX = std::min(m_walkOffsetX + pixelsWalked, 0);
else if(m_direction == Otc::South)
else if(m_direction == Otc::South || m_direction == Otc::SouthEast || m_direction == Otc::SouthWest)
m_walkOffsetY = std::min(m_walkOffsetY + pixelsWalked, 0);
else if(m_direction == Otc::West)
if(m_direction == Otc::East || m_direction == Otc::NorthEast || m_direction == Otc::SouthEast)
m_walkOffsetX = std::min(m_walkOffsetX + pixelsWalked, 0);
else if(m_direction == Otc::West || m_direction == Otc::NorthWest || m_direction == Otc::SouthWest)
m_walkOffsetX = std::max(m_walkOffsetX - pixelsWalked, 0);
//double walkOffset = std::max(m_walkOffsetX, m_walkOffsetY);
@ -178,6 +176,7 @@ void Creature::walk(const Position& position)
m_walkOffsetX = 0;
m_walkOffsetY = 0;
m_walkingFromPosition = m_position;
int walkTimeFactor = 1;
// update map tiles
g_map.removeThingByPtr(asThing());
@ -201,11 +200,46 @@ void Creature::walk(const Position& position)
m_direction = Otc::West;
m_walkOffsetX = 32;
}
else if(m_walkingFromPosition + Position(1, -1, 0) == m_position) {
m_direction = Otc::NorthEast;
m_walkOffsetX = -32;
m_walkOffsetY = 32;
walkTimeFactor = 2;
}
else if(m_walkingFromPosition + Position(1, 1, 0) == m_position) {
m_direction = Otc::SouthEast;
m_walkOffsetX = -32;
m_walkOffsetY = -32;
walkTimeFactor = 2;
}
else if(m_walkingFromPosition + Position(-1, 1, 0) == m_position) {
m_direction = Otc::SouthWest;
m_walkOffsetX = 32;
m_walkOffsetY = -32;
walkTimeFactor = 2;
}
else if(m_walkingFromPosition + Position(-1, -1, 0) == m_position) {
m_direction = Otc::NorthWest;
m_walkOffsetX = 32;
m_walkOffsetY = 32;
walkTimeFactor = 2;
}
else { // Teleport
// we teleported, dont walk or change direction
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;
}
// get walk speed
int groundSpeed = 0;
@ -213,7 +247,7 @@ void Creature::walk(const Position& position)
if(ground)
groundSpeed = ground->getAttributes().speed;
float walkTime = 1000.0 * (float)groundSpeed / m_speed;
float walkTime = walkTimeFactor * 1000.0 * (float)groundSpeed / m_speed;
walkTime = walkTime == 0 ? 1000 : walkTime;
m_walkTimePerPixel = walkTime / 32.0;

View File

@ -87,6 +87,18 @@ void Game::walk(Otc::Direction direction)
case Otc::West:
m_protocolGame->sendWalkWest();
break;
case Otc::NorthEast:
m_protocolGame->sendWalkNorthEast();
break;
case Otc::SouthEast:
m_protocolGame->sendWalkSouthEast();
break;
case Otc::SouthWest:
m_protocolGame->sendWalkSouthWest();
break;
case Otc::NorthWest:
m_protocolGame->sendWalkNorthWest();
break;
}
}

View File

@ -47,6 +47,10 @@ public:
void sendWalkEast();
void sendWalkSouth();
void sendWalkWest();
void sendWalkNorthEast();
void sendWalkSouthEast();
void sendWalkSouthWest();
void sendWalkNorthWest();
void sendTurnNorth();
void sendTurnEast();
void sendTurnSouth();

View File

@ -102,6 +102,34 @@ void ProtocolGame::sendWalkWest()
send(oMsg);
}
void ProtocolGame::sendWalkNorthEast()
{
OutputMessage oMsg;
oMsg.addU8(0x6A);
send(oMsg);
}
void ProtocolGame::sendWalkSouthEast()
{
OutputMessage oMsg;
oMsg.addU8(0x6B);
send(oMsg);
}
void ProtocolGame::sendWalkSouthWest()
{
OutputMessage oMsg;
oMsg.addU8(0x6C);
send(oMsg);
}
void ProtocolGame::sendWalkNorthWest()
{
OutputMessage oMsg;
oMsg.addU8(0x6D);
send(oMsg);
}
void ProtocolGame::sendTurnNorth()
{
OutputMessage oMsg;
@ -129,5 +157,3 @@ void ProtocolGame::sendTurnWest()
oMsg.addU8(0x72);
send(oMsg);
}

View File

@ -52,6 +52,18 @@ bool UIMap::onKeyPress(uchar keyCode, char keyChar, int keyboardModifiers)
} else if(keyCode == Fw::KeyLeft || keyCode == Fw::KeyNumpad4) {
g_game.walk(Otc::West);
return true;
} else if(keyCode == Fw::KeyNumpad9) {
g_game.walk(Otc::NorthEast);
return true;
} else if(keyCode == Fw::KeyNumpad3) {
g_game.walk(Otc::SouthEast);
return true;
} else if(keyCode == Fw::KeyNumpad1) {
g_game.walk(Otc::SouthWest);
return true;
} else if(keyCode == Fw::KeyNumpad7) {
g_game.walk(Otc::NorthWest);
return true;
}
} else if(keyboardModifiers == Fw::KeyboardCtrlModifier) {
if(keyCode == Fw::KeyUp || keyCode == Fw::KeyNumpad8) {