hi! Hello, everyone, I am little ant. Today we continue the second part of how to make a tower defense mini-game, how to position turrets, and how to create different types of turrets.

How to set the turret position

The location of the yellow star is the location of the turret to be created. In tower defense games, the position of turrets is usually set according to the current terrain, meaning that turrets can only be created in the specified position.

In order to conveniently set the position of the turret, a spirit picture can be used as the logo. In the picture, I used the yellow five-pointed star as the logo of the turret position. You can directly drag the five-pointed star from the scenic spot to set the position of the turret. Then after the game starts we’ll use the turret create button to replace those pentacles.

Take a look at the building block logic on the pentacle that marks the location of turrets.

When the game starts, a clone creates a turret position button, and then hides itself.

Next, let’s look at the clone logic of the turret position button.

Focus on the first block and move yourself to the creator’s position as soon as the button is created. This will allow us to replace the star used to indicate the location of the turret with a button to create the turret once the game starts.

How to create different types of turrets

In tower defense games there are different types of turrets, such as fast attack but low damage, slow attack but high damage, etc. When we need to create different types of turrets, how do we do that with mini-game making tools?

This is where “global variables” come in. We can assign a type number to turrets. For example, for turrets that currently contain two types of turrets, we assign a type number 1 to the first one and a type number 2 to the second one. You can then create a global variable for the type of turret you want to create.

What is the global variable “create turret position index” used for?

Next, take a look at the building block logic for clicking the Create turret button.

First of all, we recorded the position index of the current turret in the global variable “current turret position index”, so that we could know which position to create the turret in the future. Then, the turret creation panel was displayed.

The turret creation panel displays a dialog box for selecting different turrets in the current button position.

Here I use a circular dialog box with two different turret creation buttons and a close button in the middle.

Next, let’s look at the logic on the different types of turret creation buttons.

Create turret 1 button block logic.

Create block logic for turret 2 button.

You can see that everything is the same except for “create turret type”. There is no specific logic to create a turret clone, just a “create turret” notification, as the specific turret-creation logic is handled on the “create turret button”.

Next take a look at the logical building blocks for the specific turret creation on the “Turret Creation button”.

Here we use the “current turret position index” variable to determine exactly where to build the turret, and then use the “type of turret created” variable to determine exactly what type of turret to build. Finally, after the turret is created, the Create button is removed.

One thing to note here is that after cloning the turret, we waited 1 frame before removing the Create button. Why do I have to wait 1 frame here? After the turret is cloned, the position of the turret needs to be set according to the position of the creator (create button). If there is no “wait 1 frame”, then the turret’s creator has been deleted after the clone, and the location cannot be set according to the creator.

Finally, take a look at the block logic when the turret clone starts up.

Here we set the turret position to the “Creator” position, where the “Create turret button” is located. As for the following block logic, we have already covered it in the previous section, so we won’t go into it here.

Finally, take a look at the effect of creating different turrets in different locations.

To summarize, to achieve the creation of different types of turrets at specified locations, we use two important global variables:

Current turret Position index: helps us determine where to build turrets.

Type of turret created: helps us determine what type of turret to create.

These two global variables serve primarily as data transfer, as the position of the currently clicked button and the type of turret selected in the create dialog are passed to the logic that ultimately creates the turret.

This way of data transmission with the help of “global variables” will often be used in micro channel game production tools, especially when it comes to slightly more complex functions, it can be said that it is necessary to use, if you do not know, you can take this to understand.


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!