Я хочу, чтобы мяч сталкивался с блоками, а мяч - нет. Самолет - это название бара, который игрок может передвигать (70,10) Блок (кирпич) - кирпич, который игрок должен разбить (80,40) Размер игры (480 * 640) - это создать блок
, если блок Менее 30 блоков создаются случайным образом в случайном пространстве
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])
, когда вниз и вправо размер блока точек равен 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]
, здесь также сталкиваются шарик и полоса, коробочка go через бар ... почему
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)
теперь этот код является столкновением шара, и блок
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()
- мой код. мог бы получить мой вопрос?
когда мяч двигался, он двигался через блоки и застревал в небе