Limiting the offensive power of the player helps to make the game a bit more challenging. But a single group of five enemies isn't much of an attack force to withstand. Let's give the player some more work to do by increasing the number of enemies and then create more enemy variants.
We will copy and edit a few scripts that we have already built to create more waves of enemies as shown in the following steps:
3
to 10
. This will increase the time between waves and makes sure one wave has moved a good distance along the road before the next wave is spawned.Enemies currently die on the first hit they receive. This makes them very weak and also not very Tower Defense-like. The enemies in these games usually have a healthbar , requiring multiple hits before they go down. This not only makes the game more challenging, but it's also visually appealing as you see the cannons tracking the enemies and trying to defeat them before they move out of range. So let's create a healthbar for our enemies. Instead of going down in one hit, they will be able to take 10 hits before being defeated.
There are multiple ways to solve this problem. But the easiest way of doing it is by creating multiple costumes, each with a slightly shorter healthbar graphic. Each time an enemy gets hit, it will advance to the next costume until it reaches the last one, after which it will be destroyed. The following are the steps to create the costumes:
At each step, the healthbar should be shortened a little. Since Scratch doesn't have a ruler in its drawing tools, you can't be pixel-perfect about it. I found the best way of doing it is to keep cutting the list of costumes in half. The first one has a full healthbar. The last one (number 10) has no healthbar left. So costume number five should have only half healthbar. Costume 2.5 (which doesn't exist, so we'll pick number 3) should have three quarters of the healthbar showing. Number 7.5 (again we pick a whole number, so 8) should only show a quarter.
Click back and forth through the costumes to visually check that you diminish the healthbar in equal steps for each costume.
Since the last costume is the enemies' dead state, we are going to reshape it to inform the player he has vanquished an enemy, as shown in the following steps:
With a script, we will step through the different costumes on each hit. This will make it appear that the hit bar shrinks and eventually the enemy is killed. The following are the steps to do it:
10
in the other slot. This will cause the script to repeat until the sprite is showing costume number 10, the dead state we just drew.0.05
by using the wait ... secs block.0.5
secs block just before the delete command.Test the game again to see that the enemies are indeed showing a healthbar and are losing health as they get shot, before disappearing after being hit 10 times. Now, we are well on our way to creating an enjoyable game.
To make things even more interesting, we will create two more enemy types. These behave in largely the same way as the first enemy. But with some minor changes to their scripts, we can make them behave quite differently. We will create a faster enemy that takes less time to travel the length of the road. We will also create a slower enemy that is harder to kill than the first enemy. Each type of enemy will be depicted in a different color.
Let's start with the fast enemy, the blues. The following are the steps to create it:
multiplier_B
(for blue).0.15
. This will make the blue enemies twice as fast as the red ones.We also change a few things about the wave patterns so these new enemies won't arrive at the same time as the original ones. To do this, follow the steps given:
8
, 20
, and 5
to change the pauses between waves.3
for all repeat loops. This will decrease the number of enemies spawned per wave.That's all there is to do to create fast enemies. Let's move on to the third type of enemy. Follow the steps given:
10
to 20
. This is all that's needed to make the enemy go through 20 hits before being destroyed.multiplier_Y
and again replace all instances of muliplier_R with the new one.0.5
to make this enemy slower than the red enemy.18
and 10
.2
to only create two enemies per wave.We now have an interesting army of enemies coming our way. Test the game and see how it looks. Take special note of when the enemies spawn, how fast they move, and how they respond to incoming fire. You can play around with the numbers in the < green flag> scripts to make the enemies appear in different patterns.
18.224.51.145