diff options
author | raylu <ray.lu@getclever.com> | 2013-10-12 03:48:28 -0700 |
---|---|---|
committer | raylu <ray.lu@getclever.com> | 2013-10-12 03:51:01 -0700 |
commit | fe8e0249c1916c74eed97d9750b16b03e87953e7 (patch) | |
tree | 045d1ae8fd5be2797a4cd30140d2b0a1fddac902 /tileset.py | |
parent | b3dcf3217957b0b02e5f367d44dad14b66702ae4 (diff) | |
download | troll-fe8e0249c1916c74eed97d9750b16b03e87953e7.tar.xz |
collision detection!
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 |