Download ball.py from Workfun/Pong: direct link, hf CLI and curl.
- Browser
- Download file 664 Bytes
-
https://huggingface.co/Workfun/Pong/resolve/main/ball.py
- Command line
-
hf download hf://Workfun/Pong/ball.py
-
curl -L -o ball.py https://huggingface.co/Workfun/Pong/resolve/main/ball.py
664 Bytes
| class Ball(Turtle): | |
| def __init__(self): | |
| super().__init__() | |
| self.shape("circle") | |
| self.color("light green") | |
| self.penup() | |
| self.direction_x = 10 | |
| self.direction_y = 10 | |
| def hit(self): | |
| self.setheading(90) | |
| def move(self): | |
| new_xcor = self.xcor() + self.direction_x | |
| new_ycor = self.ycor() + self.direction_y | |
| self.goto(new_xcor, new_ycor) | |
| def bounce_x(self): | |
| self.direction_x *= -1 | |
| def bounce_y(self): | |
| self.direction_y *= -1 | |
| def reset(self): | |
| self.hideturtle() | |
| self.goto(0,0) | |
| self.direction_x *= -1 | |
| self.showturtle() | |