Skip to main content
2 of 2
replaced http://gamedev.stackexchange.com/ with https://gamedev.stackexchange.com/

Answering question to provide full solution building on the answer from AtkinsSJ (thanks a lot for the nudge in the right direction) to address a couple of edge cases.

if( fIsNorthOrSouthWest )
{
    // Special case when the second position is to the left of the first

    if( rPos1.m_y % 2 == 0 )
    {
        nDistance = static_cast< int >( std::floor( ( nYDifferenceTiles / 2.0 ) + nXDifferenceTiles ) );
    }
    else
    {
        nDistance = static_cast< int >( std::ceil( ( nYDifferenceTiles / 2.0 ) + nXDifferenceTiles ) );
    }
}
else
{
    if( rPos1.m_y % 2 == 0 )
    {
        nDistance = static_cast< int >( std::ceil( ( nYDifferenceTiles / 2.0 ) + nXDifferenceTiles ) );
    }
    else
    {
        nDistance = static_cast< int >( std::floor( ( nYDifferenceTiles / 2.0 ) + nXDifferenceTiles ) );
    }
}
Konrad
  • 300
  • 1
  • 10