-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
67 lines (56 loc) · 1.79 KB
/
main.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import sys
import pygame
import paddle
import ball
import brick
class Main:
def __init__(self, width, height):
pygame.init()
self.clock = pygame.time.Clock()
self.screen = pygame.display.set_mode((width, height))
self.width = width
self.height = height
self.blocks = self.spawnbrick(15,10)
self.ball = ball.ball(self.width, self.height)
self.paddle = paddle.paddle(self.width, self.height, self.ball)
def spawnbrick(self, i, j):
blocks = []
blockwidth = (self.width//i)
blockheight = ((self.height / 2)//j)
for x in range(i):
for y in range(j):
blocks.append(brick.block(x * blockwidth + 5, (y * blockheight)+10, blockwidth - 10, blockheight - 10))
return blocks
def draw(self):
self.screen.fill((20, 20, 20))
self.paddle.draw(self.screen)
self.ball.draw(self.screen)
self.drawBricks()
pygame.display.flip()
def brickCollied(self):
toBePoped = []
for x in self.blocks:
if x.collied(self.ball):
toBePoped.append(x)
for x in toBePoped:
self.blocks.pop(self.blocks.index(x))
def drawBricks(self):
for x in range(len(self.blocks)):
self.blocks[x].draw(self.screen)
def handleinput(self):
input = pygame.event.get()
for event in input:
if event.type == pygame.QUIT:
sys.exit()
self.paddle.handleInput(input)
def run(self):
while True:
self.clock.tick(60)
self.handleinput()
self.ball.move()
self.ball.colliedMap()
self.paddle.collied()
self.brickCollied()
self.draw()
run = Main(500, 500)
run.run()