-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDungeon.py
28 lines (22 loc) · 845 Bytes
/
Dungeon.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from cocos.tiles import RectMapLayer, RectCell, TileSet
class Dungeon(RectMapLayer):
def __init__(self, width, height, th=16, tw=16):
self.tile_set = TileSet.from_atlas("ground", 0, "img/tileset_min_cave.png", tw, th)
# make every cell collidable
properties = {'top': True, 'bottom': True, 'right': True, 'left': True}
cells = []
for i in range(width):
c = []
for j in range(height):
tile = self.tile_set[3]
cell = RectCell(i, j, tw, th, properties, tile)
c.append(cell)
cells.append(c)
super(Dungeon, self).__init__('cave', tw, th, cells)
def make_walkable(self, walkable):
for tile in walkable:
cell = self.get_cell(*tile)
if cell is not None:
# walkable area should not be collidable
cell['top'] = cell['bottom'] = cell['right'] = cell['left'] = False
cell.tile = self.tile_set[0]