-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrick.py
28 lines (23 loc) · 876 Bytes
/
brick.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import pygame
from util import *
class block:
def __init__(self, x, y, width, height):
self.brick = pygame.Rect(x, y, width, height)
self.blockColor = randColor()
def draw(self, screen):
pygame.draw.rect(screen, self.blockColor, self.brick)
def collied(self, ball):
tolerence = 10
if self.brick.colliderect(ball.ball):
# print("k")
if abs(self.brick.top - ball.ball.bottom) < tolerence:
ball.speed[1] *= -1
if abs(self.brick.bottom - ball.ball.top) < tolerence:
ball.speed[1] *= -1
if abs(self.brick.right - ball.ball.left) < tolerence:
ball.speed[0] *= -1
if abs(self.brick.left - ball.ball.right) < tolerence:
ball.speed[0] *= -1
return True
else:
return False