coding_giants

lesson 13 paddle

Mar 17th, 2023 (edited)
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import pygame
  2.  
  3. SCREEN_WIDTH = 1024
  4. SCREEN_HEIGHT = 800
  5.  
  6.  
  7. class Paddle(pygame.sprite.Sprite):
  8. def __init__(self):
  9. super(Paddle, self).__init__()
  10. self.image = pygame.image.load("images/pad.png")
  11. self.moving = 0
  12. self.reset_position()
  13.  
  14. # resetting position
  15. def reset_position(self):
  16. self.rect = pygame.Rect(
  17. SCREEN_WIDTH/2-70, SCREEN_HEIGHT-100, 140, 30)
  18.  
  19. # moving the paddle
  20. def move_paddle(self, value):
  21. speed = 10
  22. self.rect.move_ip(value*speed, 0)
  23. self.moving = value
  24. if self.rect.left <= 0:
  25. self.rect.x = 0
  26. if self.rect.right >= SCREEN_WIDTH:
  27. self.rect.x = SCREEN_HEIGHT-140
  28.  
  29. # update
  30. def update(self):
  31. self.moving = 0
  32.  
Add Comment
Please, Sign In to add comment