Hi guys i'm making a game in python using pygame. I have a piece of code that shoots lasers from a ship in a space themed game. Here is the code:
# Laser
laserImg = pygame.image.load('assets/PNG/Lasers/laserBlue01.png')
laserX = 0
laserY = 480
laserX_change = 0
laserY_change = 8
laser_state = "ready"
def fire_laser(x,y):
global laser_state
laser_state = "fire"
screen.blit(laserImg, (x+20,y+9))
screen.blit(laserImg, (x+70,y+9))
running = True
while running:
screen.fill((0, 0, 0))
screen.blit(background,(0,0))
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.key == pygame.K_SPACE:
if laser_state is "ready":
laser_sound = mixer.Sound('assets/Bonus/sfx_laser1.ogg')
laser_sound.play()
laserX = playerX
fire_laser(playerX, laserY)
# Bullet movement
if laserY <= 0:
laserY = 475
laser_state = "ready"
if laser_state is "fire":
fire_laser(laserX, laserY)
laserY -= laserY_change
Well this piece of code shoots two lasers from the ship,
like this.
But i don't want that. I want to make if player presses space once shoot the left laser if player presses space again than shoot the right laser and when he presses space again it will shoot left laser again. I hope you did understand.

