首页 > 解决方案 > 我如何让球真正反射到桨上?

问题描述

顺便说一句,这是给 Brick Breaker 或 Breakout

def gamePlay(level,speed):
    global k,A,play,score,life,gameLevel,gameSpeed
    gameSpeed = speed
    gameLevel = level
    x = random.randrange(0,800)
    y = 200
    xpaddle = 400
    ypaddle = 565
    f = 0
    f1 = 0
    while True:
        gameDisplay.fill(black)
        gameData(score,life,level)
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                GameOver()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_LEFT:#paddle move left
                    xpaddle-=100
                    if xpaddle < 0:
                        xpaddle+=100
                if event.key == pygame.K_RIGHT:#paddle move right
                    xpaddle+=100
                    if xpaddle > 700:
                        xpaddle-=100
                if event.key == pygame.K_p:#pause
                    paused()
                    global pause 
                    pause = True

这是桨物理^

pygame.draw.circle(gameDisplay,green,(x,y),10)

这是你击中的实际球^

pygame.draw.rect(gameDisplay,red,(xpaddle,ypaddle,100,10))
        global paddle
        paddle = pygame.draw.rect(gameDisplay,red,(xpaddle,ypaddle,100,10))
        pygame.display.update()
        global ball
        ball = pygame.draw.circle(gameDisplay,green,(x,y),10)
        if ball.collidelist([paddle]) > -1:
            gameSpeed = -gameSpeed

这就是我认为“碰撞反射器”的工作方式^

标签: pythonpygamepython-3.7

解决方案


推荐阅读