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: time.sleep(ball.move_speed) screen.update() ball.move_ball() # wall collision if ball.ycor() > 280 or ball.ycor() < -280: ball.bounce() # paddle collision if ball.distance(r_paddle) < 50 and ball.xcor() > 320 or ball.distance( l_paddle) < 50 and ball.xcor() < -320: ball.paddle_bounce() # check score right if ball.xcor() > 380: ball.reset_position() score.l_point() # check score left if ball.xcor() < -380: ball.reset_position() score.r_point() screen.exitonclick()
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, "a") is_game_on = True while is_game_on: screen.update() time.sleep(0.01) my_ball.move() if my_ball.ycor() > 280 or my_ball.ycor() < -280: my_ball.bounce_y() if (my_ball.distance(r_paddle) < 50 and my_ball.xcor() > 440) or (my_ball.distance(l_paddle) < 50 and my_ball.xcor() < -440): my_ball.bounce_x() if my_ball.xcor() > 480: my_ball.reset_position() my_score.l_point() if my_ball.xcor() < -480: my_ball.reset_position() my_score.r_point() screen.exitonclick()