当前位置: 首页>>代码示例>>Python>>正文


Python Surface.get_tile_by_position方法代码示例

本文整理汇总了Python中surface.Surface.get_tile_by_position方法的典型用法代码示例。如果您正苦于以下问题:Python Surface.get_tile_by_position方法的具体用法?Python Surface.get_tile_by_position怎么用?Python Surface.get_tile_by_position使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在surface.Surface的用法示例。


在下文中一共展示了Surface.get_tile_by_position方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: update_neighbors_list

# 需要导入模块: from surface import Surface [as 别名]
# 或者: from surface.Surface import get_tile_by_position [as 别名]
		def update_neighbors_list(tile):

			neighbors = []

			neighbor_left = Surface.get_tile_by_position((tile.x - tile.width, tile.y))
			neighbor_right = Surface.get_tile_by_position((tile.x + tile.width, tile.y))
			neighbor_top = Surface.get_tile_by_position((tile.x, tile.y - tile.height))
			neighbor_botton = Surface.get_tile_by_position((tile.x, tile.y + tile.height))

			if check_neighbor(neighbor_left):
				neighbors.append(neighbor_left)

			if check_neighbor(neighbor_right):
				neighbors.append(neighbor_right)

			if check_neighbor(neighbor_top):
				neighbors.append(neighbor_top)

			if check_neighbor(neighbor_botton):
				neighbors.append(neighbor_botton)

			return neighbors
开发者ID:mmoreirasouza,项目名称:pythonzombiegame,代码行数:24,代码来源:astar.py

示例2: get_path

# 需要导入模块: from surface import Surface [as 别名]
# 或者: from surface.Surface import get_tile_by_position [as 别名]
	def get_path(enemy):

		for tile in Surface.Tiles:
			tile.parent = None
			tile.g = 0
			tile.h = 0
			tile.f = 0

		open_list = []
		close_list = []
		neighbors = []
		path = []


		enemy_tile = Surface.get_tile_by_position((enemy.x, enemy.y))
		player_tile = Surface.get_tile_by_position((enemy.player.x, enemy.player.y))

		open_list.append(enemy_tile)

		def check_neighbor(tile):

			if tile != None and tile.walk == True:
				return True
			else:
				return False

		def update_neighbors_list(tile):

			neighbors = []

			neighbor_left = Surface.get_tile_by_position((tile.x - tile.width, tile.y))
			neighbor_right = Surface.get_tile_by_position((tile.x + tile.width, tile.y))
			neighbor_top = Surface.get_tile_by_position((tile.x, tile.y - tile.height))
			neighbor_botton = Surface.get_tile_by_position((tile.x, tile.y + tile.height))

			if check_neighbor(neighbor_left):
				neighbors.append(neighbor_left)

			if check_neighbor(neighbor_right):
				neighbors.append(neighbor_right)

			if check_neighbor(neighbor_top):
				neighbors.append(neighbor_top)

			if check_neighbor(neighbor_botton):
				neighbors.append(neighbor_botton)

			return neighbors

		while open_list:

			tile_min_f = min(open_list, key = lambda p : p.g + p.h)

			open_list.remove(tile_min_f)
			close_list.append(tile_min_f)

			if tile_min_f == player_tile:

				while tile_min_f.parent != None:

					path.append(tile_min_f)
					tile_min_f = tile_min_f.parent

				return path
				

			neighbors = update_neighbors_list(tile_min_f)

			for neighbor in neighbors:

				if neighbor in close_list:
					continue

				else:

					if neighbor in open_list:

						new_g = tile_min_f.g + 10

						if new_g < neighbor.g:

							neighbor.g = new_g
							neighbor.parent = tile_min_f						

					else:

						neighbor.g = tile_min_f.g + 10
						neighbor.h = math.sqrt((player_tile.x - neighbor.x)**2 + (player_tile.y - neighbor.y)**2)
						neighbor.f = neighbor.g + neighbor.h
						neighbor.parent = tile_min_f
						open_list.append(neighbor)

		return path
开发者ID:mmoreirasouza,项目名称:pythonzombiegame,代码行数:95,代码来源:astar.py


注:本文中的surface.Surface.get_tile_by_position方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。