• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Game Freezes thanks to enemy Spawner

L

LanderMiskolczi

Guest
So My game freezes, Idk if my game is stuck in a loop or something else, Can I have help?
It only freezes when enemyCount is equal to 7
OB_SPAWNER
Create
Code:
/// Varabiles
enemyCount = 0;
ranX = 2;
ranY = 2;
Alarm[0] (Only has a comment)
Step
Code:
/// Spawn Enemys
if (enemyCount <= 25)
{
    if (alarm[0] <= 0)
    {
        do
        {
            ranX = irandom_range(0, room_width);
            ranY = irandom_range(0, room_height);
        }
        until (!collision_point(ranX, ranY, ob_wall, true, true))
       
        instance_create(ranX, ranY, ob_enemy);
        enemyCount++;
       
        alarm[0] = room_speed*2;
    }
}
Draw
Code:
/// Draw enemyCount
draw_text(room_width-98, 16, 'Enemys: ' + string(enemyCount));
draw_text(room_width-226, 32, 'RANX/RANY: ' + string(ranX) + '/' + string(ranY));
I think this is the problem but I have no idea, There is another do loop in my game, but I dont think thats the problem if you want to see it tho, here it is
SCRIPT I MADE
Code:
/// sc_choose_movement_type
alarm[1] = room_speed;
dir = choose(0, 1);
do
{
    randomX = irandom_range(0, room_width);
    randomY = irandom_range(0, room_height);
} until (!collision_line(x, y, randomX, randomY, ob_wall, true, true))
enemyType = enemyMovement[irandom_range(0, 3)];
 

TheouAegis

Member
It's both, probably.

Your first code checks if there is not a wall at a particular point. If there's no wall at that point, it creates the enemy there. Your code does not say, "Don't create the enemy at the specified coordinates if it will place it on a wall", it just says, "Don't create an enemy if there is a wall at the specified coordinates." So then your enemy is getting created so close to a wall that it is now inside the wall.

Then your other code is trying to find random coordinates such that there's no line collision with a wall from (x,y) to the specified coordinates. ...Except since the enemy is IN a wall, there's ALWAYS a line collision, so it freezes.

Your spawner code needs to take into consideration the enemy's mask before finalizing its spawn coordinates.
 
Top