For loop unexpected behavior
Hi all
I have the following loop running for manual fire in my game
if mouse_check_button_pressed(mb_left){
instance_create_layer(x,y,"Instances",obj_bullet)
if (powerup == 1){
for(var i=0; i<=spread_level; i+=1){
var _bullet = instance_create_layer(x,y,"Instances",obj_bullet) ;
_bullet.direction += (spread_level*10);
_bullet.image_angle = _bullet.direction
var _bullet = instance_create_layer(x,y,"Instances",obj_bullet);
_bullet.direction -= (spread_level*10);
_bullet.image_angle = _bullet.direction
}
}
}
I'm expecting it to make a new bullet on either side of the main bullet for each point in "spread_level"
spread_level 1 = 3 bullets
spread_level 2 = 5 bullets
spread_level 3 = 7 bullets
that's not what's happening though.
spread_level = 1 is resulting in 3 total bullets
1 aligning to the image_angle of the player sprite
2 others at +10 and -10 degrees
spread_level = 2 just makes the 2 additional bullets increase their angle by 10 degrees for a total of 20
spread_level = 3 - 2 additional bullets are at 30 degrees now
Any suggestions?
Thanks