Re: Shooting Multiple Bullets

new topic     » goto parent     » topic index » view thread      » older message » newer message
	for i = length(bullets) to 1 by -1 do  
		bullets[i][X] += bullet_speed  
		  
		if (bullets[i][X] >= GetScreenWidth()) then  
			bullets = remove(bullets,i)  
		end if  
		  
		DrawCircleV(bullets[i][X],bullets[i][Y],20,red)  
	end for  

If you remove from an array (bullets) when you have a for loop iterating over it, you shouldn't try to draw that bullet in the DrawCircleV line:

	for i = length(bullets) to 1 by -1 do  
		bullets[i][X] += bullet_speed  
		  
		if (bullets[i][X] >= GetScreenWidth()) then  
			bullets = remove(bullets,i) 
                        -- bullets[i] may no longer exist or 
                        -- it refers to something that has already been drawn. 
                        -- Go to the next iteration now! 
                        continue 
		end if 
		  
		DrawCircleV(bullets[i][X],bullets[i][Y],20,red)  
	end for  
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu