schen357 commited on
Commit
3c310a8
·
1 Parent(s): 2ed2a0f

Create ball.py

Browse files
Files changed (1) hide show
  1. ball.py +30 -0
ball.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ class Ball(Turtle):
2
+
3
+ def __init__(self):
4
+ super().__init__()
5
+ self.shape("circle")
6
+ self.color("light green")
7
+ self.penup()
8
+ self.direction_x = 10
9
+ self.direction_y = 10
10
+
11
+ def hit(self):
12
+ self.setheading(90)
13
+
14
+ def move(self):
15
+ new_xcor = self.xcor() + self.direction_x
16
+ new_ycor = self.ycor() + self.direction_y
17
+ self.goto(new_xcor, new_ycor)
18
+
19
+ def bounce_x(self):
20
+ self.direction_x *= -1
21
+
22
+ def bounce_y(self):
23
+ self.direction_y *= -1
24
+
25
+ def reset(self):
26
+ self.hideturtle()
27
+ self.goto(0,0)
28
+ self.direction_x *= -1
29
+ self.showturtle()
30
+