-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpaddle.py
26 lines (19 loc) · 807 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
from turtle import Turtle
class Paddle(Turtle):
"""A class to manage the paddle in Pong game."""
def __init__(self, position_tuple):
"""Initialize the attributes of the paddle. Include a starting position (tuple) at instantiation."""
super().__init__()
self.shape('square')
self.color('pink')
self.penup()
self.shapesize(stretch_wid=5, stretch_len=1)
self.setpos(position_tuple)
def move_up(self):
"""Moves the paddle up the screen."""
if self.ycor() <= 0.40 * self.getscreen().window_height():
self.sety(self.ycor() + 50)
def move_down(self):
"""Moves the paddle down the screen."""
if self.ycor() >= -0.40 * self.getscreen().window_height():
self.sety(self.ycor() - 50)