當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。