paddle.py 688 B

12345678910111213141516171819202122232425
  1. from turtle import Turtle
  2. from config import SCREEN_HEIGHT, PADDLE_LENGTH
  3. STEP = 20
  4. class Paddle(Turtle):
  5. def __init__(self, pos):
  6. super().__init__()
  7. self.shape("square")
  8. self.color("white")
  9. self.setheading(90)
  10. self.penup()
  11. # self.speed("fastest")
  12. self.shapesize(stretch_len=PADDLE_LENGTH, stretch_wid=1)
  13. self.goto(pos, 0)
  14. def up(self):
  15. y = self.ycor()
  16. if y < SCREEN_HEIGHT / 2 - PADDLE_LENGTH * 5 - STEP * 2:
  17. self.forward(STEP)
  18. def down(self):
  19. y = self.ycor()
  20. if y > -(SCREEN_HEIGHT / 2 - PADDLE_LENGTH * 5 - STEP * 2):
  21. self.backward(STEP)