1 """ Class holding the level info """
7 self.width = self.height = 0
13 self.start_pos = (0, 0)
16 self.enemy_generators = []
19 def get_neighbors(self, x, y):
20 # 4 -connected neighbors
21 return [self.tiles[y][x-1] if x > 0 else None,
22 self.tiles[y][x+1] if x < self.width - 1 else None,
23 self.tiles[y-1][x] if y > 0 else None,
24 self.tiles[y+1][x] if y < self.height - 1 else None]
26 def can_walk(self, x, y, layer):
27 if 'walk' in self.tiles[y][x][layer]['behaviour']:
29 for door in self.doors:
30 if (x, y) == door.game_pos and door.is_closed():
35 def can_fly(self, x, y, layer):
36 if 'fly' in self.tiles[y][x][layer]['behaviour']:
37 for door in self.doors:
38 if (x, y) == door.game_pos and door.is_closed():
44 def can_crawl(self, x, y, layer):
45 return 'crawl' in self.tiles[y][x][layer]['behaviour']
47 def is_keypad(self, x, y):
48 for keypad in self.keypads:
49 if (x, y) == keypad.game_pos:
53 def is_grate(self, x, y):
54 if (x, y) in self.grates:
58 def press_keypad(self, x, y, roaches):
59 for keypad in self.keypads:
60 if (x, y) == keypad.game_pos:
61 keypad.activate(roaches)
63 def get_friends(self):
64 return self._friends[:]
66 def friend_at(self, x, y):
67 for f in self.friends:
68 if f.game_pos == (x, y):
71 def remove_friend(self, friend):
72 self.friends.remove(friend)
74 def item_at(self, x, y):
76 if i.game_pos == (x, y):
79 def remove_item(self, item):
80 self.items.remove(item)
82 def is_exit(self, x, y):
83 return self.exit and (x, y) == tuple(self.exit["pos"])
85 def get_exit_level(self):
86 return self.exit["next level"]