Download main.py from Workfun/Pong: direct link, hf CLI and curl.
- Browser
- Download file 1.41 kB
-
https://huggingface.co/Workfun/Pong/resolve/main/main.py
- Command line
-
hf download hf://Workfun/Pong/main.py
-
curl -L -o main.py https://huggingface.co/Workfun/Pong/resolve/main/main.py
1.41 kB
| from turtle import Screen | |
| from net import make_net | |
| from paddle import Paddle | |
| from ball import Ball | |
| from scoreboard import Scoreboard | |
| import time | |
| SCREEN_WIDTH = 800 | |
| SCREEN_HEIGHT = 600 | |
| SCREEN_COLOR = "black" | |
| COORDINATES = [(350, 0), (-350, 0)] | |
| SPEED = 0.09 | |
| screen = Screen() | |
| screen.setup(width=SCREEN_WIDTH, height=SCREEN_HEIGHT) | |
| screen.title("That's right, PONG!!! (with SUPER SHOT)") | |
| screen.bgcolor(SCREEN_COLOR) | |
| screen.tracer(0) | |
| make_net() | |
| paddle_1 = Paddle(coordinates=COORDINATES[0]) | |
| paddle_2 = Paddle(coordinates=COORDINATES[1]) | |
| ball = Ball() | |
| score = Scoreboard() | |
| screen.listen() | |
| screen.onkey(paddle_1.up, "Up") | |
| screen.onkey(paddle_1.down, "Down") | |
| screen.onkey(paddle_2.up, "w") | |
| screen.onkey(paddle_2.down, "s") | |
| game_is_on = True | |
| while game_is_on: | |
| screen.update() | |
| time.sleep(SPEED) | |
| ball.move() | |
| if ball.ycor() > 280 or ball.ycor() < -280: | |
| ball.bounce_y() | |
| if paddle_1.distance(ball) < 50 and ball.xcor() > 320 or paddle_2.distance(ball) < 50 and ball.xcor() < -320: | |
| ball.bounce_x() | |
| if SPEED >= .01: | |
| SPEED -= .009 | |
| if ball.xcor() > 400: | |
| score.add_point_p2() | |
| ball.reset() | |
| SPEED = .09 | |
| if ball.xcor() < -400: | |
| score.add_point_p1() | |
| ball.reset() | |
| SPEED = .09 | |
| if score.score_p1 == 5 or score.score_p2 == 5: | |
| score.end_game() | |
| game_is_on = False | |
| screen.exitonclick() | |