-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpaddle.py
More file actions
42 lines (31 loc) · 942 Bytes
/
paddle.py
File metadata and controls
42 lines (31 loc) · 942 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
35
36
37
from turtle import Turtle
class Paddle(Turtle):
def __init__(self, pos):
super().__init__()
self.shape("square")
self.color("white")
self.turtlesize(stretch_len=2, stretch_wid=10)
self.penup()
self.goto(pos)
self.move_y = 40
self.move_x = 40
self.energy_full = False
def go_up(self):
if self.ycor() < 630:
self.move_y = 40
self.sety(self.ycor() + self.move_y)
else:
self.move_y = 0
def go_down(self):
if self.ycor() > -630:
self.move_y = 40
self.sety(self.ycor() - self.move_y)
else:
self.move_y = 0
def smash(self):
if self.energy_full:
if self.xcor() < 0:
self.setx(self.xcor() + self.move_x)
else:
self.setx(self.xcor() - self.move_x)
self.energy_full = False