I'm programming a space-shooter mobile game with a sandbox gameplay style similar to Defender's. The player faces infinite waves of enemies moving towards his ship. The game has many upgrades the player can buy to increase his ship's strength.

It is important that the difficulty of each level matches the player's skill and strength. This includes setting the right number of enemy waves per level and the number and toughness of the enemies in them. This must be done procedurally, since the game has no predefined set of levels laid out by a designer.

I'm interested in straightforward solutions with more or less the desired effect, simple enough to quickly implement and test.

How should I approach this?

  • \$\begingroup\$ How important is it that the enemies in the next wave is calculated based on the player skill and abilities? Most games simply have a fixed set of enemy "a" in the beginning , a bossfight on let's say level 5, and then they introduce this new tougher enemy "b". Most games don't take into account if the player chose proper upgrades or not. Is this important to you? \$\endgroup\$
    – Tholle
    Commented May 15, 2014 at 19:23
  • 1
    \$\begingroup\$ This is a VERY subjective question because it all comes down to which parameters of human gameplay behaviour -- specific to your game -- you consider to be measurable, based off of which you would thus assess and assign AI strength. \$\endgroup\$
    – Engineer
    Commented May 15, 2014 at 19:57

4 Answers 4


The balance

I don't think there are shortcuts to balancing the game, it takes time and experimentation to find the best settings. You can increase the level of difficulty differently depending on how good the player is. The game will correct the difficulty to match the player skill. For example, the more lives he has the faster it gets harder. But I don't really think it is really a good idea, this kind of "mario kart" thing can be very frustrating. Even more in single player game.

Automate level creation

I can think of two differents way to acheive this. In both you keep a variable that correspond to the level of difficulty. You increase it as time passes. You can then create monsters depending on this variable, the number of them and their strengh. I will call this variable diff for the rest of the answer.

1) Random monster, random position (easier)

Each monster has a time before spawning, which is influenced by diff. It can be randomized to make it better looking. The position of the monster can just be randrom on the Y axis outside the view. For example, if the time is in ms.

fullTimeBeforeSpawn_monsterA = 200+1000/diff + random_between(-100,100);

When diff equals 1 a monster A spawns every 1.2 second and when it is equal to 1000 a monster A spawns every 0.2 second.

They can also have a window of diff where they can be created, for example monster C will not be created if spawn is inferior to 500. That will make the harder monsters arrive has the time passes.

2) Paterns increasing in difficulty (harder)

Another way could be to make patterns. You then randomly choose between the patterns. And just like the monsters, you can make them pickable for certain value of diff.

For example you can decide to have a pattern like on the following image. The red lines spawns a kind of monster and the blue line spawns another kind (They are still created outside the view).


The number of monster will depend on diff. Their position will be calculated to be at regular interval on the lines.

numberOfEnnemy_blueLine = 3+diff/10 // will never be 0
numberOfEnnemy_redLine = diff*diff/1000 // will increase faster than the blue
                                         // there will be more blue than red at the 
                                         // beginning and more red than blue at the end

The dots represent where the enemies are created.

Beginning Furter in the game

3) Why not both ?

In my opinion it looks better when these two options are used together. It gives the feeling that the main, strong and slow army is marching toward you while there are smaller and faster ennemies that need to be taken care of.

In fine

