Exemple #1
0
    def __init__(self, scene, start, end, manhattan=False):
        self.x,self.y = start
        self.scene = scene
        self.endradius = max( int( scene.distance( start, end ) // 3 ) , 1 )
        self.radius = int( scene.distance( start, end ) + self.endradius )
        self.manhattan = manhattan

        # Start with a ball
        proto_cone = set()
        for x in range( end[0]-self.endradius, end[0]+self.endradius+1):
            for y in range( end[1]-self.endradius, end[1]+self.endradius+1):
                if scene.distance( (x,y), end ) <= self.endradius:
                    proto_cone.add( (x,y) )

        # Draw lines back to origin.
        for t in range( -self.endradius, self.endradius+1 ):
            h_line = animobs.get_line( start[0], start[1], end[0]+t, end[1] )
            proto_cone.update( h_line )
            if t != 0:
                v_line = animobs.get_line( start[0], start[1], end[0], end[1]+t )
                proto_cone.update( v_line )

        # Determine the PFOV from origin.
        self.tiles = set()
        fieldOfView( start[0] , start[1] , scene.width , scene.height , self.radius , self )

        # The finished cone is the intersection of the two.
        self.tiles.intersection_update( proto_cone )
        self.tiles.remove( start )
Exemple #2
0
    def __init__(self, scene, start, end, manhattan=False):
        self.x, self.y = start
        self.scene = scene
        self.endradius = max(int(scene.distance(start, end) // 3), 1)
        self.radius = int(scene.distance(start, end) + self.endradius)
        self.manhattan = manhattan

        # Start with a ball
        proto_cone = set()
        for x in range(end[0] - self.endradius, end[0] + self.endradius + 1):
            for y in range(end[1] - self.endradius,
                           end[1] + self.endradius + 1):
                if scene.distance((x, y), end) <= self.endradius:
                    proto_cone.add((x, y))

        # Draw lines back to origin.
        for t in range(-self.endradius, self.endradius + 1):
            h_line = animobs.get_line(start[0], start[1], end[0] + t, end[1])
            proto_cone.update(h_line)
            if t != 0:
                v_line = animobs.get_line(start[0], start[1], end[0],
                                          end[1] + t)
                proto_cone.update(v_line)

        # Determine the PFOV from origin.
        self.tiles = set()
        fieldOfView(start[0], start[1], scene.width, scene.height, self.radius,
                    self)

        # The finished cone is the intersection of the two.
        self.tiles.intersection_update(proto_cone)
        self.tiles.remove(start)
 def draw_road_connection(self, gb, x1, y1, x2, y2):
     path = animobs.get_line(x1, y1, x2, y2)
     for p in path:
         self.fill(gb, pygame.Rect(p[0] - 2, p[1] - 2, 5, 5), wall=None)
         self.fill(gb,
                   pygame.Rect(p[0] - 1, p[1] - 1, 3, 3),
                   floor=maps.HIGROUND)
 def get_cover(self,x1,y1,x2,y2,vmode=movement.Vision):
     # x1,y1 is the viewer, x2,y2 is the target
     my_line = animobs.get_line(x1,y1,x2,y2)
     it = 0
     for p in my_line[1:]:
         if self.on_the_map(*p):
             it += self._map[p[0]][p[1]].get_cover(vmode)
     return it
Exemple #5
0
 def get_cover(self,x1,y1,x2,y2,vmode=movement.Vision):
     # x1,y1 is the viewer, x2,y2 is the target
     my_line = animobs.get_line(x1,y1,x2,y2)
     it = 0
     for p in my_line[1:]:
         if self.on_the_map(*p):
             it += self._map[p[0]][p[1]].get_cover(vmode)
     return it
Exemple #6
0
    def render(self, gb):
        if not self.area:
            raise RoomError("ROOM ERROR: No area found for {} in {}".format(
                self, gb))
        # Fill the floor with BASIC_FLOOR, and clear room interior
        self.fill(gb, self.area, floor=maps.BASIC_FLOOR)
        self.fill(gb, self.area.inflate(-2, -2), wall=None)
        # Set the four corners to basic walls
        gb.map[self.area.x][self.area.y].wall = maps.BASIC_WALL
        gb.map[self.area.x + self.area.width -
               1][self.area.y].wall = maps.BASIC_WALL
        gb.map[self.area.x][self.area.y + self.area.height -
                            1].wall = maps.BASIC_WALL
        gb.map[self.area.x + self.area.width -
               1][self.area.y + self.area.height - 1].wall = maps.BASIC_WALL

        # Draw each wall. Harder than it sounds.
        self.draw_wall(
            gb,
            animobs.get_line(self.area.x + 1, self.area.y,
                             self.area.x + self.area.width - 2, self.area.y),
            (0, -1))
        self.draw_wall(
            gb,
            animobs.get_line(self.area.x, self.area.y + 1, self.area.x,
                             self.area.y + self.area.height - 2), (-1, 0))
        self.draw_wall(
            gb,
            animobs.get_line(self.area.x + 1,
                             self.area.y + self.area.height - 1,
                             self.area.x + self.area.width - 2,
                             self.area.y + self.area.height - 1), (0, 1))
        self.draw_wall(
            gb,
            animobs.get_line(self.area.x + self.area.width - 1,
                             self.area.y + 1,
                             self.area.x + self.area.width - 1,
                             self.area.y + self.area.height - 2), (1, 0))
Exemple #7
0
 def get_area(self, camp, origin, target):
     tiles = animobs.get_line(origin[0], origin[1], target[0], target[1])
     tiles.remove(origin)
     return tiles
Exemple #8
0
 def get_area( self, camp, origin, target ):
     tiles = animobs.get_line( origin[0], origin[1], target[0], target[1] )
     tiles.remove( origin )
     return tiles
Exemple #9
0
 def draw_direct_connection(self, gb, x1, y1, x2, y2):
     path = animobs.get_line(x1, y1, x2, y2)
     for p in path:
         for x in range(p[0] - 1, p[0] + 2):
             for y in range(p[1] - 1, p[1] + 2):
                 self.draw_fuzzy_ground(gb, x, y)
Exemple #10
0
 def draw_road_connection( self, gb, x1,y1,x2,y2 ):
     path = animobs.get_line( x1,y1,x2,y2 )
     for p in path:
         self.fill( gb, pygame.Rect(p[0]-2,p[1]-2,5,5), wall=None )
         self.fill( gb, pygame.Rect(p[0]-1,p[1]-1,3,3), floor=maps.HIGROUND )