Example #1
0
 def receives__look(self): 
   """return heading of first object seen"""
   
   # set up view poly
   self.Ax = 0.0
   self.Ay = 0.0
   self.Bx = (self.sight_distance * math.cos(math.radians(self.rotation - 45.0)))
   self.By = (self.sight_distance * math.sin(math.radians(self.rotation - 45.0)))
   self.Cx = (self.sight_distance * math.cos(math.radians(self.rotation + 45.0)))
   self.Cy = (self.sight_distance * math.sin(math.radians(self.rotation + 45.0)))    
   poly_x = [self.Ax, self.Bx, self.Cx]
   poly_y = [self.Ay, self.By, self.Cy]  
   
   # for every inhabitant
   for inhabitant in TheWorld.inhabitants:
     if inhabitant == self:
       continue
     # get pos of inhabitant relative to fov unit square coords
     Px = (inhabitant.x / self.width)  - (self.x / self.width)
     Py = (inhabitant.y / self.height) - (self.y / self.width)
     if MathLib.polygon_test(Px, Py, poly_x, poly_y):
       ret = 0.0
       Dx = inhabitant.x - self.x 
       Dy = inhabitant.y - self.y 
       ret = math.degrees(math.atan2(Dy, Dx))
       if ret < 0:
         ret += 360.0
       #print "I can see: ", inhabitant, "at", ret, "degrees"
       return ret - self.rotation