예제 #1
0
def generate_sprites(map_object, layer_name, scaling, base_directory=""):
    sprite_list = SpriteList()

    if layer_name not in map_object.layers_int_data:
        print(f"Warning, no layer named '{layer_name}'.")
        return sprite_list

    map_array = map_object.layers_int_data[layer_name]

    # Loop through the layer and add in the wall list
    for row_index, row in enumerate(map_array):
        for column_index, item in enumerate(row):
            if str(item) in map_object.global_tile_set:
                tile_info = map_object.global_tile_set[str(item)]
                filename = base_directory + tile_info.source

                my_sprite = Sprite(filename, scaling)
                my_sprite.right = column_index * (map_object.tilewidth * scaling)
                my_sprite.top = (map_object.height - row_index) * (map_object.tileheight * scaling)

                if tile_info.points is not None:
                    my_sprite.set_points(tile_info.points)
                sprite_list.append(my_sprite)
            elif item != 0:
                print(f"Warning, could not find {item} image to load.")

    return sprite_list
예제 #2
0
def _move_sprite(moving_sprite: arcade.Sprite, platforms: arcade.SpriteList,
                 dt):

    if moving_sprite.bottom <= 0 and moving_sprite.change_y < 0:
        moving_sprite.change_y = 0
        moving_sprite.bottom = 0

    moving_sprite.center_y += moving_sprite.change_y * moving_sprite.speed_multiplier * (
        dt / (1 / 60))

    hit_list_y = arcade.check_for_collision_with_list(moving_sprite, platforms)

    for platform in hit_list_y:
        if platform.color != moving_sprite.current_background:
            if moving_sprite.change_y > 0:
                if not platform.change_y:
                    moving_sprite.top = platform.bottom
                    moving_sprite.change_y = 0

            elif moving_sprite.change_y < 0:
                moving_sprite.bottom = platform.top
                if platform.change_y:
                    if platform.change_y < 0:
                        moving_sprite.center_y -= 2
                        moving_sprite.change_y = -3
                    else:
                        moving_sprite.change_y = 0
                else:
                    moving_sprite.change_y = 0
                if platform.change_x:
                    moving_sprite.momentum = platform.change_x

    moving_sprite.center_x += (moving_sprite.change_x + moving_sprite.momentum
                               ) * moving_sprite.speed_multiplier * (dt /
                                                                     (1 / 60))

    hit_list_x = arcade.check_for_collision_with_list(moving_sprite, platforms)

    for platform in hit_list_x:
        if platform.color != moving_sprite.current_background and platform not in hit_list_y:
            if moving_sprite.change_x > 0 and not platform.change_x:
                moving_sprite.right = platform.left
            elif moving_sprite.change_x < 0 and not platform.change_x:
                moving_sprite.left = platform.right

            if platform.change_y:
                if platform.change_y >= 0:
                    moving_sprite.change_x = 0
            else:
                moving_sprite.change_x = 0

    if len(hit_list_y) <= 0 and moving_sprite.momentum != 0:
        moving_sprite.change_x += moving_sprite.momentum
        moving_sprite.momentum = 0
예제 #3
0
def generate_sprites(map_object: TiledMap,
                     layer_name: str,
                     scaling: float,
                     base_directory="") -> SpriteList:
    """
    generate_sprites has been deprecated. Use arcade.tilemap.process_layer instead.
    Generate the sprites for a layer in a map.

    :param TiledMap map_object: Map previously read in from read_tiled_map function
    :param layer_name: Name of the layer we want to generate sprites from. Case sensitive.
    :param scaling: Scaling factor.
    :param base_directory: Directory to read images from. Defaults to current directory.
    :return: List of sprites
    :rtype: SpriteList
    """
    from warnings import warn
    sprite_list = SpriteList()

    if layer_name not in map_object.layers_int_data:
        print(f"Warning, no layer named '{layer_name}'.")
        return sprite_list

    map_array = map_object.layers_int_data[layer_name]

    # Loop through the layer and add in the wall list
    for row_index, row in enumerate(map_array):
        for column_index, item in enumerate(row):
            if str(item) in map_object.global_tile_set:
                tile_info = map_object.global_tile_set[str(item)]
                tmx_file = base_directory + tile_info.source

                my_sprite = Sprite(tmx_file, scaling)
                my_sprite.right = column_index * (map_object.tilewidth *
                                                  scaling)
                my_sprite.top = (map_object.height -
                                 row_index) * (map_object.tileheight * scaling)

                if tile_info.points is not None:
                    my_sprite.set_points(tile_info.points)
                sprite_list.append(my_sprite)
            elif item != 0:
                print(f"Warning, could not find {item} image to load.")

    return sprite_list