Jump to content
  • Advertisement

VictorErmakov

Member
  • Content count

    0
  • Joined

  • Last visited

Community Reputation

100 Neutral

About VictorErmakov

  • Rank
    Newbie
  1. VictorErmakov

    Coordinates in Hexagon-Based Tile Maps

    Thanks for useful info. I can propose my C++ implementation for you algorithm. In my case i use inverted grid (X -> Y). [code] u32 SectX = (ScrPosition.X + m_CameraScroll.X) / (float)MAP_TILE_WIDTH / 0.75f; u32 SectY = (ScrPosition.Y + m_CameraScroll.Y) / (float)MAP_TILE_HEIGHT; u32 SectPxlX = (TScreenPosition.X + m_CameraScroll.X) % (int)((float)MAP_TILE_WIDTH * 0.75f); u32 SectPxlY = (TScreenPosition.Y + m_CameraScroll.Y) % MAP_TILE_HEIGHT; m_GridPosition.X = SectX; m_GridPosition.Y = SectY; if(SectX%2) { // right side if(SectPxlY >= (float)MAP_TILE_HEIGHT / 2.0f) { if(SectPxlX < (2 * (float)MAP_TILE_WIDTH * 0.25f - SectPxlY * 0.5)) { m_GridPosition.X = SectX - 1; m_GridPosition.Y = SectY; } else { m_GridPosition.X = SectX; m_GridPosition.Y = SectY; } } // left side if(SectPxlY < (float)MAP_TILE_HEIGHT / 2.0f) { if(SectPxlX < (SectPxlY * 0.5f)) { m_GridPosition.Y = SectY; m_GridPosition.X = SectX - 1; } else { m_GridPosition.Y = SectY - 1; m_GridPosition.X = SectX; } } } else { // middle m_GridPosition.Y = SectY; m_GridPosition.X = SectX; // left Edge if(SectPxlX < ((float)MAP_TILE_WIDTH * 0.25f - SectPxlY * 0.5f)) { m_GridPosition.Y = SectY - 1; m_GridPosition.X = SectX - 1; } // right Edge if(SectPxlX < (- (float)MAP_TILE_WIDTH * 0.25f + SectPxlY * 0.5f)) { m_GridPosition.Y = SectY; m_GridPosition.X = SectX - 1; } } [/code]
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!