我正在研究我的第一个python / pygame项目,该项目正在制造拆砖机。出于某种原因,无论我如何更改,当球碰到桨时,我都无法使球从speedY变为-speedY。
我试图改变球需要改变速度的地方,不起作用
pygame.draw.rect(win, (0, 255, 0), (paddleX, 355, paddleWidth, paddleHeight))
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] and paddleX > 0:
paddleX -= vel
elif keys[pygame.K_RIGHT] and paddleX < 400 - paddleWidth:
paddleX += vel
pygame.draw.circle(win, (0, 0, 255), (x, y), 9)
if isBallMoving:
x += speedX
y += speedY
elif not isBallMoving:
x = paddleX + 38
y = 344
if y <= 6:
speedY = -speedY
if x <= 8:
speedX = -speedX
if x >= 392:
speedX = -speedX
#if y >= 344 and y < 361 and x >= paddleX - paddleWidth/2 and x <= paddleX + paddleWidth/2:
# speedY = -speedY
if y >= 355 and y <= 370 and x <= paddleX + (paddleWidth/2) and x > paddleX - (paddleWidth/2):
speedY = -speedY
if y >= 400:
isBallMoving = False
if keys[pygame.K_SPACE]:
if not isBallMoving:
speedX = startSpeedX
speedY = startSpeedY
isBallMoving = True
我希望球从球拍上弹起,但这只是通过球而已。