I'm trying to make a game using pygame
module
I've already imported my pictures and can move the helicopter but I'm not able to shoot. The commented lines are the things that I've done so far for the shooting part. When pressing the button for shooting, nothing happens. It seems that the code does not run for the second if statement and I don't know the reason.
Thank you for your help!
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()