# HG changeset patch # User Gideon Visser # Date 1315799956 25200 # Node ID 915fd0ee28f50eab6ae9c06d795869342b9b4245 # Parent 45dd79e9ba1b5375b270810c84e3aafd7cc8bf45 Added test tile orientation diff -r 45dd79e9ba1b -r 915fd0ee28f5 mamba/level.py --- a/mamba/level.py Sun Sep 11 21:14:56 2011 +0200 +++ b/mamba/level.py Sun Sep 11 20:59:16 2011 -0700 @@ -73,6 +73,7 @@ class Level(object): def __init__(self, level_name): self.level_name = level_name + self.tiles_ascii = '' self.load_level_data() def load_level_data(self): @@ -83,6 +84,7 @@ tileset_name = level_data.readline().strip() self.tileset = Tileset(tileset_name) tiles_ascii = [line.strip() for line in level_data.readlines()] + self.tiles_ascii = tiles_ascii self.setup_tiles(tiles_ascii) self.make_background() @@ -96,6 +98,8 @@ raise InvalidMapError("Map not rectangular.") tile_row = [] for x, tile_char in enumerate(row): + tile_orientation = self.get_tile_orientation(y, x, row, tile_char) + print tile_orientation tile = self.tileset.get_tile(tile_char, (x, y), self.sprites) tile_row.append(tile) if isinstance(tile, EntrySprite): @@ -106,6 +110,46 @@ if self.entry is None: raise InvalidMapError("Not enough entry points.") + + def is_same_tile(self, tile, x, y): + """Is there a tile of the same type?""" + try: + temp_tile = self.tiles_ascii[y][x] + except IndexError: + return 'The map went out of range' + try: + return temp_tile == tile + except KeyError: + return 'The map tile is not existing' + + return self.get_bool(x, y, 'wall') + + #please note: planning on tile tuple to be -1, 0, 1 of x then y + def get_tile_orientation(self, map_y, map_x, row, tile_char): + #print "y: ", map_y, " x: ", map_x, " row: ", row, " tile_char: ", tile_char + #tile_char + if self.is_same_tile(tile_char, map_x, map_y): + # Draw different tiles depending on neighbourhood + if not self.is_same_tile(tile_char, map_x, map_y+1): + if self.is_same_tile(tile_char, map_x+1, map_y) and self.is_same_tile(tile_char, map_x-1, map_y): # + tile = 1, 2 + elif self.is_same_tile(tile_char, map_x+1, map_y): + tile = 0, 2 + elif self.is_same_tile(tile_char, map_x-1, map_y): + tile = 2, 2 + else: + tile = 3, 2 + else: + if self.is_same_tile(tile_char, map_x+1, map_y+1) and self.is_same_tile(tile_char, map_x-1, map_y+1): + tile = 1, 1 + elif self.is_same_tile(tile_char, map_x+1, map_y+1): + tile = 0, 1 + elif self.is_same_tile(tile_char, map_x-1, map_y+1): + tile = 2, 1 + else: + tile = 3, 1 + return tile + def get_tile_size(self): return self.tile_size