| 142 | |
| 143 | |
| 144 | class Brick(pygame.sprite.Sprite): |
| 145 | def __init__(self, screen, width, height, x, y): |
| 146 | self.__screen = screen |
| 147 | self._width = width |
| 148 | self._height = height |
| 149 | self._xLoc = x |
| 150 | self._yLoc = y |
| 151 | w, h = pygame.display.get_surface().get_size() |
| 152 | self.__W = w |
| 153 | self.__H = h |
| 154 | self.__isInGroup = False |
| 155 | |
| 156 | def draw(self): |
| 157 | """ |
| 158 | draws the brick onto screen. |
| 159 | color: rgb(56, 177, 237) |
| 160 | """ |
| 161 | pygame.draw.rect( |
| 162 | screen, |
| 163 | (56, 177, 237), |
| 164 | (self._xLoc, self._yLoc, self._width, self._height), |
| 165 | 0, |
| 166 | ) |
| 167 | |
| 168 | def add(self, group): |
| 169 | """ |
| 170 | adds this brick to a given group. |
| 171 | """ |
| 172 | group.add(self) |
| 173 | self.__isInGroup = True |
| 174 | |
| 175 | def remove(self, group): |
| 176 | """ |
| 177 | removes this brick from the given group. |
| 178 | """ |
| 179 | group.remove(self) |
| 180 | self.__isInGroup = False |
| 181 | |
| 182 | def alive(self): |
| 183 | """ |
| 184 | returns true when this brick belongs to the brick wall. |
| 185 | otherwise false |
| 186 | """ |
| 187 | return self.__isInGroup |
| 188 | |
| 189 | def collide(self, ball): |
| 190 | """ |
| 191 | collision detection between ball and this brick |
| 192 | """ |
| 193 | brickX = self._xLoc |
| 194 | brickY = self._yLoc |
| 195 | brickW = self._width |
| 196 | brickH = self._height |
| 197 | ballX = ball._xLoc |
| 198 | ballY = ball._yLoc |
| 199 | ballXVel = ball.getXVel() |
| 200 | ballYVel = ball.getYVel() |
| 201 | |