-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathball.py
40 lines (32 loc) · 947 Bytes
/
ball.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from turtle import Turtle
class Ball(Turtle):
# Ball Appearance
def __init__(self):
super().__init__()
self.shape('circle')
self.pu()
self.color('white')
self.y_move = 10
self.x_move = 10
self.speed = 0
self.move_speed = 0.1
# Ball Movement
def move(self):
new_x = self.xcor() + self.x_move
new_y = self.ycor() + self.y_move
self.goto(new_x, new_y)
# Ball Bounce from Top and Bottom Walls
def bounce_y(self):
self.y_move *= -1
# Ball Bounce from Left Paddle
def bounce_x_l_paddle(self):
self.x_move = (abs(self.x_move))
self.move_speed *= 0.9
# Ball Bounce from Right Paddle
def bounce_x_r_paddle(self):
self.x_move = -(abs(self.x_move))
self.move_speed *= 0.9
# Ball Position Reset
def reset_position(self):
self.goto(0, 0)
self.move_speed = 0.1