Esempio n. 1
0
 def draw_line(self, coordA, coordB, char=('*', Pair.Yellow), includeFirst=False):
     if includeFirst:
         for coord in bresenham(coordA, coordB):
             self.draw_char(coord, char)
     else:
         for coord in bresenham(coordA, coordB):
             if coord != coordA:
                 self.draw_char(coord, char)
Esempio n. 2
0
 def draw_line(self,
               coordA,
               coordB,
               char=('*', Pair.Yellow),
               includeFirst=False):
     if includeFirst:
         for coord in bresenham(coordA, coordB):
             self.draw_char(coord, char)
     else:
         for coord in bresenham(coordA, coordB):
             if coord != coordA:
                 self.draw_char(coord, char)
Esempio n. 3
0
 def look(self):
     coord = self.coord
     drawline_flag = False
     direction = Dir.Stay
     while True:
         new_coord = add_vector(coord, direction)
         if self.actions.level.is_legal(new_coord):
             coord = new_coord
         self.io.msg(self.actions.level.look_information(coord))
         if drawline_flag:
             self.io.draw_line(self.coord, coord, ("*", Pair.Yellow))
             self.io.draw_line(coord, self.coord, ("*", Pair.Yellow))
             self.io.msg("LoS: {}".format(self.actions.level.check_los(self.coord, coord)))
         if coord != self.coord:
             symbol, (foreground, background) = self.actions.level.visible_char(coord)
             char = symbol, (foreground, Color.Green)
             self.io.draw_char(char, coord)
             self.io.draw_char(self.actions.level.visible_char(self.coord), self.coord, reverse=True)
         key = self.io.get_key()
         self.actions.redraw()
         direction = Dir.Stay
         if key in Bind.Directions:
             direction = Dir.from_key[key]
         elif key == 'd':
             drawline_flag = not drawline_flag
         elif key == 'b':
             from generic_algorithms import bresenham
             for coord in bresenham(self.actions.level.get_coord(self.coord), coord):
                 self.io.msg(coord)
         elif key == 's':
             if coord in self.actions.level.creatures:
                 self.actions.game.register_status_texts(self.actions.level.creatures[coord])
         elif key in Bind.Cancel or key in Bind.Look_Mode:
             break
Esempio n. 4
0
 def get_light_set(self, visibility_func, start_coord, sight):
     light_set = set()
     sight_squared = sight * sight
     start_y, start_x = start_coord
     for octant in range(8):
         mult_y_i = self._mult[0][octant]
         mult_x_i = self._mult[1][octant]
         mult_y_s = self._mult[2][octant]
         mult_x_s = self._mult[3][octant]
         for i in range(sight):
             for y, x in bresenham(
                     start_coord,
                 (start_y + sight * mult_y_s + i * mult_y_i,
                  start_x + sight * mult_x_s + i * mult_x_i)):
                 if sight_squared < ((start_y - y)**2 + (start_x - x)**2):
                     break
                 if (y, x) not in light_set:
                     light_set.add((y, x))
                 if not visibility_func((y, x)):
                     break
     return light_set
Esempio n. 5
0
 def check_los(self, coordA, coordB):
     return not (any(not self.is_see_through(coord) for coord in bresenham(coordA, coordB)) and
                 any(not self.is_see_through(coord) for coord in bresenham(coordB, coordA)))
Esempio n. 6
0
 def get_last_pathable_coord(self, coord_start, coord_end):
     last = None
     for coord in bresenham(coord_start, coord_end):
         if not self.is_pathable(coord):
             return last
         last = coord
Esempio n. 7
0
 def check_los(self, coordA, coordB):
     return not (any(not self.is_see_through(coord) for coord in bresenham(coordA, coordB)) and
                 any(not self.is_see_through(coord) for coord in bresenham(coordB, coordA)))
Esempio n. 8
0
 def get_last_pathable_coord(self, coord_start, coord_end):
     last = None
     for coord in bresenham(coord_start, coord_end):
         if not self.is_pathable(coord):
             return last
         last = coord