本文整理汇总了Python中maze.Maze.load_level方法的典型用法代码示例。如果您正苦于以下问题:Python Maze.load_level方法的具体用法?Python Maze.load_level怎么用?Python Maze.load_level使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类maze.Maze
的用法示例。
在下文中一共展示了Maze.load_level方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: game_loop
# 需要导入模块: from maze import Maze [as 别名]
# 或者: from maze.Maze import load_level [as 别名]
def game_loop(self):
"""Main loop. """
pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
score = 0
high_score = 0
maze = Maze(self.maze_tiles, HORIZONTAL_TILES, VERTICAL_TILES)
maze.load_level(maze.MAZE)
pac = PacMan(104, 204, self.pacman_tiles)
delta = (0, 0)
while True:
event = pygame.event.poll()
if event.type == pygame.QUIT:
sys.exit(0)
if event.type == pygame.KEYUP:
if event.key == pygame.K_ESCAPE:
sys.exit(0)
pressed = pygame.key.get_pressed()
if pressed[pygame.K_LEFT]:
delta = (-1, 0)
elif pressed[pygame.K_RIGHT]:
delta = (1, 0)
elif pressed[pygame.K_DOWN]:
delta = (0, 1)
elif pressed[pygame.K_UP]:
delta = (0, -1)
x, y = self.screen_to_tile(pac.x, pac.y)
if maze[(x, y)] > 0:
score += 10
maze[(x, y)] = 0
if score > high_score:
high_score = score
if self.legal_move(maze, pac, delta):
pac.delta = delta
elif not self.legal_move(maze, pac, pac.delta):
pac.delta = (0, 0)
pac.move()
maze.draw()
pac.draw()
self.write_message(3, 0, "1UP")
self.write_message(4, 1, str(score))
self.write_message(9, 0, "HIGH SCORE")
self.write_message(10, 1, str(score))
pygame.display.flip()