def getTilebyHex(self,Pos):#get a Tile using hex coords arrayPos = HexMath.convertHexToArray(Pos[0], Pos[1]) return self.getTile((arrayPos[0],arrayPos[1]))
def getCachedLineIntersections(self,startPos,endPos): ReturnList = [] #move on to right for offset startPos = (startPos[0]+1,startPos[1]) endPos = (endPos[0]+1,endPos[1]) #convert to hex coord for easier calculation startPos = HexMath.convertArrayToHex(startPos[0],startPos[1]) endPos = HexMath.convertArrayToHex(endPos[0],endPos[1]) #get direction of line #since the hex tile from where the cached lines are casted is considerd to be the top left hex #there are some cases that need special threadment direction = self.getDirecetion(startPos, endPos) dx = 0 dy = 0 #if direction == 2,swap start and endPos if direction == 2 or direction ==4 or direction ==6: startPos,endPos = endPos,startPos if direction == 3 or direction == 4: dx = endPos[0] - startPos[0] dy = endPos[1] - startPos[1] endPos = (startPos[0] + dy,startPos[1] +dx)#swap dx and dy if direction == 5 or direction == 6: dx = endPos[0] - startPos[0] endPos = (startPos[0],startPos[1]+dx) #get end pos adjusted for offset (startPos) mEndPos = (endPos[0]-startPos[0],endPos[1]-startPos[1]) #convert to array mEndPosarray = HexMath.convertHexToArray(mEndPos[0], mEndPos[1]) #get path Path = self.nodes[mEndPosarray[1]][mEndPosarray[0]+1]#+1 for offset #adjust for offset for i,Node in enumerate(Path): my = dy * i if Node[0] == 1: mNode = HexMath.convertArrayToHex(Node[1][0],Node[1][1]) mNode = (mNode[0]+ (startPos[0]-1),mNode[1] + (startPos[1] -1)) if direction ==5 or direction ==6: #cant happen with two nodes mNode = (mNode[0]+i,mNode[1]-i) mNode = HexMath.convertHexToArray(mNode[0],mNode[1]) mNode = (mNode[0]-1,mNode[1]-my) ReturnList.append((1,mNode)) if Node[0] == 2: mNode = HexMath.convertArrayToHex(Node[1][0],Node[1][1]) mNode = (mNode[0]+ (-1),mNode[1]+ (startPos[1]-1)) mNode = HexMath.convertHexToArray(mNode[0],mNode[1]) mNode = (mNode[0]-1,mNode[1]-my) #second mNode2 = HexMath.convertArrayToHex(Node[2][0],Node[2][1]) mNode2 = (mNode2[0]+ (startPos[0]-1),mNode2[1]+ (startPos[1] -1)) mNode2 = HexMath.convertHexToArray(mNode2[0],mNode2[1]) mNode2 = (mNode2[0]-1,mNode2[1]-my) ReturnList.append((2,mNode,mNode2)) if direction == 2 or direction == 4 or direction ==6: ReturnList.reverse() print ReturnList