def get_highest_tile(tiles, direction, start_abs, end_abs):
"""
Returns the `highest` tile in a list (row or column) of sloped, full-collision or empty tiles.
:param list tiles: the list of tiles to check
:param str direction: the direction in which the list of tiles is arranged (x=row of tiles or y=column of tiles)
:param int start_abs: the absolute leftmost x-value from where to check
:param int end_abs: the absolute rightmost x-value from where to check
:return: a tuple consisting of a) the highest SlopedTileSprite found in the list and b) the height value measured on a cartesian y-axis (positive=up)
:rtype: Tuple[SlopedTileSprite,int]
"""
# start with leftmost tile (measure max height for the two x points: sprite's leftmost edge and tile's right edge)
best_tile = None # the highest tile in this row (if not height==0.0)
tile = tiles[0]
if tile:
max_y = max(tile.get_y(start_abs - tile.rect.left), tile.get_y(tile.rect.width))
best_tile = tile
else:
max_y = 0
# then do all center tiles
for slot in range(1, len(tiles) - 1):
tile = tiles[slot]
max_ = tile.max_y if tile else 0
if max_ > max_y:
max_y = max_
best_tile = tile
# then do the rightmost tile (max between tiles left edge and sprite's right edge)
tile = tiles[-1]
max_ = max(tile.get_y(end_abs - tile.rect.left), tile.get_y(0)) if tile else 0
if max_ > max_y:
max_y = max_
best_tile = tile
# TODO: store x-in and y-pull(push) in tile props (as temporary values)
return best_tile, max_y
评论列表
文章目录