-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathball.py
28 lines (23 loc) · 795 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
from turtle import Turtle
class Ball(Turtle):
def __init__(self, shape = "circle", undobuffersize = 1000, visible = True):
super().__init__(shape, undobuffersize, visible)
self.setheading(30)
self.color('white')
self.penup()
self.move_speed = 10
self.sleep_speed =0.1
def move(self):
self.forward(self.move_speed)
def x_collision(self):
# reflect the x axis heading
heading = self.heading()
new_heading = 180-heading
self.setheading(new_heading)
# the setheading() function handles negative coordinates
def y_collision(self):
# reflect the y axis heading
heading = self.heading()
self.setheading(360-heading)
def reset(self):
self.goto((0,0))