Example #1
0
def get_closest(playerlist):
    target = None    
    mindist = 99999.0

    pos = None
    
    mypos = server.get_pos()
    for plr in playerlist:
        dist = distance(mypos, (plr[1], plr[2]))
        if dist < mindist:
            target = plr[0]
            offset = (0.0, 0.0)
            if plr[9]:
                offset = mathlib.rot(plr[5] / 5.0, 0.0, plr[3]) 
            pos = (plr[1] + offset[0], plr[2] + offset[1])
            mindist = dist
    
    return target, pos, mindist        
Example #2
0
 if old_target != target_id:
     #print target_id, mypos, pos, dist
     old_pos = pos
 if target_id == None:
     server.do(True, 0, True, 0)
 else:
     if pos != None and mypos != None:
         dist = distance(pos, mypos) 
                 
         thrust = False
         fire = False
         turn_left = False
         turn_right = False
         
         if dist > 75:
             thrust = True
             
         dirvec = mathlib.rot(1.0, 0.0, server.get_dir())
         adiff = mathlib.anglediff(mypos[0], mypos[1], pos[0], pos[1], dirvec[0], dirvec[1])
         if abs(adiff) > 0.1:
             if adiff < 0:
                 turn_right = True
             else:
                 turn_left = True
                 
         if server.get_has_shot() and dist < 500 and abs(adiff) < 0.2 - ((0.15 / 400) * dist):
             fire = True
         
         server.do(turn_left, turn_right, thrust, fire)