파이썬 터틀 충돌판정은 어떻게 해야하나요?

조회수 1347회

터틀그래픽 안에서 간단한 리듬게임을 만드려보려 합니다. 노트내려올때 밑에 키가 올라오면서 충돌할때 점수카운트하고 싶어 코드를 작성하였으나 함수가 정상적으로 작동을 하지 않습니다. 노트가 내려오는 함수부터 제대로 되지 않은것같기도 싶어서 한번 여쭤보고싶습니다.

//from turtle import *
#게임 창 설정
screen=Screen()
screen.setup(500, 750)

check1 = -screen.window_height() / 2 + 75
check2 = -screen.window_width() / 2 + 10
check3 = screen.window_width() / 2 - 10

#판정선 그리기
checkline=Turtle()
checkline.penup()
checkline.goto(check2, check1)
checkline.pendown()
checkline.goto(check3, check1)

#리듬게임에서 쓰는 키 선언
t1=Turtle()
t2=Turtle()
t3=Turtle()
t4=Turtle()

t1.penup()
t2.penup()
t3.penup()
t4.penup()

#키 모양 선언
t_w = 120 / 2
t_h = 20 /2
t_s = Shape("compound")
t_pp=((-t_w, -t_h), (-t_w, t_h), (t_w, t_h), (t_w, -t_h))
t_s.addcomponent(t_pp, "red")
screen.register_shape("hit", t_s)

t1.shape("hit")
t2.shape("hit")
t3.shape("hit")
t4.shape("hit")

t1.lt(90)
t1.setx(check2 + 60)
t1.sety(check1 - 40)

t2.lt(90)
t2.setx(check2 + 180)
t2.sety(check1 - 40)

t3.lt(90)
t3.setx(check2 + 300)
t3.sety(check1 - 40)

t4.lt(90)
t4.setx(check2 + 420)
t4.sety(check1 - 40)

#콤보 글씨 삽입
combo=Turtle()
combo.penup()
combo.hideturtle()
combo.color("blue")
combo_count=0

def count_combo() :
    combo.clear()
    combo.goto(-screen.window_width()/2 + 250, screen.window_height()/2 -80)
    combo.write("COMBO", align = "center", font=("Arial", 32, "bold"))
    combo.goto(-screen.window_width() / 2 + 250, screen.window_height() / 2 - 140)
    combo.write(combo_count, align="center", font=("Arial", 52, "bold"))

#노드생성
nw = 120 / 2
nh = 20 /2
ns = Shape("compound")
np=((-nh, -nw), (-nh, nw), (nh, nw), (nh, -nw))
ns.addcomponent(np, "blue")
screen.register_shape("node", ns)

nodes=Turtle()
nodes.penup()
nodes.hideturtle()
nodes.goto(-180, 300)
nodes.showturtle()
nodes.shape("node")


#노트 떨어지기 모션
def nodefall():
    nodes.goto(-180, -300)

# 점수 계산
def counting() :
    if nodefall():
        if nodes.distance(-180, -300) == 0:
            if t1.distance(check2+60, check1) ==0:
                combo_count+=1
                count_combo()
            else:
                combo_count += -1
                count_combo()


#리듬키 작동시키기      
def key1_press_action():
    t1.goto(check2 + 60, check1)
    t1.goto(check2 + 60, check1 - 40)

def key2_press_action():
    t2.goto(check2 + 180, check1)
    t2.goto(check2 + 180, check1 - 40)

def key3_press_action():
    t3.goto(check2 + 300, check1)
    t3.goto(check2 + 300, check1 - 40)

def key4_press_action():
    t4.goto(check2 + 420, check1)
    t4.goto(check2 + 420, check1 - 40)

screen.onkeypress(key1_press_action, "d")
screen.onkeypress(key2_press_action, "f")
screen.onkeypress(key3_press_action, "j")
screen.onkeypress(key4_press_action, "k")
screen.listen()

count_combo()
nodefall()
counting()
  • (•́ ✖ •̀)
    알 수 없는 사용자

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)