【发布时间】:2026-02-19 12:05:02
【问题描述】:
我一直在尝试做一个小游戏(足球中的点球),其中球向侧面移动,直到您按下按钮并且球向前移动直到它与球门柱在同一条线上,但是球也在移动快速原因我使用循环。我想知道是否有什么东西可以减慢。谢谢大家
tela = turtle.Screen()
tela.tracer(0)
tela.bgcolor("black")
tela.title("Jogo de Futebol")
tela.setup(width= 800, height= 600)
# Creating ball
bola = turtle.Turtle()
bola.speed(0)
bola.up()
bola.color("white")
bola.shape("circle")
bola.goto(0, -250)
# TGoalpost
trave_central = turtle.Turtle()
trave_central.speed(0)
trave_central.up()
trave_central.color("white")
trave_central.shape("square")
trave_central.goto(0, 300)
trave_central.shapesize(stretch_wid=2, stretch_len=15)
# For ball move foward
def bola_frente():
y = bola.ycor()
y += 10
bola.sety(y)
# Ball speed
bola.dx = 1
bola.dy = 1
time = 0
# Loop do jogo
while True:
tela.update()
# Making ball go sideways
bola.setx(bola.xcor() + bola.dx)
if bola.xcor() > 380:
bola.dx *= -1
if bola.xcor() < -380:
bola.dx *= -1
if bola.ycor() > 280:
bola.goto(0, -250)
# Ball moving foward
tela.listen()
tela.onkey(bola_frente, "w ")
if bola.ycor() != -250:
bola.dx = 0
while True:
bola_frente()
if bola.ycor() == trave_central.ycor():
bola.goto(0, -250)
bola.dx = 1
break
【问题讨论】: