award xyz
So, this is so far what I've worked out, though I have yet to figure out how to get the third rotation and possible further rotations for possible higher variable values. This allows for the rotation left and right from the starting position and also the second rotation left and right after moving the required distance. I am still working on how to calculate for 3rd, 4th rotation possibilities.
func test_hex(shipPos):
var ship = local_to_map(shipPos)
var shipFace = snapped($Ship.transform.x,Vector2(0.5,0.5))
const faceN = Vector2(0.5,0); const faceNE = Vector2(0.5,0.5)
const faceSE = Vector2(-0.5,0.5); const faceS = Vector2(-0.5,0)
const faceSW = Vector2(-0.5,-0.5); const faceNW = Vector2(0.5,-0.5)
const SW = +Vector2i(-1,1); const NW = +Vector2i(-1,0); const N = +Vector2i(0,-1)
const NE = +Vector2i(1,-1); const SE = +Vector2i(1,0); const S = +Vector2i(0,1)
var face : Array = [null,faceN,faceNE,faceSE,faceS,faceSW,faceNW,null]
var left : Array = [SW,NW,N,NE,SE,S,SW,NW]
var dir : Array = [NW,N,NE,SE,S,SW,NW,N]
var right : Array = [N,NE,SE,S,SW,NW,N,NE]
var shipRot = 2; var rotCd = 0; var maxSpeed = 5
var cellPosD = ship
for a in get_used_cells_by_id(0,0,Vector2i(1,0),0):
set_cell(0,a,0,Vector2i(0,0),0)
for b in maxSpeed:
var moveable = Vector2i(1,0)
var i = face.find(shipFace)
var rotateR = cellPosD; var rotateL = cellPosD
var rotCdR = rotCd; var rotCdL = rotCd
var rotate
if get_cell_atlas_coords(0,(cellPosD + dir[i])) != moveable:
set_cell(0,(cellPosD + dir[i]),0,moveable,0)
cellPosD = cellPosD + dir[i]
if rotCdR == 0 and rotCdL == 0:
for numb in maxSpeed - b:
if Vector2(ship).distance_to(Vector2(rotateR + right[i])) >= shipRot:
rotate = true
else:
rotate = false
if get_cell_atlas_coords(0, rotateR + right[i]) != moveable:
set_cell(0,(rotateR + right[i]),0,moveable,0)
rotateR = rotateR + right[i]
if rotCdR != shipRot:
rotCdR += 1
if get_cell_atlas_coords(0, rotateL + left[i]) != moveable:
set_cell(0,(rotateL + left[i]),0,moveable,0)
rotateL = rotateL + left[i]
if rotCdL != shipRot:
rotCdL += 1
if rotCdL == shipRot and rotCdR == shipRot:
rotCdL = 0
rotCdR = 0
if rotate == true:
var extRotL = rotateL; var extRotR = rotateR
for numb1 in maxSpeed - (numb - b + 1):
if get_cell_atlas_coords(0, extRotL + left[i-1]) != moveable:
set_cell(0,(extRotL + left[i-1]),0,moveable,0)
extRotL = extRotL + left[i-1]
if get_cell_atlas_coords(0, extRotR + right[i+1]) != moveable:
set_cell(0,(extRotR + right[i+1]),0,moveable,0)
extRotR = extRotR + right[i+1]