-
Notifications
You must be signed in to change notification settings - Fork 0
/
ball.py
33 lines (25 loc) · 917 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
29
30
31
from turtle import Turtle
class Ball(Turtle):
def __init__(self):
""" Creates ball, sets speed, moving step size, puts to position. """
super().__init__()
self.shape("circle")
self.color("yellow")
self.penup()
self.speed = 0.05
self.step_x = 10
self.step_y = 10
self.start_position()
def ball_move(self):
""" Moves ball from current x, y postions adding step and dirrection"""
self.goto(self.xcor()+self.step_x, self.ycor()+self.step_y)
def bounce_horizontal(self):
""" Changes to the opposite direction to up or down."""
self.step_y *= -1
def bounce_vertical(self):
""" Changes to the opposite direction to left or right."""
self.step_x *= -1
def start_position(self):
""" Puts to start position."""
self.setposition(0, -160)
self.speed *= 0.9