I know you were looking for an easy and fast solution, but in case somebody else is interested I developed my answer a bit further. There are a lot of ways to automate the creation of ennemies. Your system can balance itself if the difficulty is increased differently if the player is good or not but there will always be settings to choose. However, the balance doesn't have to be perfect the player can adapt.

  • 1
    \$\begingroup\$ The question was about difficulty, not about placing enemies, was it? \$\endgroup\$
    – API-Beast
    Commented May 15, 2014 at 22:07
  • \$\begingroup\$ I thought it was about how to make the game increase in difficulty with the player. So I understood it as how to manage the difficulty automatically, manage the creation of the monster. I think you are right though, I didn't develop the right thing. Should I delete it? \$\endgroup\$
    – Heckel
    Commented May 15, 2014 at 22:11
  • \$\begingroup\$ It was a fantastic answer @Heckel, I really like the ideia of the line formation, I think it should fit perfectly a space-shooter and shouldn't be very hard to set up an initial version and then expand as needed. Thanks a lot! \$\endgroup\$
    – glampert
    Commented May 16, 2014 at 1:46
  • \$\begingroup\$ @Mr.Beast, a good distribution of enemies should be enough to balance the difficulty, I think. \$\endgroup\$
    – glampert
    Commented May 16, 2014 at 1:50

The problem with adaptive difficulty is that games live from problems the player "overcomes". If you analyze the strength of the player then that is very linear and predictable. Either it is too easy all the time or too hard.

I would suggest the opposite: Instead of changing the wave difficulty depending on the player strength let the player adapt to the difficulties ahead. Generate one difficulty progression at the start of the game and let the player know it in advance. If in 2 waves enemies will come that are resistant against arrow towers, tell the player. He will than be able to change his strategy accordingly. Add a user select-able difficulty level and you should have a game that is enjoyable for both "hardcore" gamers and "casuals".

How you generate that wave progression is a different question and will require a lot of tweaking values until you get a satisfying result. I would suggest first putting down some "milestones" and then interpolating between them.


  • Wave 1 is a few of small mobs
  • Wave 5 is a bunch of small mobs with a few special mobs mixed in
  • Wave 7 is a huge amount of the special mobs
  • Wave 10 is a random boss with both small mobs and special mobs mixed in.

After you have defined a progression like that by hand or procedurally you can calculate the waves in between, for example Wave 3 would be a few more small mobs and a single special mob.

  • \$\begingroup\$ Having a player selectable difficulty is also very valid. It can play well with the procedural generation. Thanks for the reply! \$\endgroup\$
    – glampert
    Commented May 16, 2014 at 1:52

PCG is hard to get right. There are always balance issues, because you always have a variety of gamer types (casual, hardcore, etc.) to balance between.

Since other answers are deep and technical, I'm going to provide a simple answer, inspired by the game "Warning Forever": keep track of what types of enemies kill your player and spawn more of that. Also keep track of what types get slaughtered by the player, and spawn less of that.

For example, imagine you have three types of monsters (A, B, and C). In the first wave, you spawn ten of each. At the beginning of the next wave, you notice that:

  • Monster A had the longest average lifetime (13 seconds)
  • Monster B caused the most player deaths (2)
  • Monster C is not significant statistically

Based on this, next wave, you might change the distribution to 40% A, 35% B, and 25% C.

This provides a procedurally-generated, but highly customized form of gameplay: players will see something different depending on their skill, and they can change their strategy from game to game. It could quickly become frustrating though, if they always have the same gameplay style.


You can always implement a "ratings system" for the player.

PlayerRating is calculated by the following

  • Ship Upgrades
  • Kills
  • Deaths
  • Score
  • Shots fire / hit

You have a max rating, say 100, that corresponds with the hardest enemies.

You start the game at 0.

Ship upgrade/power ups - If you gain "ultra blaster" it adds on 10 to your score. If you lose that powerup it subtracts 10. Kills / Misses (If you're in a side scroller etc) can add up to 10. Deaths - the more deaths divided by a percentage can LOWER your score...you aren't as good. High score + 10...if you are scoreing high, you are a better. Shots that actually hit / shots that miss. If you aim better you are better? (subjective) There are many variables you can put in your game to help calculate. So this number floats around and you can can generate your waves of enemies off this score.

If you have 10 different enemy ships:

PlayerRating < 11 enemy tier 0
PlayerRating < 21 enemy tier 1
PlayerRating = max Super Boss.


Not the answer you're looking for? Browse other questions tagged .