Zombie spawner

xS89Deepx

Member
I'm making a zombie game and zombie only spawns in 4 directions, check the image below...

zombie_sc.png

//here my code for zombie spawns

obj_zombie_spawner

create event -
alarm[0] = 100;
global.level = 0;

alarm[0] event -
if (instance_number(obj_zombie) < 3)
{
repeat (1 + global.level)
{
instance_create_depth(x+0,y+2560,0,obj_zombie);
instance_create_depth(x+5120,y+2560,0,obj_zombie);
instance_create_depth(x+2560,y+0,0,obj_zombie);
instance_create_depth(x+2560,y+5120,0,obj_zombie);
}
audio_play_sound(snd_levelup,0,false);
global.level += 1;
}

//Reset alarm
alarm[0] = 100;

but my question is how do i keep zombies in limits?

lets say in round 20, more than 100 zombies spawns at same time, which can slowdown and crash the game...so i only want 10 zombies in room but you have to kill 100 zombies to go to next round...just keep 10 in room, so how do i do that? HELP! ME FRIENDS ;)
 
Last edited:

flyinian

Member
Make a variable that tracks how many zombies you want on screen.
Make another variable that tracks the max amount of zombies to spawn in said level.
Each time the player kills a zombie, subtract the count from the max count.
Continue spawning zombies until max count reaches 0.



GML:
zombie_Maxcount  = 100; // in a room start event.

// step event;

// Spawn zombies
if (zombie_count < 10)
{

// Zombie spawning code goes here.

}
else
{

//  This else part isn't necessary. Just gives you an option on what to do if max zombies are spawned in. Like spawn in a boss or something.
// zombie count has been reached code goes here.

};


// All zombies are eliminated
if(zombie_Maxcount  <= 0 && zombie_count  <= 0 )
{

// Level passed code

}
I hope this makes sense or at least helps in some way. Took me a second to think this through. so, I do believe it's right or at least a decent start.

If anyone saw the series of edits,...
 
Last edited:
Top