from turtle import Turtle, Screen, reset
from paddle import Paddle
from ball import Ball
from scoreboard import Scoreboard
import time

#Create and setup Screen
screen = Screen()
screen.bgcolor("black")
screen.setup(width=800, height=600)
screen.title("Pong")
screen.tracer(0)

#Create Paddles
r_paddle = Paddle((350, 0))
l_paddle = Paddle((-350, 0))
ball = Ball()

#Create scoreboard
scoreboard = Scoreboard()

#Controlling Paddles with keyboard inputs
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:
    time.sleep(ball.move_speed)
    screen.update()
    ball.move()

    #Detect Collision with upper and lower walls
    if ball.ycor() > 290 or ball.ycor() < -290:
        ball.bounce_y()

    #Detect Collision with paddles
    if ball.distance(r_paddle) < 50 and ball.xcor() > 320 or ball.distance(l_paddle) < 50 and ball.xcor() < -320:
        ball.bounce_x()

    #Detect when r_paddle misses
    if ball.xcor() > 380:
        ball.reset_position()
        scoreboard.l_point()

    #Detect when l_paddle misses
    if ball.xcor() < -380:
        ball.reset_position()
        scoreboard.r_point()

screen.exitonclick()
from turtle import Turtle, Screen, reset
from paddle import Paddle
from ball import Ball
from scoreboard import Scoreboard
import time

#Create and setup Screen
screen = Screen()
screen.bgcolor("black")
screen.setup(width=800, height=600)
screen.title("Pong")
screen.tracer(0)

#Create Paddles
r_paddle = Paddle((350, 0))
l_paddle = Paddle((-350, 0))
ball = Ball()

#Create scoreboard
scoreboard = Scoreboard()

#Controlling Paddles with keyboard inputs
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:
    time.sleep(ball.move_speed)
    screen.update()
    ball.move()

    #Detect Collision with upper and lower walls
    if ball.ycor() > 290 or ball.ycor() < -290:
        ball.bounce_y()

    #Detect Collision with paddles
    if ball.distance(r_paddle) < 50 and ball.xcor() > 320 or ball.distance(l_paddle) < 50 and ball.xcor() < -320:
        ball.bounce_x()

    #Detect when r_paddle misses
    if ball.xcor() > 380:
        ball.reset_position()
        scoreboard.l_point()

    #Detect when l_paddle misses
    if ball.xcor() < -380:
        ball.reset_position()
        scoreboard.r_point()

screen.exitonclick()
#Create and setup Screen #Create Paddles #Create scoreboard #Controlling Paddles with keyboard inputs #Detect Collision with upper and lower walls #Detect Collision with paddles #Detect when r_paddle misses #Detect when l_paddle misses