在pygame中射击直升机

时间:2018-05-20 07:49:15

标签: python python-3.x pygame

我正在尝试使用pygame模块制作游戏 我已经导入了我的照片,可以移动直升机,但我无法射击。评论的线条是我迄今为拍摄部分所做的事情。按下按钮进行拍摄时,没有任何反应。似乎代码没有针对第二个if语句运行,我不知道原因。

感谢您的帮助!

import pygame

white=(255,255,255)
black=(0,0,0)

pygame.init()
surface = pygame.display.set_mode((1000,1000))
pygame.display.set_caption("AI Game")
clock = pygame.time.Clock()

def helicopter(x , y, image):
    surface.blit(helicopterPicture ,(x,y))

def bulletshape(x, y, image):
    surface.blit(bulletPicture ,(x,y))

bullets=[]



helicopterPicture = pygame.image.load('helicoptter.png')
bulletPicture = pygame.image.load('bullet.png')

x_helicopter= 150
y_helicopter= 200
x_bullet= 260
y_bullet= 240
y_move = 0
x_move = 0
y_bullet_move = 0
x_bullet_move = 0

Game_Over=False

def GameOver():
    pygame.quit()
    quit()


while not Game_Over:
    for event in pygame.event.get():
        if (event.type == pygame.QUIT):
            Game_Over=True
        if (event.type == pygame.KEYDOWN):
            if (event.key == pygame.K_UP):
                y_move = -5
                x_move = 0
                y_bullet_move = -5
                x_bullet_move = 0
                if (event.type == pygame.KEYDOWN):
                    if(event.key == pygame.K_SPACE):
                        y_bullet_move = -20
                        x_bullet_move = 0

        if (event.type == pygame.KEYDOWN):
            if (event.key == pygame.K_DOWN):
                y_move = 5
                x_move = 0
               # y_bullet_move = 5
               # x_bullet_move = 0
               # if (event.key == pygame.K_KP_ENTER):
                #    y_bullet_move = 10
                 #   x_bullet_move = 0
        if(event.type == pygame.KEYDOWN):
            if(event.key == pygame.K_RIGHT):
                x_move = 5
                y_move = 0
                x_bullet_move = 5
                y_bullet_move = 0
                #if(event.key == pygame.K_KP_ENTER):
                 #   x_bullet_move = 10
                  #  y_bullet_move = 0
        if(event.type == pygame.KEYDOWN):
            if(event.key == pygame.K_LEFT):
                x_move = -5
                y_move = 0
               # x_bullet_move = -5
               # y_bullet_move = 0
               # if(event.key == pygame.K_KP_ENTER):
                #    x_bullet_move = -100
                 #   y_bullet_move = 0

    y_helicopter+=y_move
    x_helicopter+=x_move
    x_bullet+=x_bullet_move
    y_bullet+=y_bullet_move

    surface.fill(black)

    helicopter(x_helicopter,y_helicopter,helicopterPicture)
    bulletshape(x_bullet,y_bullet,bulletPicture)

    if (y_helicopter>950 or y_helicopter<25 or x_helicopter>950 or x_helicopter<25):
        GameOver()

    pygame.display.update()
    clock.tick(10)


pygame.quit()
quit()

0 个答案:

没有答案