I want ball to collide with blocks but ball don't. plane is name about bar which player can move (70,10) block(brick)is brick that player must break(80,40) game size is (480*640) here is create block
if block is less than 30 block create by randomly in random space
while len(wblock) <= 30:
down = random.randint(0, 9)
right = random.randint(0, 6)
wb = random.randint(1,42)
wblock.append([right*80, down*40, wb])
when down and right is point block size is 80*40
if wball[0] >= 460:
bx = bx*(-1)
if wball[0] == 0:
bx = bx*(-1)
if wball[1] >= 640:
running = False
if wball[1] == 0:
by = by*(-1)
wball[0] += bx*2
wball[1] += by*2
screen.blit(ball, (wball[0],wball[1]))
ballrect = pygame.Rect(ball.get_rect())
ballrect.left = wball[0]
ballrect.right = wball[1]
here is ball and bar collide also , boll go through of bar... why
position = pygame.mouse.get_pos()
planepos = (position[0], 600)
position[0]
screen.blit(plane, planepos)
planerect = pygame.Rect(plane.get_rect())
planerect.left = planepos[0]
planerect.top = planepos[1]
if planerect.colliderect(ballrect):
by = by*(-1)
print(by)
now this code is collide of ball and block
index = 0
for brick in wblock:
index += 1
brickrect = pygame.Rect(blocks[brick[2]].get_rect())
brickrect.left=brick[0]
brickrect.top=brick[1]
if brickrect.colliderect(ballrect):
wblock.pop(index)
by = by*(-1)
index -= 1
screen.blit(blocks[brick[2]], (brick[0],brick[1]))
fpsClock.tick(FPS)
pygame.display.flip()
screen.blit(gameover, (10,100))
pygame.display.flip()
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
exit(0)
pygame.display.flip()
is my code. could get my question?
when ball move he move through blocks and stuck in sky