spacing between damage area spawning - help me

kureoni

Member
I'm programming a boss that spawns areas of damage across the map, but right now some areas spawn in the same place or too close to each other,

thats the code for the spawning in an alarm event, it uses random ranges to define the y and x of the damage areas, of course that there is nothing in this code that set any spacing, so, how can i change this code to:

1- spawn the areas of damage randomly in a pre-defined area
2- set a space between the areas so them will be well spread across the map

GML:
if(instance_exists(obj_player)) && life >0{
        
xis1=irandom_range(375,1200)
yps1=irandom_range(220, 570)

xis2=irandom_range(375,1200)
yps2=irandom_range(220, 570)


xis3=irandom_range(375,1200)
yps3=irandom_range(220, 570)


xis4=irandom_range(375,1200)
yps4=irandom_range(220, 570)


xis5=irandom_range(375,1200)
yps5=irandom_range(220, 570)


with(instance_create_layer(xis1, yps1,"Instances", obj_thirdblaze_bullet)){
        depth=200
        
}
with(instance_create_layer(xis2, yps2,"Instances", obj_thirdblaze_bullet)){
        depth=200
    
}
with(instance_create_layer(xis3, yps3,"Instances", obj_thirdblaze_bullet)){
        depth=200
        
}
with(instance_create_layer(xis4, yps4,"Instances", obj_thirdblaze_bullet)){
        depth=200
}
with(instance_create_layer(xis5, yps5,"Instances", obj_thirdblaze_bullet)){
        depth=200
}

alarm[0]=120
}
the image shows how they are spawning rn
 

Attachments

Nocturne

Friendly Tyrant
Forum Staff
Admin
Moderator
Spawn them one at a time on a loop and do a collision_circle check around the spawn area. So, something like this:

GML:
if(instance_exists(obj_player)) && life >0
{
repeat(4)
    {
    var _x = irandom_range(375,1200);
    var _y = irandom_range(220, 570);
    while (collision_circle(_x, _y, 64, obj_thirdblaze_bullet, false, false)) // Change the radius to suit...
        {
        _x =irandom_range(375,1200);
        _y =irandom_range(220, 570);
        }
    instance_create_depth(xis1, yps1, 200, obj_thirdblaze_bullet)
    }
}
 
Top