diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2021-12-12 16:07:27 +0100 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2021-12-12 16:07:27 +0100 |
| commit | 084ae1b47481743873fe3f65ba5c97c7b4ce3e06 (patch) | |
| tree | 90769a8fb21d3eb569c94ccdf675fd59dde5a330 /scripts | |
| parent | 994457141ed07cda1ff2d04c8adf61734d654d68 (diff) | |
| download | muhqs-game-084ae1b47481743873fe3f65ba5c97c7b4ce3e06.tar.gz muhqs-game-084ae1b47481743873fe3f65ba5c97c7b4ce3e06.zip | |
use selector to choose correct tower tile
A selector string contains all 4 directions: [left, right, up, down]
in that order.
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/generate_map_img.py | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/scripts/generate_map_img.py b/scripts/generate_map_img.py index a2bdf434..b8b1e225 100755 --- a/scripts/generate_map_img.py +++ b/scripts/generate_map_img.py @@ -16,6 +16,8 @@ SHOW_MAP = False Row = Sequence[str] Tiles = Sequence[Row] +FORTIFICATIONS = ['tower', 'gate', 'wall'] + def get_tile_path(tile: str) -> pathlib.Path: """Return the corresponding image file name for a tile""" @@ -117,7 +119,7 @@ def find_wall_tile(tiles: Sequence[Sequence[str]], x: int, y: int): left, right, above, below = is_connected_to(tiles, x, y, - kind=['wall', 'tower', 'gate']) + kind=FORTIFICATIONS) connections = count_connections(left, right, above, below) @@ -137,7 +139,7 @@ def find_wall_tile(tiles: Sequence[Sequence[str]], x: int, y: int): elif connections == 1 or (connections == 2 and ((left and right) or (above and below))): if above or below: - tile_img = cv2.imread(str(get_tile_path('wall_h'))) + tile_img = cv2.imread(str(get_tile_path('wall_lr'))) else: tile_img = cv2.imread(str(get_tile_path('wall'))) @@ -163,7 +165,7 @@ def find_gate_tile(tiles: Sequence[Sequence[str]], x: int, y: int): left, right, above, below = is_connected_to(tiles, x, y, - kind=['wall', 'tower']) + kind=FORTIFICATIONS) connections = count_connections(left, right, above, below) @@ -175,7 +177,7 @@ def find_gate_tile(tiles: Sequence[Sequence[str]], x: int, y: int): return cv2.imread(str(get_tile_path('gate'))) if left or right: - return cv2.imread(str(get_tile_path('gate_wall_h'))) + return cv2.imread(str(get_tile_path('gate_lr'))) return cv2.imread(str(get_tile_path('gate'))) @@ -185,7 +187,7 @@ def find_tower_tile(tiles: Sequence[Sequence[str]], x: int, y: int): left, right, above, below = is_connected_to(tiles, x, y, - kind=['wall', 'gate']) + kind=FORTIFICATIONS) connections = count_connections(left, right, above, below) @@ -193,18 +195,28 @@ def find_tower_tile(tiles: Sequence[Sequence[str]], x: int, y: int): if connections == 0: return cv2.imread(str(get_tile_path('tower'))) - if left and (not right and not is_right_edge(tiles, x, y)): - return cv2.imread(str(get_tile_path('tower_left_wall'))) + # generate connection selector + selector = '' + if left: + selector += 'l' + + if right: + selector += 'r' + + if above: + selector += 'u' - if right and (not left and not is_left_edge(tiles, x)): - return cv2.imread(str(get_tile_path('tower_right_wall'))) + # corner cases where tower is placed on the edge + if selector and 'r' not in selector and is_right_edge(tiles, x, y): + selector += 'r' - # We reach this if either right and left are connected or - # one side is connected and this tile is on the edge - if right or left: - return cv2.imread(str(get_tile_path('tower_in_wall'))) + if selector and 'l' not in selector and is_left_edge(tiles, x): + selector += 'l' - return cv2.imread(str(get_tile_path('tower'))) + tile_name = 'tower' + if selector: + tile_name = f'{tile_name}_{selector}' + return cv2.imread(str(get_tile_path(tile_name))) TILE_SELECTORS = { |
