更多关于pygame力量

时间:2016-07-21 09:19:46

标签: python pygame physics

所以早些时候我发布了一个关于我在pygame中制作的物理引擎编程力的问题。我编辑了一点代码,所以现在我想要添加的内容是event.key == K_UP:代码片段。当用户按下时,我希望它向上投射正方形。我尝试了许多斜坡和框架以及新坐标系统的东西,但是没有能够获得任何东西。

import pygame

pygame.init()

display_width = 800
display_height = 600
block_size = 30

gameDisplay = pygame.display.set_mode((display_width, display_height))
pygame.display.set_caption('Physics Engine')
clock = pygame.time.Clock()

x = display_width / 2
y = display_height / 2 + 200

y_change = 0
x_change = 0

gameExit = False

def force(ang, mag):
    # code about the force goes here
    x


while not gameExit:


    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            quit()
        elif event.type == pygame.KEYDOWN:  # check for key presses
            if event.key == pygame.K_LEFT:  # left arrow turns left
                x_change = -10
                y_change = 0
            elif event.key == pygame.K_RIGHT:  # right arrow turns right
                x_change = 10
                y_change = 0
            elif event.key == pygame.K_UP:
                # force(angle, magnitude)
                # I want to make a force that pushes the block up


        elif event.type == pygame.KEYUP:  # check for key presses
            if event.key == pygame.K_LEFT:  # left arrow turns left
                x_change = 0
                y_change = 0
            elif event.key == pygame.K_RIGHT:  # right arrow turns right
                x_change = 0
                y_change = 0




    y += y_change
    x += x_change

    gameDisplay.fill((255, 255, 255))
    pygame.draw.rect(gameDisplay, (255, 0, 0), [x, y, block_size, block_size])
    pygame.display.update()

    clock.tick(25)

pygame.quit()
quit()
非常感谢阅读,我非常感谢所有给予我的帮助!一个慷慨的家伙上次给了我一些提示,但我不太能跟进:(。

0 个答案:

没有答案