-2
我试图让球对象在屏幕内弹跳,我一直在测试不同的东西几个小时,在这里看着其他乒乓球游戏源代码和其他问题,但我似乎无法想办法。有人可以指出从哪里开始?我应该为不同的动作分别制作功能吗?Pygame pong游戏
# ----- Game Loop ----- #
# Setting the loop breakers
game_exit = False
# ball positon/velocity
ball_x = DISP_W/2
ball_y = DISP_H/2
velocity = 5
# Game loop
while not game_exit:
# Gets all events
for event in pygame.event.get():
# Close event
if event.type == pygame.QUIT:
# Closes game loop
game_exit = True
# Background fill
GAME_DISP.fill(black)
# Setting positions
ball.set_pos(ball_x, ball_y)
# ceil.set_pos(0, 0)
# floor.set_pos(0, DISP_H - boundary_thickness)
ball_y += velocity
# Drawing sprites
ball_group.draw(GAME_DISP)
# collision_group.draw(GAME_DISP)
pygame.display.update()
# Setting FPS
clock.tick(FPS)
# ----- Game exit ----- #
pygame.quit()
quit()
全码:http://pastebin.com/4XxJaCvf
这将有助于,如果你解释发生了什么,以及你期望发生什么。 – PinkFluffyUnicorn
我希望它能从天花板和地板反弹,沿着对角线移动,现在我只是试图让它从地面反弹,天花板以直线移动...... – Lucas