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


Python Timer.update方法代码示例

本文整理汇总了Python中Timer.update方法的典型用法代码示例。如果您正苦于以下问题:Python Timer.update方法的具体用法?Python Timer.update怎么用?Python Timer.update使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Timer的用法示例。


在下文中一共展示了Timer.update方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Level1State

# 需要导入模块: import Timer [as 别名]
# 或者: from Timer import update [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.update方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。