Pong / ball.py
schen357's picture
Create ball.py
3c310a8
Raw
History Blame Contribute Delete
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()