X-Git-Url: https://git.ctpug.org.za/?p=koperkapel.git;a=blobdiff_plain;f=koperkapel%2Fgamelib%2Flevel.py;h=bcc319a2886d2f5e530d30ff70be6f7f50478a09;hp=8c93baabb6533feb99f1f7ed50cbc547a28724d7;hb=5729b7d89f992ba3d5b3f779ecc1094a48a85459;hpb=466427cad130565731effa9aff3fe5b9a6fb1d68 diff --git a/koperkapel/gamelib/level.py b/koperkapel/gamelib/level.py index 8c93baa..bcc319a 100644 --- a/koperkapel/gamelib/level.py +++ b/koperkapel/gamelib/level.py @@ -6,19 +6,81 @@ class Level(object): def __init__(self): self.width = self.height = 0 self.tiles = [] + self.keypads = [] + self.doors = [] + self.grates = [] self.tileset = None self.start_pos = (0, 0) + self.exit = None + self.enemies = [] + self.enemy_generators = [] + self.friends = [] def get_neighbors(self, x, y): # 4 -connected neighbors return [self.tiles[y][x-1] if x > 0 else None, self.tiles[y][x+1] if x < self.width - 1 else None, self.tiles[y-1][x] if y > 0 else None, - self.tiles[y+1][x] if y < self.height- 1 else None, - ] + self.tiles[y+1][x] if y < self.height - 1 else None] def can_walk(self, x, y, layer): - return 'walk' in self.tiles[y][x][layer]['behaviour'] + if 'walk' in self.tiles[y][x][layer]['behaviour']: + # check doors + for door in self.doors: + if (x, y) == door.game_pos and door.is_closed(): + return False + return True + return False def can_fly(self, x, y, layer): - return 'fly' in self.tiles[y][x][layer]['behaviour'] + if 'fly' in self.tiles[y][x][layer]['behaviour']: + for door in self.doors: + if (x, y) == door.game_pos and door.is_closed(): + return False + return True + + return False + + def can_crawl(self, x, y, layer): + return 'crawl' in self.tiles[y][x][layer]['behaviour'] + + def is_keypad(self, x, y): + for keypad in self.keypads: + if (x, y) == keypad.game_pos: + return True + return False + + def is_grate(self, x, y): + if (x, y) in self.grates: + return True + return False + + def press_keypad(self, x, y, roaches): + for keypad in self.keypads: + if (x, y) == keypad.game_pos: + keypad.activate(roaches) + + def get_friends(self): + return self._friends[:] + + def friend_at(self, x, y): + for f in self.friends: + if f.game_pos == (x, y): + return f + + def remove_friend(self, friend): + self.friends.remove(friend) + + def item_at(self, x, y): + for i in self.items: + if i.game_pos == (x, y): + return i + + def remove_item(self, item): + self.items.remove(item) + + def is_exit(self, x, y): + return self.exit and (x, y) == tuple(self.exit["pos"]) + + def get_exit_level(self): + return self.exit["next level"]