Got another one for you guys, this one isn't a math problem though, I just cannot figure out whats wrong.
loop(20)
{
let x = rand(50, GetStgFrameWidth()-50);
let y = rand(50, GetStgFrameHeight()-50);
let count = 0;
while(count <= 300)
{
if(truncate(GetPlayerX()) == x+count || truncate(GetPlayerY()) == y+count || truncate(GetPlayerX()) == x-count || truncate(GetPlayerY()) == y-count)
{
x = rand(50, GetStgFrameWidth()-50);
y = rand(50, GetStgFrameHeight()-50);
count = 0;
}
count++;
}
CreateStraightLaserA1(x, y, 0, 75, 10, 120, DS_BALL_M_PURPLE, 30);
CreateStraightLaserA1(x+75, y+75, 180, 75, 10, 120, DS_BALL_M_PURPLE, 30);
CreateStraightLaserA1(x, y+75, 270, 75, 10, 120, DS_BALL_M_PURPLE, 30);
CreateStraightLaserA1(x+75, y, 90, 75, 10, 120, DS_BALL_M_PURPLE, 30);
TRingShot(x+37.5, y+37.5, 2, 12);
loop(5){yield}
}
This creates 20 squares made of 4 lasers each. Then a burst of bullets shoots from inside. The problem is I can;t have these boxes spawn too close to the player, so i added that while function. The function should keep the boxes at a 300 unit distance from the player, by getting a new random top left if the box would spawn over the player, but its not working and I have no idea why.