def is_border_collision(self, object): """ check a collision between disk and a border of the pitch :param object: object with x,y,radius parameters :return: 'x' or 'y' if the collision between a disk/mallet and the border of pitch have taken place, false - if it haven't :raise: WrongTypeException if object is not type of disc/mallet """ # TODO: Is there a way to do it better ? if not isinstance(object, Disc) and not isinstance(object, Mallet): Logger.error("PITCH: is_border_collision raised WrongTypeException") raise WrongTypeException if object.pos.x - object.radius < self.i_min or object.pos.x + object.radius > self.i_max: Logger.debug("PITCH: is_border_collision return x") return 'x' if object.pos.y - object.radius < self.j_min or object.pos.y + object.radius > self.j_max: Logger.debug("PITCH: is_border_collision return y") return 'y' Logger.debug("PITCH: is_border_collision return False") return False
def load_image(self, image1, image2): """ Method used to load sprite for Mallet according to Player. :return: None """ from Player import Player if self._player.playerColor == Player.PLAYER_BLUE: Logger.debug("MALLET: load_image playerColor = PLAYER_BLUE") image = image1 elif self._player.playerColor == Player.PLAYER_RED: Logger.debug("MALLET: load_image playerColor = PLAYER_RED") image = image2 else: Logger.error("MALLET: Invalid value for player (" + self._player.playerColor + ")") raise ValueError('Invalid value for player (' + self._player.playerColor + ')') self._image = pygame.transform.scale( pygame.image.load(image), (int(2 * self.radius), int(2 * self.radius)))