I’m a beginner programmer and my first language is Python 2.7, I’m trying to make a space invader type game but i want to have multiple bullets at once and cant find a way to do that. so i made my own way here is my code ill explain more after you see it
if event.type ==pygame.KEYDOWN and event.key==K_SPACE:
if m < 5:
m+=1
if m==1:
m1a=1
m1x=ls
if m==2:
m2a=1
m2x=ls
if m==3:
m3a=1
m3x=ls
if m==4:
m4a=1
m4x=ls
if m==5:
m5a=1
m5x=ls
print m
#missle 1
if m1a==1:
screen.blit(rship,(m1x,m1))
if m1>=0:
m1-=1
else:
m-=1
m1a=0
m1=460
#missle 2
if m2a==1:
screen.blit(rship,(m2x,m2))
if m2>=0:
m2-=1
else:
m-=1
m2a=0
m2=460
#missle 3
if m3a==1:
screen.blit(rship,(m3x,m3))
if m3>=0:
m3-=1
else:
m-=1
m3a=0
m3=460
#missle 4
if m4a==1:
screen.blit(rship,(m4x,m4))
if m4>=0:
m4-=1
else:
m-=1
m4a=0
m4=460
#missle 5
if m5a==1:
screen.blit(rship,(m5x,m5))
if m5>=0:
m5-=1
else:
m-=1
m5a=0
m5=460
I’m sure its laughably noobish but I’m just learning but the problem is the first and second missile are fine its the third and beyond that get messed up. when you fire the third it moves the second over the where your shooting from and then if you fir again the code wont go back down to 1 it stays at 2 and gets even more glitches. If you need me to try and explain it better I gladly will. Just trying to Learn.
Full code here: pastebin.com/FnPaME6N
Here is some working code, but I wouldn’t call it great.
Any time you find yourself making variables with numbers in them, it’s a code smell, and means you probably should use a different data type.
As has been suggested, you’ll probably want to look into the sprite and group modules, but this will at least do what you were trying to do so far.