Advertisement
giganciprogramowania

Brick

Jan 20th, 2022
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.81 KB | None | 0 0
  1. import pygame
  2. import copy
  3.  
  4. class Brick(pygame.sprite.Sprite):
  5.     def __init__(self, x, y, hp):
  6.         super(Brick, self).__init__()
  7.         self.surfOrig = pygame.image.load("images/brick.png")
  8.         #self.surf = pygame.image.load("images/brick.png")
  9.         self.rect = pygame.Rect(x, y, 96, 48)
  10.         self.hp = hp
  11.    
  12.     #aktualizacja
  13.     def update(self):
  14.         mask = 0
  15.         if self.hp == 3:
  16.             mask = (128, 0, 0)
  17.         if self.hp == 2:
  18.             mask = (0, 0, 128)
  19.         if self.hp == 1:
  20.             mask = (0, 128, 0)
  21.         self.surf = copy.copy(self.surfOrig)
  22.         self.surf.fill(mask, special_flags=pygame.BLEND_ADD)
  23.  
  24.     #funkcja wywolywana podczas zderzenia z kulka
  25.     def hit(self):
  26.         self.hp -= 1
  27.         if self.hp <= 0:
  28.             self.kill()
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement