-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathball.py
More file actions
36 lines (25 loc) · 801 Bytes
/
Copy pathball.py
File metadata and controls
36 lines (25 loc) · 801 Bytes
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
from turtle import Turtle
# Class for making the Ball.
class Ball(Turtle):
def __init__(self):
super().__init__()
self.shape("circle")
self.color("white")
self.shapesize(stretch_len = 1, stretch_wid = 1)
self.penup()
self.x_move = 0.30
self.y_move = 0.30
# Method for making the ball move.
def move(self):
new_x = self.xcor() + self.x_move
new_y = self.ycor() + self.y_move
self.goto(new_x, new_y)
# Method for having to bounce from y axis.
def bounce_y(self):
self.y_move *= -1
# Method for having to bounce from x axis.
def bounce_x(self):
self.x_move *= -1
# Method for resetting where the ball goes
def reset_ball(self):
self.goto(0, 0)