Example #1
0
 def _free_line_of_sight(self, x0, y0, x1, y1):
     "Check if the line is free of cells blocking the light."
     line = get_line(x0, y0, x1, y1)
     for cell in line:
         if self[cell].block_light:
             return False
     return True
Example #2
0
 def clear_los(self, posA, posB):
     "Check if both objects have a clear line of sight"
     i0, j0 = posA
     i1, j1 = posB
     los = library.get_line(i0, j0, i1, j1)
     #other_ships = {pos:ship for pos, ship in self.entities['ships'].iteritems()
                     #if (ship is not objA and ship is not objB)}
     for cell in los:
         if cell in self.entities['asteroids'] or \
             cell in self.entities['ships'] and \
             cell != (i0, j0) and cell != (i1, j1):
             return False
     return True
Example #3
0
 def get_field_of_vision(self, x, y, radius):
     """
     Returns a list of tile coordinates in the field of vision.
     We first get a bounding circle around our position. Then we raycast lines
     going from the position (x, y) to the bounding circle. If we hit a block_light Tile,
     we make it visible and stop to look further on that ray.
     """
     points = set()
     border = self._get_bounding_circle(x, y, radius)
     for border_x, border_y in border:
         for tile_x, tile_y in get_line(x, y, border_x, border_y):
             points.add( (tile_x, tile_y) )
             if not self[tile_x, tile_y].block_light:
                 # To remove artifacts, check surrounding cells for a wall
                 points.update(self._reveal_adjacent_walls(tile_x, tile_y, x, y, radius))
             else:
                 break
     return points