Thursday, July 4, 2019

2d - How do I rotate a structure of hexagonal tiles on a hexagonal grid?



My 2D isometric game uses a hexagonal grid map. In reference to the image below, how do I rotate the light blue hexagon structures by 60 degrees around the pink hexagons?


http://www.algonet.se/~afb/spriteworld/ongoing/HexMap.jpg


EDIT:


Main hex is (0,0). Other hexes are children, count of them is fixed. I'm going to define only one position (in this case its right) and calculate other directions if needed (left-bottom, right-botom, right-top, left-top and left). Other hexes are defined like: Package.Add(-1,0), Package.Add(-2,0) and so on.


enter image description here


switch(Direction)
{
case DirRightDown:
if(Number.Y % 2 && Point.X % 2)
Number.X += 1;

Number.Y += Point.X + Point.Y / 2;

Number.X += Point.X / 2 - Point.Y / 1.5;
break;
}

In this code Number is the main hex and Point is the hex that I want to rotate, but it doesn't work:


enter image description here




No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...