def extract_collision_objects_from_tile_layers( tmx_data: pytmx.TiledMap, collision_layer_names: List[str]) -> List[pygame.Rect]: collison_objects = list() for layer_name in collision_layer_names: collision_layer = tmx_data.get_layer_by_name(layer_name) for x in range(collision_layer.width): for y in range(collision_layer.height): image = tmx_data.get_tile_image(x, y, 1) if image: collison_objects.append( pygame.Rect( x * tmx_data.tilewidth, y * tmx_data.tileheight, tmx_data.tilewidth, tmx_data.tileheight, )) return collison_objects
view_offset = [332.0, -1100.0] tmx_data = TiledMap(resource_path(os.path.join("data", "test_map.tmx")), image_loader=pygame_sdl2_image_loader) tile_width = tmx_data.tilewidth tile_height = tmx_data.tileheight tile_dimensions = [tile_width, tile_height] tile_map = [] for y in range(0, tmx_data.height): tile_col = [] for x in range(0, tmx_data.width): layer_index = 0 tile_layer = [] for layer in tmx_data.visible_layers: y_offset = layer.offsety image = tmx_data.get_tile_image(y, x, layer_index) new_tile = None if image is not None: position = [ (y * tile_width / 2) - (x * tile_width / 2), (x * tile_height / 2) + (y * tile_height / 2) + y_offset ] if layer_index == 0 or layer_index == 1: # for ground tiles use highest point of tile, tile_base_position = position[ 1] + 32 # we always want to be on top of these render_order_sort_value = tile_base_position else: # for objects tiles try using the centre point of diamond tile_centre_position = position[1] + 48 - y_offset + ( (layer_index - 1) * 0.01) render_order_sort_value = tile_centre_position new_tile = Tile([x, y], position, image,