Endless enemy wave generation

Started by
7 comments, last by triggdev 10 years, 1 month ago

I'm trying to figure out a way to generate endless waves of enemies in a space shooter. The waves will progress after you kill each enemy in the current wave. I want a way to generate different types of enemies with different strengths. I've already set up all of these enemies, I just need numbers now.

I've been thinking you could use prime numbers and the distance between each prime number would be the number of enemies. The problem with this is that you wouldn't really have much of a difference in waves.

My next thought was to use the fibonacci sequence, but I'm still stuck.

Does anyone have any ideas on how accomplishing this?

I want waves to be something like this -

Wave 1

Tier1: 4

Tier2: 2

Tier3: 0

Tier4: 0

Tier5: 0

each tier is a type of enemy varying in health, speed and strength. So wave 1 would have a total of 6 enemies.

Advertisement

I am sorry, but your question is a bit vague, and very general in nature .

Pass in the "wave number" variable when the enemy object is created, and use that to determine the internal states of speed, health, e.t.c.

Enemies per "stage" can be easily determined by a incremental math.

If you want 8% more enemies per wave ?

" enemy_number *= 1.08 "

I hope I interpreted your question correctly.

I cannot remember the books I've read any more than the meals I have eaten; even so, they have made me.

~ Ralph Waldo Emerson

I'm making a space shooter too. I'm not making enemy waves yet, but I'm thinking of this:

- a list of tiers has all possible tiers sorted in ascending order

- each wave is a tier window that includes enemies from a low tier to a high tier (for example, a window that starts at 2 and has a size of 3 will include tiers 2, 3 and 4)

- the tier window moves to higher tiers as you defeat more enemies or as you move forward

- the window size may grow or shrink, so that some waves have more different tiers than other waves

I am sorry, but your question is a bit vague, and very general in nature .

Pass in the "wave number" variable when the enemy object is created, and use that to determine the internal states of speed, health, e.t.c.

Enemies per "stage" can be easily determined by a incremental math.

If you want 8% more enemies per wave ?

" enemy_number *= 1.08 "

I hope I interpreted your question correctly.

Oh sorry, I didn't mean to be vague.

All of the enemies have a predetermined health, speed and power attribute.

I have 5 tiers and 4 colors in each tier.

blue green orange black

1

2

3

4

5

i want to slowly increase form blue-1 to black-5, hitting all tier/type combinations.

I think this is more in the range of a algorithm design question I think, If I understand you correctly, you are trying to figure out how to go from wave to wave and with each wave, increase tiers/attributes.

I don't think you're having trouble implementing the code, but more on how you want to make it happen. Right?

The easiest way is to probably simply keep track of the waves, every X waves you increase a tier and/or attributes. How you increase the X is entirely up to you, there are countless of possibilities for that. The same can be done for your tiers. If you up a wave, perhaps shift the numbers in your tiers down (so it becomes, 6, 4, 2, 0, 0).

Attribute increments can be done as shippou suggests, but it's all up to you on how you want to do it though.

Question: Do you want any variability in the waves of enemies being generated, or do you want the waves to be completely predictable, so that players know what to expect from each wave of enemies?

I would probably try some type of point system. Each enemy is worth a set number of points. The more power the enemy, the more points they are worth. Each wave gets something like (wave number) * 10 points worth of enemies.

If you want some variability, you randomly select enemies within a certain point range until you've used up all your points. To avoid having only 1 or 2 enemies in a wave, the total point allocation should have to be some multiple of the enemy point value for it to have a chance of being generated, say 5x. So for wave 1, you have a total of 10 points, but you will only randomly selecting enemies that are worth 1 or 2 points. At wave 2, you have 20 points, so you can randomly select enemies that are worth from 1 to 4 points, etc. You may want a lower cap as well, so at wave ten with 100 points, you are no longer potentially generating lvl 1 enemies.

If you want it completely deterministic, then you just need to replace the random selection with a deterministic selection. A simple solution would be to add (point total / 4) point enemy to the wave, until your point total is 0.

So for wave 1:

10 / 4 = 2 point enemy;

8 / 4 = 2 point enemy;

6 / 4 = 1 point enemy;

5 / 4 = 1 point enemy;

4 / 4 = 1 point enemy;

3 / 4 = 0 point enemy (automatically elevated to minimum 1 point enemy)

In both scenarios you can tweak point totals/values, multipliers, divisors to adjust wave generation and scaling.

If you want pseudo-random or random content you can use a sequence for the creation.
You can use creators as a framework that offers great prototyping flexibility.

You can define a source interface for values that you use for decisions:
public interface StreamSource {
int consumeInt();
long consumeLong();
char consumeChar();
byte consumeByte();
float consumeFloat();
double consumeDouble();
}
Then use another interface that creates objects using the value source:
public interface ObjectCreator<OBJ> {

OBJ create(StreamSource streamSource);
}
Now you can write data containers (e.g. the classes Wave and Enemy) and creator implementations that create actual content.
There are dependencies between Waves and Enemies ... a Wave creator will use an Enemy creator to create enemies that are right for the level of the wave instance, for example.

The way I accomplish that is with Context interfaces (obviously this is just to show the basic idea ... no null checks, do default behaviour etc.):
public interface EnemyContext {

int getMinStrength();
int getMaxStrength();
}

public class WaveCreator implements ObjectCreator<Wave>, EnemyContext {

private final EnemyCreator enemyCreator = new EnemyCreator();

private WaveContext context = null;

public WaveCreator() {
enemyCreator.setContext(this);
}

public void setContext(WaveContext context) {
this.context = context;
}

public int getMinStrength() {
return getMinStrengthByWaveLevel(context.getWaveLevel());
}
public int getMaxStrength() {
return getMaxStrengthByWaveLevel(context.getWaveLevel());
}

public int getMinStrengthByWaveLevel(int waveLevel) {.
...
}
...

public Wave create(StreamSource streamSource) {

Wave wave = new Wave();

int numberOfEnemies = 10;
numberOfEnemies += streamSource.consumeChar() % 10;

for (int i=0; i<numberOfEnemies; i++) {
wave.registerEnemy(enemyCreator.create(streamSource));
}

return wave;
}
}
The game itself or a module would register itself as the wave context and increment the level. That change would create different waves.
Notice how the context influences the object creation in a controllable way while the streamSource is responsible for (pseudo) random decisions.

This is Java code, but I hope the concept translates well ... you have a lot of freedom in the create functions so you can play with different approaches and add complexity pretty easily.

I can attach a Java implementation of a random stream source and a fixed stream source (fibonacci sequence - for reproduceable content with a random character) if you are interested ... if you do not see how it all would come together feel free to ask ...

Guess for what you have in mind the streamSource is irrelevant, though.
You would just ask the context for the current wave level and play with implementations of create until you find a strategy that produces waves that you are happy with.

Rough fibonacci implementation without a random character:
public Wave create(StreamSource streamSource) {

Wave wave = new Wave();

for (int tierNumber=1; tierNumber<=5; tierNumber++) {

setCurrentTier(tierNumber);
int numberOfEnemies = getNumberOfEnemies();

for (int i=0; i<numberOfEnemies; i++) {
wave.registerEnemy(enemyCreator.create(streamSource));
}
}

return wave;
}

private int getNumberOfEnemies() {
return (3 + getFibonacci(context.getWaveLevel())) / getCurrentTier();
}

private int getFibonacci(int n) {
if (n == 0 || n == 1)  return n;
else
return Fibonacci(n - 1) + Fibonacci(n - 2);
}
Obviously in this case the enemy context must contain the method getCurrentTier(), so that the EnemyCreator knows what tier it has to create an enemy for.
Given enough eyeballs, all mysteries are shallow.

MeAndVR

Btw. I think that something linear will probably be fine if you combine several properties that define a wave. Fibonacci would get too crazy too fast.

For example, using level classes that have the same number of enemies in a peak tier might work. The peak tier changes from 1 to 5 ... within one level class.

Another property could be a factor that determines how many enemies the neighbouring tiers have (e.g. peakAmount / (2 * tierDistance)).

Then you'd have to ensure that with each class change the number of enemies in the peak tier changes enough that it is harder than the last wave of the previous class. That might be the tricky part.

Given enough eyeballs, all mysteries are shallow.

MeAndVR

Thanks for the help everyone!

I decided to go with a simple y = 7 * sqrt(x) curve and i just generate a percentage of y for each type of enemy in the tier.

This topic is closed to new replies.

Advertisement