示例#1
0
文件: Main.py 项目: csharrison/ASTAR
 def set_path(self, grid, end):
     "sets a path for the guy to follow"
     self.goal = end # reset the goal
     
     #create a path using A* and smooth it up with the smoothing function
     #draw stuff as well in these functions
     self.path = create_path(self.loc,end,grid,self.screen)
     #self.path = make_smooth(self.loc, self.path, grid, self.screen)
     
     #sometimes the path will be empty
     if len(self.path)>0:
         self.calculate_direction()#calculate the initial direction
     pygame.display.flip()#update the screen
示例#2
0
    def set_path(self, grid1,grid2, end,targetImage):
        """
        function        : sets a path for the source to follow
        @ grid1         : first layer
        @ grid2         : second layer
        @ end           : target node
        @ targetImage   : image of target
        """

        #create a path using A* 
        self.path = create_path(self.loc,end,grid1,grid2,self.screen,False,targetImage)
        grid1[self.rloc[0]/10][self.rloc[1]/10] = False # make the source as a wall for next path
        selfPathLength = len(self.path)

        #To delete the already formed line to avoid from further calculation
        for i in range(0,selfPathLength):               
            grid1[self.path[i][0]][self.path[i][1]] = False
        
        if selfPathLength == 0:
            # if no path found, draw the grid
            for r in xrange(1,100):
                pygame.draw.line(self.screen,(0,0,0),(r*10,0),(r*10,1000),1)
                pygame.draw.line(self.screen,(0,0,0),(0,r*10),(1000,r*10),1)
                pygame.display.flip()

            # try to find the path in second layer
            self.path = create_path(self.loc,end,grid1,grid2,self.screen,True,targetImage)
            grid2[self.rloc[0]/10][self.rloc[1]/10] = False   # make the source as a wall for next path

            selfPathLength = len(self.path)
            
            #To delete the already formed line to avoid from further calculation
            for i in range(0,selfPathLength):
                grid2[self.path[i][0]][self.path[i][1]] = False
        
        pygame.display.flip()