Skip to content

Commander and Enemies

benicoll edited this page Apr 14, 2013 · 4 revisions

This page introduces the Commander (Commander.cs) and Enemies

Commander

Purpose

The commander is used to generate enemies for the game. Every universe holds a commander script, with generation working independently for each universe. The commander is capable of sending a wave of enemies, a wave of enemies, or a boss, and is build to work with as much randomisation and unpredictability as possible. It also controls how difficult the game gets, as this is entirely based on the enemies you encounter. All enemy generation takes place on the server, and is then synched to the client through the movements of enemies, meaning that Commander should only ever really cause direct changes on the server.

How It Works

On initialisation ( Start() ), commander sets some variables before calling the "StartGame" IEnumerator. This starts a delay, before sending the first wave of enemies.

Enemy generation then works as follows (in the simplest possible case):

  1. Pick a random number between 0 and astProb (exclusive)
    • astProb can be set, and is the probability of encountering an asteroid belt (so 3 means in 1 in 3 chance). A sane value is 5, though for testing you may want to experiment. Set to 1 to always have asteroids, and high (say 200) to "never" encounter them.
  2. If the number chosen is the highest possible value, send an asteroid belt. Otherwise, send a wave of enemies.
  3. Send the next wave by repeating these steps when the previous wave has been cleared (or the timeout clause has been met).

That's really all there is to it!

Difficulty Variables

At present, there are 6 different variables that are used to control difficulty. These are adjusted as the player makes progress in the game. They are as follows:

  • beltLevels - the number of different levels (or tiers) within a single asteroid belt
  • minAstsInBelt - the minimum number of asteroids within a single level of an asteroid belt
  • maxAstsInBelt - the maximum number of asteroids within a single level of an asteroid belt
  • enemyTotalStrength - the "strength" of the deployed enemies within a single wave
  • minEnemyClearanceTime - the minimum amount of time the player is given to clear a single wave of enemies
  • maxEnemyClearanceTime - the maximum amount of time the player is given to clear a single wave of enemies

When choosing a difficulty variable to increase, min and maxEnemyClearanceTime are grouped, and min and maxAstsInBelt are grouped. This leaves 4 possible selections to increase.

Asteroid Belts

Belt Generation

The "SendAsteroidBelt" function is used to send an asteroid belt. It works as follows:

  1. Turn on all background asteroid particle systems
  2. Rotate all players in the current universe to the "camera behind" view"
  3. Create the asteroid belt a level at a time, repeating the following beltLevels times:
    • Create one asteroid at the current height of the player
    • Pick a random number between (minAstsInBelt-1) and (maxAstsInBelt) exclusive
    • Send this random number of asteroids at random heights
    • Wait for beltGap seconds before sending the next level in the belt
  4. Turn off background asteroid particle systems

Asteroid Creation

  1. Pick a random height within the confines of the screen
  2. Pick a random x position between positive and negative of the x offset value to allow for the asteroid belt levels to appear as a continual belt. Add this to the far border of the screen and an offset used for generation.
  3. Instantiate the asteroid. This will then move across the screen.
  4. Pick a random scaling factor between minAstScale and maxAstScale, and scale the asteroid by this factor.
  5. Make note of the asteroid to allow for tidying on the game's end.

Enemy Waves

The "SendEnemyWave" function is used to send the next wave of enemies. It works as follows:

  1. Take enemyTotalStrength
  2. Until enemyTotalStrength = 0:
    • Pick a random number between 1 and min(enemyTotalStrength, 5) exclusive
    • Deploy the enemy with this strength (e.g. 1 = light, 4 = superheavy)
    • Decrease enemyTotalStrength by this random number
  3. Start a countdown until the next wave is deployed. This countdown runs for a random time between min and maxEnemyClearanceTime.

Note that the countdown timer is cancelled if the wave is cleared, at which point a new wave is automatically sent.

Difficulty Increases

Difficulty increases are intended to be as random as possible, and occur after a set period of time has passed. A random number is selected in the range of the number of potential difficulty variables. This variable is then increased/decreased by a set amount, unless it has already reached it's preset min/max value. These presets are used to prevent the game from becoming too ridiculous.

The random difficulty increases mean that 2 players in different universes of the same game will have the same overall difficulty, but may be difficult in different ways. For example, one universe may have very difficult asteroid belts but easier enemies, while another universe faces a lot of enemies but easier asteroids.

Enemies

This section will inform you about the different types of enemy that are present in the game. To Be Completed (14/04/2013)

Clone this wiki locally