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.

  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);
     }
    }

Learn more About Enemy Spawning in
Code, Create, Play: Your 7 Day Guide to Game Development

What you’ll Learn

  • Setting up a game development environment in GameMaker.
  • Fundamentals of game design & coding.
  • Understanding basics of game graphics.
  • Coding essential game mechanics.
  • Using GML for enemy dynamics.
  • Managing player health and lives.
  • Implementing a scoring system.
  • Designing a home screen, menu, and end screen.
  • Enhancing gameplay with music and sound effects.
  • Enhancing gameplay with music and sound effects.
code create play book your 7 day guide to game development
Code Create Play:
Your 7 Day Guide to Game Development

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *