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


Python Window.renderMenu方法代码示例

本文整理汇总了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)

#.........这里部分代码省略.........
开发者ID:divid3byzero,项目名称:zompy,代码行数:103,代码来源:Controller.py


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