SHOW:
|
|
- or go back to the newest paste.
| 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.rect = 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 |