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


Python Camera.update_camera方法代码示例

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


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

示例1: Level2State

# 需要导入模块: import Camera [as 别名]
# 或者: from Camera import update_camera [as 别名]
class Level2State(LevelState.LevelState):
    map = None
    player = None
    level_state_manager = None
    collider = None
    level_background_music = None
    main_menu = None
    camera = None
    timer = None

    # List to hold all the enemy objects.
    enemy_list = []

    # Spawn point of the player.
    player_spawn_x = 170
    player_spawn_y = 180

    # The X value on which the player needs
    # to be when starting to shift the map and stop shifting the map.
    shift_start = 410
    shift_end = 3290

    cloud_images = []

    # Half the width of the surface.
    # This is needed for the placement of the images/sprites.
    half_screen_width = Artist.get_half_screen_width()

    def __init__(self, level_state_manager, main_menu):
        self.enemy_list = []

        # The map variable is a TileGrid object.
        # The map contains an multidimensional array of tiles.
        # This creates the map
        self.map = TileGrid(DatabaseReceiver.get_level_data
                            ("TXT", "Level2", "Level2"))
        self.main_menu = main_menu
        self.LevelStateManager = level_state_manager

        # Create a player object with the x and y
        # value in which the player should spawn and the
        # LevelStateManager.
        self.player = Player(self.player_spawn_x,
                             self.player_spawn_y,
                             level_state_manager)

        # Statement to set the player_x variable in the map class.
        # It is necessary for the camera
        # that the map knows the x coordinate of the spawn point.
        self.map.set_player_x(self.player_spawn_x)

        # This variable creates the background of the level.
        # It uses the DatabaseReceiver to get the image from,
        # the database.
        self.background = Background(
            DatabaseReceiver.get_level_data(
                "IMAGE", "Level2", "BackgroundTwee"))

    def run(self):
        self.map.run()
        self.enemy_list = []

        # 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(Fish(580, 600, 110, 'Lava'))
        self.enemy_list.append(Fish(2570, 600, 400, 'Lava'))
        self.enemy_list.append(Slime(1736, 10))

        # 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)

        # 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 2.
        self.timer.load_best_time(2)

    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
#.........这里部分代码省略.........
开发者ID:jehoofd3,项目名称:ISCP,代码行数:103,代码来源:Level2State.py


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