本文整理汇总了Python中Window.renderMenu方法的典型用法代码示例。如果您正苦于以下问题:Python Window.renderMenu方法的具体用法?Python Window.renderMenu怎么用?Python Window.renderMenu使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Window
的用法示例。
在下文中一共展示了Window.renderMenu方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Controller
# 需要导入模块: import Window [as 别名]
# 或者: from Window import renderMenu [as 别名]
class Controller(object):
"""
The Controller of the game
"""
def __init__(self):
"""
The Constructor of the Controller
"""
self.themeFactory = None
self.mapFile = self.__loadMap()
self.map = None
self.window = Window(len(self.mapFile[0]) * BaseTile.WIDTH, len(self.mapFile) * BaseTile.HEIGHT)
self.jukebox = Jukebox()
self.player = None
self.clock = pygame.time.Clock()
self.enemies = pygame.sprite.RenderPlain()
self.bullets = pygame.sprite.RenderPlain()
self.walls = pygame.sprite.RenderPlain()
self.pathfinder = Pathfinder()
self.players = pygame.sprite.RenderPlain()
self.collisionDetector = None
self.renderMenu = True
self.userInterface = None
def start(self):
"""
Starts the game by "starting" the infinite loop
:return:
"""
self.jukebox.playSound("menu")
while True:
# PROCESS INPUT
self.__handle_events()
# LOGIC STUFF
if self.renderMenu:
self.jukebox.playSound("menu")
self.__renderMenu()
elif self.player.life <= 0:
self.jukebox.playSound("dead")
self.userInterface.drawLostScreen()
else:
self.jukebox.playSound("game")
if self.player is not None:
self.player.move()
if pygame.time.get_ticks() % (1000 / self.map.amountHorizontal) is 0:
self.__spawnEnemy()
self.enemies.update(self.player, self.map)
self.bullets.update()
self.collisionDetector.checkCollisions()
# DRAW EVERYTHING
self.userInterface.draw()
self.__drawWorld()
pygame.display.flip()
self.clock.tick(30)
def __drawWorld(self):
"""
Draws all game objects
"""
self.map.sprites.draw(self.window.screen)
self.players.draw(self.window.screen)
self.enemies.draw(self.window.screen)
self.bullets.draw(self.window.screen)
self.userInterface.draw()
def __loadMap(self):
"""
Loads and generates the map
:return: the generated map
"""
mapGenerator = MapGenerator()
return mapGenerator.generateMap()
def __initPlayer(self):
"""
Builds the Player
:return: the player object
"""
tile = self.map.getWalkableTile()
player = self.themeFactory.createThemeElement("pl")
player.setCoordinates(tile.row, tile.col)
self.players.add(player)
return player
def __spawnEnemy(self):
"""
Spawns the enemy at a random spawn point
"""
tile = self.map.getSpawnPoint()
enemy = Enemy()
enemy.setCoordinates(tile.row, tile.col)
self.enemies.add(enemy)
#.........这里部分代码省略.........