collidrect 함수를 collidepoint함수로

코변·2022년 4월 26일
0

개발일지

목록 보기
8/41
 if enemy.rect.collidepoint(arrow.x_pos + ux, arrow.y_pos + uy):
            off_space = False
            arrow.x_pos = 2000
            arrow.y_pos = 2000
            pygame.time.delay(1500)
            self.state = 'clear'
            stage += 1
        # 화면에 그리기
        # 화살과 다른 쿼카가 부딪혔을 때 게임오버 페이지로 이동한다.
        quokka.rect.left = quokka.x_pos
        quokka.rect.top = quokka.y_pos
        if quokka.rect.collidepoint(arrow.x_pos + ux, arrow.y_pos + uy):
            off_space = False
            stage = 0
            on_game = False
            self.state = 'gameover'

colliderect 함수로 충돌검사를 하니 화살의 정확도도 떨어지고 충돌을 겹쳐서 인식하거나 제대로 인식하지 못하는 상태가 되었다. 그래서 collidepoint함수로 대체 하였고

start_ticks = pygame.time.get_ticks()
elapsed_time = (pygame.time.get_ticks() - start_ticks) / 1000
timer = game_font.render("Time : {}".format(int(total_time[stage] - elapsed_time)), True, (255,0,0))
screen.blit(timer, (screen_width -400 , 100))

시간을 표시해주는 타이머까지 설정하였다. 이제 화살 갯수를 표시하는 것까지 만들면 오늘 할 일은 마칠 것 같다. 좀만 더 힘내자!!

profile
내 것인 줄 알았으나 받은 모든 것이 선물이었다.

0개의 댓글