grrrvahrrr
Member
Hi! I am trying to recreacte space invaders and i got a bit stuck at properly spawning enemy bullets.
I want a random enemy object from the bottom row to create 1 bullet with a certain cooldown. I got stuck on choosing a random instance of an enemy object to create a bullet. And i am a bit confused about where to put a random variable, because when i put it in a create event it only randomises once, and putting it in step event doesn't seem to work. Also with my code several enemies from bottom row create bullets, not 1...
Create event
step event
I want a random enemy object from the bottom row to create 1 bullet with a certain cooldown. I got stuck on choosing a random instance of an enemy object to create a bullet. And i am a bit confused about where to put a random variable, because when i put it in a create event it only randomises once, and putting it in step event doesn't seem to work. Also with my code several enemies from bottom row create bullets, not 1...
Create event
Code:
cooldown = 0;
randomise ();
inst = instance_find(obj_enemy, irandom(instance_number(obj_enemy)-1));
Code:
with (inst) {
if !collision_line(x, y+60, x, y+300,obj_enemy,false,false) && (cooldown < 1) {
instance_create_layer(x,y,"Instances",obj_e_bullet);
cooldown = 120;
}
}
if !instance_exists(obj_e_bullet) cooldown -= 1;