我正在为 Python 使用 turtle 模块,并且正在尝试制作游戏。我试图让一只乌龟射出另一只乌龟作为子弹。我无法弄清楚如何跟踪射手龟的xcor()
和ycor()
然后将子弹龟运送到那里。这是我的代码:
# Projectiles
bullet = turtle.Turtle()
bullet.hideturtle()
bullet.color('purple')
bullet.shape('circle')
bullet.penup()
bullet.shapesize(0.5, 0.5)
bulletspeed = 0
# The player
player = turtle.Turtle()
player.speed(0)
player.color('blue')
player.shape('triangle')
player.penup()
player.setposition(0, -250)
player.setheading(90)
x = player.xcor()
y = player.ycor()
ph = player.heading()
def right():
player.right(30)
def left():
player.left(30)
def increasespeed():
global speed
speed += 1
def decreasespeed():
global speed
speed -= 1
def bulletmove():
global bulletspeed
bullet.pos() == player.pos()
bullet.showturtle()
bulletspeed += 10
# Keybindings
turtle.listen()
turtle.onkey(left, 'Left')
turtle.onkey(right, 'Right')
turtle.onkey(increasespeed, 'Up')
turtle.onkey(decreasespeed, 'Down')
turtle.onkey(bulletmove, 'space')