May-16-2020, 01:52 AM
Below is some code from a tutorial for making pong with Turtle. I noticed that the short presses of "w" and "s" move the left paddle instantaneously, whereas there is a 1 second delay for the paddle to move when I long press (or hold down one of the keys). Is there a way to make long press responses equally fast, or is it just something that has to be accepted with using Turtle?
#Jimmy. 5-13-20 Pong, base on tutorial by Christian Thompson #His twitter is @TokyoEdTech import turtle wn = turtle.Screen() wn = turtle.Screen() wn.title("Pong by Jimmy") wn.bgcolor("black") wn.setup(width=800, height=600) wn.tracer(0) # stops window from update, requiring manual update. # Paddle A paddle_a = turtle.Turtle() paddle_a.speed(0) # sets animation speed to maximum. paddle_a.shape("square") paddle_a.color("white") paddle_a.shapesize(stretch_wid=5, stretch_len =1) paddle_a.penup() #something to do with not drawing lines. (which Turtle object do by default). paddle_a.goto(-350,0) # Paddle B paddle_b = turtle.Turtle() paddle_b.speed(0) # sets animation speed to maximum. paddle_b.shape("square") paddle_b.color("white") paddle_b.shapesize(stretch_wid=5, stretch_len =1) paddle_b.penup() #something to do with not drawing lines. (which Turtle object do by default). paddle_b.goto(350,0) # Ball ball = turtle.Turtle() ball.speed(0) # sets animation speed to maximum. ball.shape("square") ball.color("white") ball.penup() #something to do with not drawing lines. (which Turtle object do by default). ball.goto(0,0) # Functions def paddle_a_up(): y = paddle_a.ycor() y += 20 paddle_a.sety(y) def paddle_a_down(): y = paddle_a.ycor() y += -20 paddle_a.sety(y) def paddle_b_up(): y = paddle_b.ycor() y += 20 paddle_b.sety(y) def paddle_b_down(): y = paddle_a.ycor() y += -20 paddle_b.sety(y)[url=https://www.youtube.com/watch?v=DplYMapxi3Y]https://www.youtube.com/watch?v=DplYMapxi3Y[/url] # Keyboard Binding wn.listen() wn.onkeypress(paddle_a_up,"w") wn.onkeypress(paddle_a_down,"s") #Main game loop while True: wn.update()