diff options
Diffstat (limited to 'tileset.py')
-rw-r--r-- | tileset.py | 14 |
1 files changed, 11 insertions, 3 deletions
@@ -5,6 +5,7 @@ import pygame class Tileset(object): TILESIZE = 16 + MAPSIZE = 50 RIGHT = 0 DOWN = 1 LEFT = 2 @@ -56,7 +57,14 @@ class Tileset(object): # read as array of 4-byte ints array = list(struct.unpack('<{}i'.format(len(data)/4), data)) loaded[name] = array + self.level_array = loaded['level'] + collidables = frozenset([6, 7, 8, 22, 24, 38, 39, 40]) + collisions = set() + for i, tile in enumerate(loaded['level']): + if tile in collidables: + y, x = divmod(i, self.MAPSIZE) + collisions.add((x, y)) units = { self.ENEMY1: [], @@ -64,15 +72,15 @@ class Tileset(object): } for i, tile in enumerate(loaded['units']): if tile in units.iterkeys(): - y, x = divmod(i, 50) + y, x = divmod(i, self.MAPSIZE) units[tile].append((x, y)) if len(units[self.PLAYER]) != 1: raise Exception('expected exactly 1 player tile in units layer, found ' + str(len(units[self.PLAYER]))) - return units + return collisions, units def render_level(self): for i, tile in enumerate(self.level_array): - y, x = divmod(i, 50) + y, x = divmod(i, self.MAPSIZE) x *= self.TILESIZE y *= self.TILESIZE tile_y, tile_x = divmod(tile - 1, self.TILESIZE) # those 1-indexing fuckers |