1 """ Definitions for the various tile types """
6 from pygame.transform import rotate
8 from pgzero.loaders import images
16 def image(cls, neighbors):
17 if cls.IMG is None or cls.TILESET is None:
18 raise NotImplementedError()
19 return images.load(os.path.join(cls.TILESET, cls.IMG))
21 class OrientatedTile(Tile):
25 def image(cls, neighbors):
26 if cls.IMG is None or cls.TILESET is None:
27 raise NotImplementedError()
28 img = images.load(os.path.join(cls.TILESET, cls.IMG))
30 img = rotate(img, cls.ANGLE)
34 class RandomizedTile(Tile):
40 def image(cls, neighbors):
41 if cls.IMGDIR is None or cls.TILESET is None:
42 raise NotImplementedError()
44 imgdir = os.path.join(os.path.dirname(__file__), '..', 'images',
45 cls.TILESET, cls.IMGDIR)
46 imgpath = os.path.splitext(random.choice(os.listdir(imgdir)))[0]
47 img = images.load(os.path.join(cls.TILESET, cls.IMGDIR, imgpath))
50 img = rotate(img, 90 * random.randint(0, 3))
54 class Floor(RandomizedTile):
57 class Wall(RandomizedTile):
60 class Underground(RandomizedTile):
61 IMGDIR = "underground"
64 IMG = os.path.join('grate', 'grate')
69 IMG = os.path.join('exit', 'exit')
73 class Tunnel(OrientatedTile):
76 def image(cls, neighbors):
77 connections = [True if 'crawl' in x['behaviour'] else False for x in neighbors]
78 conn_count = connections.count(True)
82 # return single point tunnel
83 cls.IMG = os.path.join('tunnel', 'tunnel_none')
86 cls.IMG = os.path.join('tunnel', 'tunnel_crossroads')
88 # 1 point connector, roatated correctly
89 cls.IMG = os.path.join('tunnel', 'tunnel_1way')
90 # because of the ordering of neighbors, we use this formulation
91 for x, angle in zip(connections, (90, 270, 0, 180)):
96 # 3 point connector, rotated correctly
97 cls.IMG = os.path.join('tunnel', 'tunnel_3way')
98 # find the missing connection.
99 for x, angle in zip(connections, (0, 180, 270, 90)):
103 elif conn_count == 2:
104 # Need to distinguish pass-through or corner, and
106 # neighbors is left, right then up, down
107 if connections[0] == connections[1]:
108 cls.IMG = os.path.join('tunnel', 'tunnel_passthrough')
112 cls.IMG = os.path.join('tunnel', 'tunnel_corner')
128 return super(Tunnel, cls).image(neighbors)