def ladder_below(self, rect): test_rect = Rect((rect.left, rect.top + 1), (rect.width, rect.height)) colliding_ladders = list( filter((lambda ladder: test_rect.colliderect(ladder.rect)), self.ladders.values())) return colliding_ladders[0] if len(colliding_ladders) > 0 else None
def platform_right_adjacent(self, rect): test_rect = Rect((rect.right + 1, rect.top), (rect.width, rect.height)) colliding_platforms = list( filter((lambda platform: test_rect.colliderect(platform.rect)), self.platforms.values())) return colliding_platforms[0] if len(colliding_platforms) > 0 else None
def platform_below(self, rect): test_rect = Rect((rect.left, rect.top + 1), (rect.width, rect.height)) colliding_platforms = list( filter((lambda platform: test_rect.colliderect(platform.rect)), self.platforms.values())) return colliding_platforms[0] if len(colliding_platforms) > 0 else None
def get_entities_inside_region(self, rect: Rect): # return any entity, regardless of layer, that is intersecting with the given rect found = set() for layer in self.layers: for entity in self.layers[layer]: if rect.collidepoint(*entity.position) or rect.colliderect( entity.rect): found.add(entity) return list(found)