screen.onkey(l_paddle.go_up, "w") screen.onkey(l_paddle.go_down, "s") game_on = True while game_on: screen.update() time.sleep(ball.ball_speed) ball.move() # Detect Collision with wall: if ball.ycor() > 280 or ball.ycor() < -280: # Screen size 600 ball.wall_bounce() # Detect collision with Wall and bounce # ball doesnt meet the middle point for collision, so we give distance as 50 and captures collision if ball.xcor() > 320 and ball.distance(r_paddle) < 50 or ball.xcor( ) < -320 and ball.distance(l_paddle) < 50: ball.paddle_bounce() # Detect if paddle misses the ball if ball.xcor() > 380: # if r_paddle misses ball.reset_pos() score.l_point() if ball.xcor() < -380: # if l_paddle misses ball.reset_pos() score.r_point() screen.exitonclick()
game_is_on = True while game_is_on: time.sleep(ball.move_speed) screen.update() ball.move() if ball.ycor() > 280 or ball.ycor() < -280: ball.bounce_y() if ball.distance(r_paddle) < 50 and ball.xcor() > 320 or ball.distance(l_paddle) < 50 and ball.xcor() < -320: ball.bounce_x() '''When right paddle player misses the ball, left paddle player gains the score ''' if ball.xcor() > 380: ball.reset_position() scoreboard.l_point() '''When left paddle player misses the ball, right paddle player gains the score ''' if ball.xcor() < -380: ball.reset_position() scoreboard.r_point() screen.exitonclick()