Hello Atom again, I tried(with Freebasic) easy way to allow tiles rotations.
Tiles in gridmatrix has 2 properties, tile index and rotation value (4 different possibilities = top, right, bottom,left)
When rotate 90 degrees to clockwise its just reading TopRightBottomLeft values one shifted left, so I made 4 arrays for those, RotMat {0,1,2,3}, {3,0,1,2},{2,3,0,1},{1,2,3,0}. 0=top 1=right 2=bottom 3=left.
Random number 0-3 defines rotation, 0=0, 1=90,2=180,3=270 degrees.
Declare Function DirectionType (y As Integer, x As Integer, direction As Integer) As Integer
Dim Grid(10,10) As Integer
Type gridtiles
tile As Integer 'index to tiles
rotvalue As Integer '0-3
End Type
Type alltiles
rotation As Integer 'is tile rotatable
Dir_TRBL(3) As Integer '0=Top 1=Right 2=Bottom 3=Left
End Type
Dim Shared gridtile(10,10) As gridtiles
Dim Shared Tiles(10) As alltiles
Dim Shared RotMat(0 To 3, 0 To 3) As Integer => {{0,1,2,3}, {3,0,1,2},{2,3,0,1},{1,2,3,0}}
Dim t As Integer
Dim As Integer tile, x, y,z, direction,rot
'tile 0 properties
t = 0
Tiles(t).rotation = 0
Tiles(t).Dir_TRBL(0) = 0
Tiles(t).Dir_TRBL(1) = 1
Tiles(t).Dir_TRBL(2) = 0
Tiles(t).Dir_TRBL(3) = 0
'tile 1 properties
t = 1
Tiles(t).rotation = 0
Tiles(t).Dir_TRBL(0) = 0
Tiles(t).Dir_TRBL(1) = 0
Tiles(t).Dir_TRBL(2) = 0
Tiles(t).Dir_TRBL(3) = 1
'Direction types examples
'type 0 = grass
'type 1 = road
'type 2 = water
'--------------------------------------------
'Set tiles to grid and add property for rotation
gridtile(0,0).tile = 0
gridtile(0,0).rotvalue = 0
gridtile(0,1).tile = 1
gridtile(0,1).rotvalue = 1
'==========================================
'read grid tiles direction types
x = 0
y = 0
For y = 0 To 0
For x = 0 To 1
Print "tile";gridtile(y,x).tile
'all directions (4)
For z = 0 To 3
direction = DirectionType(y,x,z)
Print "tile direction";direction
Next
next
next
'==========================================
Sleep
Private Function DirectionType (y As Integer, x As Integer, direction As Integer) As Integer
Dim As Integer tile, rot, direct
'Tile index
tile = gridtile(y,x).tile
'Rotation value 0-3, 0 = no rotation
rot = gridtile(y,x).rotvalue
'Right Direction type, 1 = right
direct = Tiles(tile).Dir_TRBL(RotMat(rot,direction))
Return direct
End Function