使用蟒蛇龟的乒乓球游戏中球拍的移动问题

问题描述 投票:0回答:1

乌龟没有反应。 对于我正在开发的乒乓球游戏,即使正确给出了关键值,球拍也没有响应。

我尝试了 onkeypress 以及 stackoverflow 上某人的建议,但仍然不起作用。 我在传递我没有包含的函数时也检查了()。

from turtle import Screen, Turtle
from paddle import Paddle

screen = Screen()
screen.setup(800, 600)
screen.bgcolor("black")
screen.title("My PONG")
screen.tracer(0)


r_paddle = Paddle()
r_paddle.goto(350, 0)
l_paddle = Paddle()
l_paddle.goto(-350, 0)

game_is_on = True

while game_is_on:
    screen.update()


screen.listen()
screen.onkeypress(r_paddle.go_up, "Up")
screen.onkeypress(r_paddle.go_down, "Down")
screen.onkeypress(l_paddle.go_up, "w")
screen.onkeypress(l_paddle.go_down, "s")


screen.exitonclick()
turtle-graphics python-turtle onkeyup pong
1个回答
0
投票
from turtle import Screen, Turtle
from paddle import Paddle

screen = Screen()
screen.setup(800, 600)
screen.bgcolor("black")
screen.title("My 🤪PONGIE😹")
screen.tracer(0)


r_paddle = Paddle()
r_paddle.goto(350, 0)
l_paddle = Paddle()
l_paddle.goto(-350, 0)


screen.listen()
screen.onkey(r_paddle.go_up, "Up")
screen.onkey(r_paddle.go_down, "Down")
screen.onkey(l_paddle.go_up, "w")
screen.onkey(l_paddle.go_down, "s")

game_is_on = True

while game_is_on:
    screen.update()


screen.exitonclick()
© www.soinside.com 2019 - 2024. All rights reserved.