因此,就上下文而言,我正在开发一个使用python海龟图形的射击游戏。我试图找到一些可以多次尝试的东西,但都没有用。例如,我试过
def direction():
wn.onkey(lambda: shuttle.setheading(90), 'Up')
wn.onkey(lambda: shuttle.setheading(180), 'Left')
wn.onkey(lambda: shuttle.setheading(0), 'Right')
wn.onkey(lambda: shuttle.setheading(270), 'Down')
direction()
bullet.setheading(direction())和
if bullet.distance(shuttle) < 15:
28 - if shuttle.setheading == 90:
29 - bullet.setheading(90)
30 - if shuttle.setheading == 180:
31 - bullet.setheading(180)
32 - if shuttle.setheading == 0:
33 - bullet.setheading(0)
34 - if shuttle.setheading == 270:
35 - bullet.setheading(270)我为电话号码道歉,但似乎太麻烦了,无法删除它们。
发布于 2020-07-23 15:31:01
假设你有两只海龟:turtle1和turtle2。若要将turtle2转到turtle1方向,请使用以下代码:
turtle2.setheading(turtle1.heading())FYI:在您的第一个代码片段中,direction返回None,因为它只添加事件,因此无法工作。
注意:我建议在游戏中使用tkinter,因为海龟是为教育用途而创建的,而且速度非常慢。
https://stackoverflow.com/questions/63057456
复制相似问题