-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathpaddle.py
22 lines (18 loc) · 1.05 KB
/
paddle.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from turtle import Turtle
MOVING_STEP = 40
class Paddle(Turtle):
def __init__(self, position : tuple): # receive the x and y coordinate in a tuple for initializing the starting position
super().__init__()
self.shape("square")
self.color("white")
self.shapesize(stretch_wid = 5, stretch_len = 1)
self.penup()
self.goto(position) # receive initial position from "position" tuple, then move the paddle to the edge of screen, for both left and right paddle
def go_up(self):
if self.ycor() < 350:
new_y = self.ycor() + MOVING_STEP # get the current paddle y position and + 20 when press "w" arrow key
self.goto(self.xcor(), new_y) # remain the x coordinate, we only wanna move its y coordinate position
def go_down(self):
if self.ycor() > -350:
new_y = self.ycor() - MOVING_STEP # get the current paddle y position and - 20 when press "s" arrow key
self.goto(self.xcor(), new_y) # remain the x coordinate, we only wanna move its y coordinate position