hi! Hello, everyone, I am little ant. Today we continue the third section of making a tower defense mini-game, how to create different types of enemies, and how to use tables to edit data and create enemies.

How do you create different types of enemies

Now, we need to create three types of enemies in the game.

Average enemy: average damage, average speed, average health.

Fast enemy: low damage, high speed, low health.

Great enemy: high damage, slow speed, high health.

Once we’ve determined the three attributes, we just need to adjust the values of the attributes to distinguish the three different types of enemies.

Next we add three local variables for each enemy, namely these three attributes.

Let’s look at the use of these three variables in enemy logic.

Set the movement speed of enemies when they are created.

Reduces the value of local variable health when an enemy is attacked.

Reduces the player’s health based on the value of their local variable “damage” when the enemy reaches its destination.

Finally, we set up different Sprite images for the enemies, so we have created three different types of enemies.

Here the normal enemy and the fast enemy are used in the same image, the fast enemy is smaller and spins faster.

There are two main differences between different types of enemies. The first one is appearance, i.e. different graphics, animations, sounds, etc. The second is intrinsic, the different attributes of each type of enemy. By tweaking these two layers, you can create a variety of enemies.

How to edit enemy data using tables

In a tower defense game, enemies usually attack in waves, killing one wave and then another, until the last wave is eliminated.

So how do we set up waves of enemies in a level? How many enemies appear in each wave? What kind of enemies appear? Here we can use a very powerful form of data called a table.

This is a table of enemy data for a level, with 6 rows and 5 columns. * * * *

The first column represents the wave number of the current enemy, i.e. the current wave number of the enemy.

The second column represents the number of enemies to spawn in the current wave.

The third column represents the health of each enemy in the current wave.

The fourth column represents the current wave of enemy types.

The fifth column represents the time interval generated between each enemy in the current wave.

Each row in the table represents a wave of enemy data, assuming that we currently read the first row (wave) of enemy data.

Once we have this line of data, we actually know the following: in this wave, there are 3 enemies of type 1(normal), each enemy has 4 health, and each enemy is generated at a 3 second interval.

With this data in hand, we can create this wave of enemies in the game.

I set up in the data table and generate the interval of the two variables, primarily to increase of the differences between different wave number of the enemy, such as the first wave of enemies in the game and the fourth wave are the same type of enemy enemy, at this time is the number of generated by adjusting the enemy, HP or generate interval, to let the enemy differentiating the two waves.

There is no need for each wave of enemies to be completely different in appearance and attributes, we can add attributes to increase diversity, so that even the same type of enemy can produce many different effects and combinations.

How do you create waves of enemies

Once you’ve got a row of enemy data in the table, all you need to do is create enemies one by one.

First, we need to create two global variables.

Wave count of current enemies: This variable helps us keep track of the current wave of enemies, and we use it to get data for the specified row in the table.

Number of enemies killed currently: This variable helps us keep track of the number of enemies killed in the current wave, and we need it to determine whether the current wave of enemies has been killed and whether the next wave needs to be generated.

Next, take a look at the building block logic that generates a wave of enemies from tabular data.

Create an enemy function that clones the specified enemy based on the enemy type.

The clone logic also changed a little bit, using the health data in the table to set the health of the enemy.

So we’ve turned a line of data into a real wave of enemies.

How do you tell if a wave of enemies has been destroyed and if the game has passed? Let’s move on to the next block logic.

If the number of enemies killed is equal to the number of enemies in the current wave, the wave is eliminated. If the wave number of the current enemy is equal to the total number of rows in the enemy table, then all enemies are killed and the game is over. Otherwise, the next wave of enemies is generated.

Since one row in the table represents a wave of enemy data, the total number of rows in the table also represents the total wave number of enemies in that level.

Finally, let’s look at enemy death handling.

So that’s how you can use tables to edit and generate enemy data. This is just a simple example, but it’s important to understand how to use tables to set up game data and then apply it to your own game. You can try adding more types of enemies, adding more types of attributes to enemies, designing a richer enemy spreadsheet, and making tower defense a better game.

That’s the end of this section. In the next section, we will continue to share how to implement turret upgrades and sell features.


I will make games will also teach you to make games of the small ant, welcome to pay attention to the public account [small ant teach you to make games], learn more and game development related to the original tutorial.

Welcome to make a friend, vX: Xiaomayi6669

If the content of this article is helpful to you, please feel free to like and share. Your encouragement means a lot to me. Thank you!