screen.tracer(0) screen.listen() screen.onkey(my_pong.key_up, "Up") screen.onkey(my_pong.key_down, "Down") screen.onkey(my_pong2.key_up, "w") screen.onkey(my_pong2.key_down, "s") in_game = True while in_game: screen.update() time.sleep(0.1) my_ball.move_ball() if my_ball.distance(my_pong) < 50 and my_ball.xcor( ) > 320 or my_ball.distance(my_pong2) < 50 and my_ball.xcor() < -320: my_ball.swich_directionsx() if my_ball.ycor() > 280 or my_ball.ycor() < -280: my_ball.swich_directionsy() if my_ball.xcor() <= -360: my_score.score_update(0) my_ball.goto(0, 0) my_ball.init_ball() if my_ball.xcor() >= 360: my_score.score_update(1) my_ball.goto(0, 0) my_ball.init_ball() screen.exitonclick()
# init with the size of the screen you are using my_snake = Snake(xvalue, yvalue) my_food = Food() my_score = ScoreBoard() screen.listen() screen.onkey(my_snake.arrow_right, "Right") screen.onkey(my_snake.arrow_left, "Left") screen.onkey(my_snake.arrow_up, "Up") screen.onkey(my_snake.arrow_down, "Down") in_game = True while in_game: screen.update() time.sleep(0.1) my_snake.move() if my_snake.invalid_move(): """ YOUR SNAKE ATE ITSELF OR YOU HIT THE WALL """ in_game = False if my_snake.head.distance(my_food) < 15: my_score.score_update() my_snake.snake_update() my_food.food_update() my_score.final_score() screen.exitonclick()