X-Git-Url: https://git.ctpug.org.za/?p=erdslangetjie.git;a=blobdiff_plain;f=erdslangetjie%2Flevel.py;h=cbec02c35d899a7ceb18123891bd177b1add1b16;hp=d42cc71ea4b92f5eaf748a8633a1627eda3ef762;hb=64e0ef0f5aaa615ba6821a9924206b4d373e2a21;hpb=b3ffacfb066d8d4c84f782d8e2265bf497dadb56 diff --git a/erdslangetjie/level.py b/erdslangetjie/level.py index d42cc71..cbec02c 100644 --- a/erdslangetjie/level.py +++ b/erdslangetjie/level.py @@ -3,6 +3,11 @@ import os from data import load_image, load, filepath +WALL = '.' +FLOOR = ' ' +ENTRY = 'E' +EXIT = 'X' + class Level(object): @@ -25,12 +30,12 @@ class Level(object): for j, line in enumerate(self.data): tile_line = [] for i, c in enumerate(line): - if c == ' ': + if c == FLOOR: tile_line.append(load_image('tiles/floor.png')) - elif c == '.': - tile_line.append(load_image('tiles/wall.bmp')) - elif c == 'E' or c == 'X': - if c == 'E': + elif c == WALL: + tile_line.append(self.get_wall_tile(i, j)) + elif c == ENTRY or c == EXIT: + if c == ENTRY: if self.enter_pos: raise RuntimeError('Multiple entry points') self.enter_pos = (i, j) @@ -48,6 +53,58 @@ class Level(object): def at_exit(self, pos): return pos in self.exit_pos + def get_wall_tile(self, x, y): + # Is the neighbour in this direction also a wall? + left = right = top = bottom = False + if x == 0: + left = True + elif self.data[y][x - 1] == WALL: + left = True + if x == len(self.data[0]) - 1: + right = True + elif self.data[y][x + 1] == WALL: + right = True + if y == 0: + top = True + elif self.data[y - 1][x] == WALL: + top = True + if y == len(self.data) - 1: + bottom = True + elif self.data[y + 1][x] == WALL: + bottom = True + if top and bottom and left and right: + return load_image('tiles/cwall.png') + elif bottom and left and right: + return load_image('tiles/bottom_wall.png') + elif top and left and right: + return load_image('tiles/top_wall.png') + elif top and bottom and right: + return load_image('tiles/left_wall.png') + elif top and bottom and left: + return load_image('tiles/right_wall.png') + elif top and bottom: + return load_image('tiles/vert_wall.png') + elif left and right: + return load_image('tiles/horiz_wall.png') + elif left and top: + return load_image('tiles/corner_lt.png') + elif left and bottom: + return load_image('tiles/corner_lb.png') + elif right and top: + return load_image('tiles/corner_rt.png') + elif right and bottom: + return load_image('tiles/corner_rb.png') + elif top: + return load_image('tiles/end_top.png') + elif bottom: + return load_image('tiles/end_bottom.png') + elif left: + return load_image('tiles/end_right.png') + elif right: + return load_image('tiles/end_left.png') + return load_image('tiles/pillar.png') + + def blocked(self, pos): if pos[0] < 0: return True