Example #1
0
    def canAshootB(self, tank1Id, tank2Id):
        tank1 = self.tanks[tank1Id]
        tank2 = self.tanks[tank2Id]

        ## Check if in range
        distance = mathHelper.distanceBetween(tank1['position'], tank2['position'])
        if (distance > PROJECTILE_RANGE + tank2['hitRadius']):
            return False

        ## Check that we are pointing at it
        angle = mathHelper.angleFromAToB(tank1['position'], tank2['position'])
        offset = math.asin(tank2['hitRadius']/distance)
        if (not mathHelper.angleInRange(tank1['turret'], angle + offset, angle - offset)):
            return False

        ## get the end point for tank1's range
        endPoint = mathHelper.getLineEndpoint(tank1['position'], distance, tank1['turret'])

# Don't want to check if other tanks are blocking because they could move
##        ## Check that no other tanks are in the way
##        for tank in self.tanks:
##            ## Don't consider the original 2 tanks
##            if (tank['id'] == tank1Id or tank['id'] == tank2Id):
##                continue
##            if (mathHelper.circleOnLine(tank1['position'], endPoint, tank['position'], tank['hitRadius'])):
##                return False

        ## Ensure path is clear of solids
        if self.isShotClear(tank1['position'], endPoint):
            return True

        return False
Example #2
0
    def canAshootB(self, tank1Id, tank2Id):
        tank1 = self.tanks[tank1Id]
        tank2 = self.tanks[tank2Id]

        ## Check if in range
        distance = mathHelper.distanceBetween(tank1["position"], tank2["position"])
        if distance > PROJECTILE_RANGE + tank2["hitRadius"]:
            return False

        ## Check that we are pointing at it
        angle = mathHelper.angleFromAToB(tank1["position"], tank2["position"])
        offset = math.asin(tank2["hitRadius"] / distance)
        if not mathHelper.angleInRange(tank1["turret"], angle + offset, angle - offset):
            return False

        ## get the end point for tank1's range
        endPoint = mathHelper.getLineEndpoint(tank1["position"], distance, tank1["turret"])

        # Don't want to check if other tanks are blocking because they could move
        ##        ## Check that no other tanks are in the way
        ##        for tank in self.tanks:
        ##            ## Don't consider the original 2 tanks
        ##            if (tank['id'] == tank1Id or tank['id'] == tank2Id):
        ##                continue
        ##            if (mathHelper.circleOnLine(tank1['position'], endPoint, tank['position'], tank['hitRadius'])):
        ##                return False

        ## Ensure path is clear of solids
        if self.isShotClear(tank1["position"], endPoint):
            return True

        return False
Example #3
0
    def correlationAtoB(self, tankA, tankB):
        result = {
            'tankA': tankA,
            'tankB': tankB
            }
        result['distance'] = mathHelper.distanceBetween(tankA['position'], tankB['position'])
        result['angle'] = mathHelper.angleFromAToB(tankA['position'], tankB['position'])

        return result
Example #4
0
    def correlationAtoB(self, tankA, tankB):
        result = {"tankA": tankA, "tankB": tankB}
        result["distance"] = mathHelper.distanceBetween(tankA["position"], tankB["position"])
        result["angle"] = mathHelper.angleFromAToB(tankA["position"], tankB["position"])

        return result