Create enemy waves in GameMaker
How to create enemy waves in GameMaker
You need to have followed the tutorial on creating a persistent object in the previous tutorial Create a score that keeps its value between rooms.
-
Add this global variable to the Create event of objVarPersist:
global.wave=1; -
Create an object called objEnemyWaves
-
In Create event add the following code:
//wait 10 seconds for the alarm for the first time alarm[0]=room_speed*10; -
Add an Alarm [0] event with the following code:
//increment the wave global.wave++; //Change the spawn rate and max enemies //or feel free to change one or none at all //take 5 from the high spawn rate value objEnemySpawner.spawnRateHigh-=5; //add 5 to enemy count objEnemySpawner.maxEnemies+=5; alarm[0] = room_speed*10; //re-trigger the alarm every 10 seconds -
Add the objEnemyWaves to the room
-
You can show which wave you are on by adding the following to the Draw event of objScore:
draw_text(100, 10, "Wave: " + string(global.wave)); -
Open the Alarm event of the enemy spawner object.
If you want to spawn different enemies on odd and even waves, wrap the instance_create_layer() method in an if statement like the following. Note you will have to create a second enemy sprite and enemy object. You can also give the second enemy object a different speed, movement and health if you like.if((instance_number(objEnemy) < maxEnemies)){ if(global.wave%2==1){ //check if there is one leftover, therefore odd instance_create_layer(irandom(room_width), irandom_range(0,50), layer, objEnemy); }else{ //on the even waves instance_create_layer(irandom(room_width), irandom_range(20,50), layer, objEnemy2); } }
Learn more About Enemy Spawning in Code, Create, Play: Your 7 Day Guide to Game Development

Learning GameMaker?
Code Create Play takes you through building a complete game step by step over seven days.