проблема с пинг понгом. когда двигаю игроком шарик будто сходит с ума и двигается рывками

import turtle
from win32api import GetSystemMetrics
import random


class Game_element(turtle.Turtle):

    def __init__(self, goto, x, y, dy=5, dx=2, shape="square"):
        super().__init__()
        self.color("white")
        self.shape(shape)
        self.penup()
        self.shapesize(x, y)
        self.goto(goto)
        self.dy = dy
        self.dx = dx

    def move_up(self):
        x, y = self.pos()
        self.setposition(x, y + self.dy)

    def move_down(self):
        x, y = self.pos()
        self.setposition(x, y - self.dy)


win_w = GetSystemMetrics(0)
win_h = GetSystemMetrics(1)

window = turtle.Screen()
x1 = -(win_w / 2) + (0.065 * win_w)
x2 = (win_w / 2) - (0.065 * win_w)
window.bgcolor("black")
window.setup(win_w, win_h)
window.tracer()

random_index = [1, -1]

index = random.choice(random_index)
index_2 = random.choice(random_index)

player_1 = Game_element([x1, 0], 5, 1)
player_2 = Game_element([x2, 0], 5, 1)
ball = Game_element([0, 0], 1, 1, shape="circle")
ball.dy = index * 2
ball.dx = index_2 * 2

window.onkeypress(player_1.move_up, "w")
window.onkeypress(player_1.move_down, "s")
window.onkeypress(player_2.move_up, "Up")
window.onkeypress(player_2.move_down, "Down")
window.listen()

while True:
    window.update()
    ball.sety(ball.ycor() + ball.dy)
    ball.setx(ball.xcor() + ball.dx)

    if ball.ycor() > (win_h / 2) - (win_h * 0.05):
        ball.sety((win_h / 2) - (win_h * 0.05))
        ball.dy *= -1
    if ball.ycor() < -(win_h / 2) + (win_h * 0.05):
        ball.sety(-(win_h / 2) + (win_h * 0.05))
        ball.dy *= -1

    if ball.xcor() > (win_w / 2) - (win_w * 0.045):
        ball.sety(0)
        ball.setx(0)
    if ball.xcor() < -(win_w / 2) + (win_w * 0.045):
        ball.sety(0)
        ball.setx(0)

    if ball.xcor() > x1 + 20 and (player_1.ycor() + 25 > ball.ycor() > player_1.ycor() - 25):
        ball.dx *= -1
    if ball.xcor() > x2 - 20 and (player_2.ycor() + 25 > ball.ycor() > player_2.ycor() - 25):
        ball.dx *= -1

Ответы (0 шт):