Exemple #1
0
scn.onkey(left_player.go_down, "s")

game_over = False

while not game_over:
    time.sleep(ball.ball_speed)
    scn.update()
    ball.move()

    # Detect Upper and Lower wall collisions
    if ball.ycor() > 280 or ball.ycor() < -280:
        ball.bounce_wall()

    # detect collision with players
    if ball.xcor() > 360 and ball.distance(
            right_player.player) < 50 or ball.xcor() < -360 and ball.distance(
                left_player.player) < 50:
        ball.bounce_player()
        ball.ball_speed *= 0.9  # increase the speed of the ball after each touch

    if ball.xcor() > 400:
        ball.reset_postion()
        score.left_score()
        ball.ball_speed = 0.1
    if ball.xcor() < -400:
        ball.reset_postion()
        score.right_score()
        ball.ball_speed = 0.1

scn.exitonclick()
Exemple #2
0
score_board = Scoreboard()

screen.onkeypress(paddle_r.up, "Up")
screen.onkeypress(paddle_r.down, "Down")
screen.onkeypress(paddle_l.up, "w")
screen.onkeypress(paddle_l.down, "s")

game_is_on = True

while game_is_on:
    screen.update()
    time.sleep(ball.move_speed)
    ball.move_cars()

    if abs(ball.ycor()) > 270:
        ball.bounce_y()

    if ball.distance(paddle_r) < 50 and ball.xcor() > 330 or ball.distance(
            paddle_l) < 50 and ball.xcor() < -330:
        ball.bounce_x()

    if ball.xcor() > 380:
        score_board.left_score()
        ball.reset_position()

    if ball.xcor() < -380:
        score_board.right_score()
        ball.reset_position()

screen.exitonclick()