enemy waves gamemaker

Create enemy waves

To create enemy waves

You need to have followed the tutorial on creating a persistent object in the previous tutorialCreate a score that keeps its value between rooms.

  1. Add this global variable to the Create event of objVarPersist:
    global.wave=1;
  2. Create an object called objEnemyWaves
  3. In Create event add the following code:
    //wait 10 seconds for the alarm for the first time
    alarm[0]=room_speed*10;
  4. 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
  5. Add the objEnemyWaves to the room
  6. 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));
  7. Open the Alarm event of the enemy spawner object.
    If you want to spawn different enemies on odd and even waves, wrap the instant_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);
     }
    }

Share and Enjoy !

Shares

Similar Posts

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.