본문 바로가기

개발 기록/자동 포스팅 프로그램

기믹 추가 내용 정리

다시 몇 가지 기믹을 추가하는데 성공하였다.

 

아래는 그러한 기믹들의 내용과 구현 방법에 대한 정리이다.

 

class ConnectGimmick(GimmickStrategy):
    def __init__(self):
        self.collision_point_list = []

    def apply(self, ball, border, game):
        for point in self.collision_point_list:
            pygame.draw.line(game.screen, ball.color, (int(point.x), int(point.y)), ball.position, 2)

    def add(self, ball, border, game):
        direction = ball.position - border.center
        distance = direction.length()
        normal = direction.normalize()
        overlap = distance - border.radius
        collision_point = ball.position - overlap * normal  # 충돌 지점 계산
        if collision_point:
            self.collision_point_list.append(collision_point)

 

선 연결 기믹이다.

 

충돌 시 호출되어 충돌한 위치를 리스트에 저장한 다음 매 순간 적용되어 충돌 지점과 원의 중심을 연결하는 선을 긋는다.

 

class SoundGimmick(GimmickStrategy):
    def __init__(self, sound_file):
        self.sound_file = sound_file

    def apply(self, ball, border, game):
        sound_effect = pygame.mixer.Sound(self.sound_file)
        sound_effect.play()

 

소리 기믹이다. 충돌 시 호출되어 지정 소리를 낸다.

 

필수 기믹들은 거의 완성되었다.

 

Tracer 기믹의 성능을 향상시키고 녹화하는 것이 이제 주요 과제이다. 거기까지 하고나면 이후 자동 업로드를 구현하여 경과를 지켜볼 것이다.