-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaddle.py
30 lines (25 loc) · 844 Bytes
/
paddle.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
from turtle import Turtle
PADDLE_WIDTH = 5
PADDLE_LEN = 1
PADDLE_SHAPE = "square"
PADDLE_COLOR = "white"
MOVE_INCREMENT = 20
SCREEN_BOUNDARY = 250
class Paddle(Turtle):
def __init__(self, cord: tuple):
super().__init__()
self.penup()
self.shape(PADDLE_SHAPE)
self.shapesize(PADDLE_WIDTH, PADDLE_LEN)
self.color(PADDLE_COLOR)
self.goto(cord)
# go_up() moves paddle by 20 pixels if below top of screen
def go_up(self):
if self.ycor() < SCREEN_BOUNDARY:
new_y = self.ycor() + MOVE_INCREMENT
self.goto(self.xcor(), new_y)
# go_down() moves paddle down by 20 pixel if above bottom of screen
def go_down(self):
if self.ycor() > -SCREEN_BOUNDARY:
new_y = self.ycor() - MOVE_INCREMENT
self.goto(self.xcor(), new_y)