當前位置: 首頁>>代碼示例>>Python>>正文


Python Timer.draw方法代碼示例

本文整理匯總了Python中Timer.draw方法的典型用法代碼示例。如果您正苦於以下問題:Python Timer.draw方法的具體用法?Python Timer.draw怎麽用?Python Timer.draw使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Timer的用法示例。


在下文中一共展示了Timer.draw方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: Level1State

# 需要導入模塊: import Timer [as 別名]
# 或者: from Timer import draw [as 別名]

#.........這裏部分代碼省略.........
        self.cloud_images.append(img.Image(
            DatabaseReceiver.get_level_data(
                "IMAGE", "Level1", "cloud1"), 1200, 300, 0.5))
        self.cloud_images.append(img.Image(
            DatabaseReceiver.get_level_data(
                "IMAGE", "Level1", "cloud2"), 1500, 250, 0.5))
        self.cloud_images.append(img.Image(
            DatabaseReceiver.get_level_data(
                "IMAGE", "Level1", "cloud3"), 2000, 500, 0.5))

    def run(self):
        self.map.run()

        # Make the enemy objects and add every enemy to the enemy_list.
        # Every enemy takes a x and y coordinate as argument.
        # (Spawn point)
        # And the range it can walk on the x axis.
        # The fish takes a third argument.
        # You got two choices: 'Water' or 'Lava'.
        # According to the fish you want.
        self.enemy_list.append(Fly(500, 600, 100))
        self.enemy_list.append(Fly(1500, 100, 100))
        self.enemy_list.append(Tank(2600, 50, 380))
        self.enemy_list.append(Fish(1000, 700, 200, 'Water'))

        # Add a collider for the enemies and the player.
        # It takes the player, map group(tiles),
        # an array with all the enemy objects, Reference to
        # LevelStateManager
        # as arguments.
        self.collider = Collider(self.player, self.map.get_group(),
                                 self.enemy_list, self.LevelStateManager)

        # Load the background music.
        # The pygame.mixer.music.load
        # method takes the file location as an argument.
        # It has to be .wav or .mp3.
        self.level_background_music = \
            pygame.mixer.music.load('../Data/Music/Level4_2.mp3')

        # Play the background music.
        # This is only necessary in level1,
        # because we don't stop the music when creating level2.
        pygame.mixer.music.play()

        # Create a camera for this level.
        self.camera = Camera(self.shift_start, self.shift_end,
                             self.map, self.player, self.enemy_list)

        # Create a timer for this level.
        self.timer = Timer()

        # Load the best time of level 1.
        self.timer.load_best_time(1)

    def update(self):
        # Update the camera with the player's x speed.
        self.camera.update_camera(self.player.x_speed)
        self.timer.update()

        self.player.update()

        # Update all the enemies in the enemy_list.
        self.enemy_list = self.collider.enemy_list
        for e in self.enemy_list:
            e.update()

        self.collider.update()

        self.background.update(self.player.x_speed, 0, self.player.rect.x)

        # Update the clouds.
        for image in self.cloud_images:
            image.update(self.player.x_speed, 0, self.player.rect.x)

        # Opens the MainMenu when you press on the escape key.
        if pygame.key.get_pressed()[pygame.K_ESCAPE]:
            self.LevelStateManager.level_state = self
            self.LevelStateManager.states = self.main_menu

    def draw(self):
        self.background.draw()

        # Draw all the clouds on the surface.
        for cloud in self.cloud_images:
            cloud.draw()

        self.map.draw()

        # Draw all the enemies.
        for e in self.enemy_list:
            e.draw()

        self.player.draw()
        self.timer.draw()

    # Reset the best time with the given level.
    # The best time is in the lower right corner of all the levels.
    def reset_best_time(self):
        self.timer.reset_best_time(1)
開發者ID:jehoofd3,項目名稱:ISCP,代碼行數:104,代碼來源:Level1State.py


注:本文中的Timer.draw方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。