Ok I'm working on a 2d shooter. Every time I shoot multiple bullets, it seems to lag. I believe it could be somewhere in the loop that handles the bullets.
This is just the part that handles drawing the bullets..
HandleBullets:
q=0
do
inc q
if q>MaxBullets then exit
if getstringtoken(bullet[q],"|",1)="1"
if GetSpriteExists(BulletSpriteStart+q)=0
wea$=localsprite[sel_button]: wea=val(wea$)
// create how bullet looks
ima=GetBulletImage(wea$)
CreateSprite(BulletSpriteStart+q,ima)
SetSpriteSize(BulletSpriteStart+q,GetBulletImageXSize(ima),GetBulletImageYSize(ima))
SetSpriteDepth(BulletSpriteStart+q,CharacterDepth)
else
// draws bullets
bspr=BulletSpriteStart+q
bX_=val(getstringtoken(bullet[q],"|",2))
bY_=val(getstringtoken(bullet[q],"|",3))
SetSpritePosition(bspr, bX_, bY_)
/// gosub BulletCollision
/// gets bullets direction
bf$=getstringtoken(bullet[q],"|",4)
bd_=val(getstringtoken(bullet[q],"|",5))
d#=GetGunBulletSpeed(localsprite[sel_button])
if bf$="0,-1"
dec bY_,d#
setspriteangle(bspr,270)
endif
if bf$="0,1"
inc bY_,d#: setspriteangle(bspr,90)
endif
if bf$="1,0"
inc bX_,d#: setspriteangle(bspr,0)
endif
if bf$="-1,0"
dec bX_,d#: setspriteangle(bspr,180)
endif
inc bd_,1
/// gosub WriteNetworkMessages
/// gosub ReadNetworkMessages
/// if zombies get hit `
kk=0
do
inc kk
if kk>MaxZombies then exit
if getspriteexists(ZombieSpriteStart+kk) and getspriteexists(bspr)
if getspritecollision(bspr,ZombieSpriteStart+kk)
// hurt zombie by health
gd#=GetGunBulletDamage(localsprite[sel_button])
zombies[kk,Zhealth]=str(val(zombies[kk,Zhealth])-gd#)
// sound
playsound(ZombieHitSound)
/// push zombie back
n=val(getstringtoken(bf$,",",1))
w=val(getstringtoken(bf$,",",2))
zombies[kk,zX]=str(val(zombies[kk,zX])+(n*4))
zombies[kk,zY]=str(val(zombies[kk,zY])+(w*4))
/// display health meter
health_=val(zombies[kk,Zhealth])
zombies[kk,Zhealth_tstart]=str(GetMilliseconds())
// if zombie health is done.. he dies
if val(zombies[kk,Zhealth])<0
playsound(ZombieDieSound)
deletesprite(ZombieSpriteStart+kk)
sss=ZombieSpriteStart+kk
s1=sss+20000: s2=sss+40000
deletesprite(s1): deletesprite(s2)
rri=random(1,100)
if rri=1 or rri=5 or rri=17 or rri=19 or rri>40
ih=FindFreeItem()
ri=GetRandomItemImage()
CreateSprite(ItemSpriteStart+ih,ri)
items[ih,iX]=(zombies[kk,zX])
items[ih,iY]=(zombies[kk,zY])
if ri=healthkit
items[ih,iImage]=str(ri)
items[ih,iInv]=str(health)
items[ih,iQuanity]=str(15)
endif
if ri=moneyitem
items[ih,iImage]=str(ri)
items[ih,iInv]=str(money)
items[ih,iQuanity]=str(1)
endif
if ri=ammo
items[ih,iImage]=str(ri)
items[ih,iInv]=str(weapon1ammo)
items[ih,iQuanity]=str(10)
endif
endif
j=0
do
inc j
if j>20 then exit
zombies[kk,j]=""
loop
endif
// kill bullet once it hit zombie
if val(localsprite[sel_button])<>cannon
bd_=0: bullet[q]="0|0|0|0,0|0"
deletesprite(bspr)
endif
else /// if it doesnt collide with zombie
bullet[q]="1|"+str(bX_)+"|"+str(bY_)+"|"+bf$+"|"+str(bd_)
/// gosub BulletCollision
endif
endif
loop
/// if bullets goes its distance then kill it
if bd_>GetGunBulletRange(localSprite[sel_button])
bd_=0: bullet[q]="0|0|0|0,0|0"
deletesprite(bspr)
endif
` gosub BulletCollision
endif
endif
loop
return