Ejemplo n.º 1
0
	def new_goal(self):
		self.m_goal[0]=random.randint(0,14)
		self.m_goal[2]=random.randint(0,14)
		
		pos = self.get_rounded_pos()
		
		while(pathfinding.point_on_obstacle(self.m_goal) or pathfinding.point_at_pos(self.m_goal,pos)):
			self.m_goal[0]=random.randint(0,14)
			self.m_goal[2]=random.randint(0,14)
		
		pathfinding.pathfind(pos,self.m_goal,self.m_path)
		
		self.m_step = 0
Ejemplo n.º 2
0
def startPathFind(*, grid, **kwargs):
    start_pos = (-1, -1)
    end_pos = (-1, -1)
    non_walkable = []
    for x, row in enumerate(grid):
        for y, pos in enumerate(row):
            if pos == 1 and start_pos == (-1, -1):
                start_pos = (x, y)
            if pos == 2 and end_pos == (-1, -1):
                end_pos = (x, y)
            if pos == 4:
                non_walkable.append((x, y))
    pathfind_grid = pathfinding.makeGrid(len(grid), len(grid[0]), non_walkable)
    pathfinding.pathfind(start_pos, end_pos, pathfind_grid)
    path = pathfinding.getPath(end_pos, pathfind_grid)
    for pos in path:
        grid[pos[0]][pos[1]] = 10
Ejemplo n.º 3
0
 def road_drag(self,  drag):
     if self.drag and drag:
         if self.road_end != ga.station_iso:
             self.road_end = ga.station_iso
             self.roadpath = ptf.pathfind(self.free_tiles, self.road_start, self.road_end)
             self.make_roadhints()
             
     elif self.drag :
         print self.roadpath
         self.drag = False
         for x,y in self.roadpath:
             if not isinstance(self.buildings[x][y],Road):
                 Road((x,y))
         for s in self.roadhints:
             s.kill()
Ejemplo n.º 4
0
 def turn(self, lines, enemies, avail):
     pr = self.app.player.row
     pc = self.app.player.col
     dirs = [(0, 1), (1, 0), (0, -1), (-1, 0)]
     for r, c in dirs:
         newR = self.row + r
         newC = self.col + c
         if (0 <= newR < len(lines) and 0 <= newC < len(lines[newR])
                 and pr == newR and pc == newC):
             self.app.player.damaged(self.damage)
             return
     if self.path == None or len(self.path) == 0:
         self.path = pathfinding.pathfind(avail, self.row, self.col, pr, pc)
         if self.path != None:
             if len(self.path) > 4:
                 self.path = self.path[:4]
             self.path.pop(0)
     if self.path != None:
         node = self.path.pop(0)
         self.move(node[0], node[1])
Ejemplo n.º 5
0
 def build(self):
     if self.loaded_build is Road:
         self.drag = True
         self.road_end = self.road_start = ga.stationGrid.get_iso(get_mousepos())
         self.roadpath = ptf.pathfind(self.free_tiles, self.road_start, self.road_end)
         
     elif self.loaded_build is Destroy:
         x,y = ga.station_iso
         building = self.buildings[x][y]
         if building and 0 <= x < ga.station.free_tiles.x_len and 0 <= y < ga.station.free_tiles.y_len:
             building.destroy()
             
     elif self.loaded_build is not None:
         anchor = ga.stationGrid.get_iso(get_mousepos())
         x,y = self.loaded_build.anchor
         pos = anchor[0] - x, anchor[1] - y
         size = self.loaded_build.size
         if self.loaded_build.check_free[0](pos, self.loaded_build):
             print self.loaded_build
             self.loaded_build(anchor)
Ejemplo n.º 6
0
 def __init__(self, app, player):
     self.app = app
     self.static, pr, pc, cr, cc = genLevel()
     while pathfinding.pathfind(self.notWall, pr, pc, cr, cc) == None:
         print("generation failed")
         self.static, pr, pc, cr, cc = genLevel()
     print(self.static)
     self.wall = app.loadImage(f"assets{os.sep}1BitPack{os.sep}wall.png")
     self.trap = app.loadImage(f"assets{os.sep}1BitPack{os.sep}trap.png")
     self.items = dict()
     self.items[(cr, cc)] = [item.genItem(self,"Crown")]
     self.enemies = set()
     self.toKill = []
     self.traps = set()
     self.genTraps(50)
     self.genEnemies(20)
     self.genItems("Sword", 5)
     self.genItems("Helmet", 5)
     self.genItems("Health Ring", 5)
     self.genItems("Health Pot", 10)
     self.genItems("Sharpening Kit", 10)
     self.player = player
     self.player.move(pr, pc)
     self.pTurn = True