File size: 664 Bytes
3c310a8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()