async def do(): if ball.is_being_dragged: ball.has_been_dragged = True ball.is_being_dragged = False @play.repeat_forever async def do(): if ball.is_being_dragged: ball.go_to(play.mouse) if ball.has_been_dragged: ball.point_towards(*start) ball.power = int(ball.distance_to(*start) / 3) ball.go_to(*start) ball.has_being_thrown = True ball.has_been_dragged = False if ball.has_being_thrown: ball.move(ball.power) if ball.distance_to(*target) < ball.width / 2: ball.angle = -90 ball.power = 10 ball.move(ball.width) score.score += 1 score.words = str(score.score) if ball.y < -100: green_flag() if ball.angle > -90: ball.turn(-3) play.start_program()
ball.physics.x_speed = -1 * abs( ball.physics.x_speed ) - 2 # минус - летим влево, -2 или +2 ускорение с течением времени def point_r(): ball.go_to(x=0, y=0) ball.physics.x_speed = abs(ball.physics.x_speed) + 2 @play.repeat_forever async def do(): if play.key_is_pressed('w', 'ц'): l_racket.y += 15 if play.key_is_pressed('s', "ы"): l_racket.y -= 15 if play.key_is_pressed('o', "щ"): r_racket.y += 15 if play.key_is_pressed('l', "д"): r_racket.y -= 15 if ball.x > RIGHT - 2 * B_SIZE: # что происходит здесь? point_l() # и здесь? if ball.x < LEFT + 2 * B_SIZE: point_r() await play.timer(seconds=1 / frames ) # частота смены кадров (пауза раз в несколько кадров) play.start_program()
# if play.key_is_pressed('w') and p2_box.top < play.screen.top: # p2_box.y += 10 # if play.key_is_pressed('s') and p2_box.bottom > play.screen.bottom: # p2_box.y -= 10 # make ball bounce off bottom and top walls @play.repeat_forever async def do(): if ball.bottom <= play.screen.bottom or ball.top >= play.screen.top: ball.dy = -1 * ball.dy # make ball come back from left and right @play.repeat_forever async def do(): global p1_score global p2_score if ball.x <= play.screen.left: p1_score += 1 p1_score_text.words = str(p1_score) ball.x = play.screen.right elif ball.x >= play.screen.right: p2_score += 1 p2_score_text.words = str(p2_score) ball.x = play.screen.left play.start_program() # this should always be the last line