Пример #1
0
    def birth_babies(self):
        '''
        Once this asteroid has been hit, before it is removed from the asteroid list, call
        this function and it will return the two child asteroids (if it is a large or medium asteroid)
        with the correct velocity / momentum / ect. or it will return nothing if the asteroid cannot be broken anymore
        '''
        convFactor = math.pi / 180
        theta_1 = 45
        theta_2 = 315
        # No need to translate because the directions are already based on the 0,0 origin
        # Asteroid Baby 1
        new_x_1 = self.direction.x * math.cos(
            theta_1 * convFactor) - self.direction.y * math.sin(
                theta_1 * convFactor)
        new_y_1 = self.direction.x * math.sin(
            theta_1 * convFactor) + self.direction.y * math.cos(
                theta_2 * convFactor)
        # Asteroid Baby 2
        new_x_2 = self.direction.x * math.cos(
            theta_2 * convFactor) - self.direction.y * math.sin(
                theta_2 * convFactor)
        new_y_2 = self.direction.x * math.sin(
            theta_2 * convFactor) + self.direction.y * math.cos(
                theta_2 * convFactor)

        dir1 = Vector((new_x_1, new_y_1))
        dir2 = Vector((new_x_2, new_y_2))

        dir1 = dir1._mult(ASTEROID_BREAK_SPEED_FACTOR)
        dir2 = dir2._mult(ASTEROID_BREAK_SPEED_FACTOR)

        # Create dummy babies with dummy position lists (alter code later to avoid needing this)
        dummy_positions = [0, 1, 2]
        dummy_positions = (dummy_positions, dummy_positions)
        new_size = self.size - 1
        baby_1, baby_2 = Asteroid(dummy_positions,
                                  size=new_size), Asteroid(dummy_positions,
                                                           size=new_size)

        baby_1.location = self.location
        baby_2.location = self.location

        baby_1.direction = dir1
        baby_2.direction = dir2

        baby_1.x_class = baby_1.direction.classify_direction(direction='x')
        baby_1.y_class = baby_1.direction.classify_direction(direction='y')

        baby_2.x_class = baby_2.direction.classify_direction(direction='x')
        baby_2.y_class = baby_2.direction.classify_direction(direction='y')

        return baby_1, baby_2