コード例 #1
0
ファイル: HexMap.py プロジェクト: Stewie23/HexEngine
 def estimate(self, xDest, yDest):
     #convert to Hex Coordinate for easier calculation
     a = HexMath.convertArrayToHex(self.xPos,self.yPos)
     b = HexMath.convertArrayToHex(xDest,yDest)
     #calculate differenc beteween x and y values, and between does two
     dX =  b[0]-a[0]
     dY =  b[1]-a[1]
     dZ =  dY-dX
     return max((dX,dY,dZ))
コード例 #2
0
ファイル: HexMap.py プロジェクト: Stewie23/HexEngine
 def __init__(self,x,y,typ,map):
     self.map = map
     #array position
     self.x = x
     self.y = y
     #hex position
     hPos = HexMath.convertArrayToHex(self.x,self.y)
     self.hX = hPos[0]
     self.hY = hPos[1]
     #typ,for terrain
     self.typ = typ
     self.opacity = self.getOpacity()
     #calculate dimensions
     #calculate points
     self.center = self.setCenter()
     self.pointlist = self.setPoints()
     self.getCenterInt= (int(self.center[0]),int(self.center[1]))
     #test for caching intersection
     self.IntersectionCache = []
コード例 #3
0
ファイル: HexMap.py プロジェクト: Stewie23/HexEngine
    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