Hi I'm working on a very basic game for a summer course I'm taking and I've recently discovered a bug that does not allow me to move and shoot at the same time. Here is the event handling code:
for event in pygame.event.get():
#create quit event
if event.type == QUIT:
pygame.quit()
sys.exit()
#checks for keyup events to stop movement
if event.type == KEYUP:
if event.key == pygame.K_w:
#stops player moving up
player.yVelocity += 8
if event.key == pygame.K_d:
#stops player moving right
player.xVelocity -= 8
if event.key == pygame.K_s:
#stops player moving down
player.yVelocity -= 8
if event.key == pygame.K_a:
#stops player moving left
player.xVelocity += 8
#checks for key presses
if event.type == KEYDOWN:
if event.key == pygame.K_w:
#sets variable to move player up
player.yVelocity -= 8
if event.key == pygame.K_d:
#sets variable to move player right
player.xVelocity += 8
if event.key == pygame.K_s:
#sets variable to move player down
player.yVelocity += 8
if event.key == pygame.K_a:
#sets variable to move player left
player.xVelocity -= 8
if event.key == pygame.K_ESCAPE:
#calls gameInit() to take player back to main menu
mainGame.gameInit()
#checks for clicks
if (pygame.mouse.get_pressed())[0] == 1:
#tells the game it should be firing
print("bam")
firing = True
if (pygame.mouse.get_pressed())[1] == 1:
#fires secondary ability
player.useAbility((0,0))
if (pygame.mouse.get_pressed())[0] == 0:
firing = False
if firing == True:
mainGame.bulletList = player.shoot(pygame.mouse.get_pos(), mainGame.bulletList)
Sorry if it's a mess I'm fairly new to all this. However, when I put a test print statement inside the bit that detects mouse clicks, I found that it wouldn't take mouse input while a key was being pressed. I have no idea as to the cause of this.