Advertisement
ada1711

Untitled

Mar 16th, 2023
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. import pygame
  2. import copy
  3.  
  4.  
  5. class Brick(pygame.sprite.Sprite):
  6. def __init__(self, x, y, health):
  7. super(Brick, self).__init__()
  8. self.original_image = pygame.image.load("images/brick.png")
  9. self.position = pygame.Rect(x, y, 96, 48)
  10. self.health = health
  11.  
  12. # refresh
  13. def refresh(self):
  14. color_mask = 0
  15. if self.health == 3:
  16. color_mask = (128, 0, 0)
  17. if self.health == 2:
  18. color_mask = (0, 0, 128)
  19. if self.health == 1:
  20. color_mask = (0, 128, 0)
  21. self.image = copy.copy(self.original_image)
  22. self.image.fill(color_mask, special_flags=pygame.BLEND_ADD)
  23.  
  24. def update(self):
  25. self.refresh()
  26.  
  27. # method used when colliding with a ball
  28. def hit(self):
  29. self.health -= 1
  30. if self.health <= 0:
  31. self.kill()
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement