The next step is to add an enemy for the player to dodge or defeat. We will look for another suitable watery character to continue the underwater theme of this game. We will make some changes to the appearance of the character and then write some movement scripts for the character.
Let's search for a suitable enemy for the diver character using the following steps:
The original sprite will be placed on the right side of the screen. From there, we will use the cloning method to generate waves of starfish moving left towards the player character by following these steps:
30
in the set size to ()% block to make it smaller. It should be about the same size as the diver.We will make the sprite jump to a random location vertically, point in a somewhat random direction to the left, and then spawn five clones.
240
, the right edge of the stage. The y value will be a random value between -180
and 180
, the full y range of the stage.-90
. We will modify that value with a random range. The direction may deviate 30 degrees both ways. So we replace the fixed direction using the pick random () to () block; enter the values-60
and -120
respectively.5
in the repeat() block.0.2
in the wait () secs block and wait between each cloning process to put some space between the clones.1
and 3
in the wait pick random () to () secs block respectively.The following screenshot shows the final script:
Now we are ready to start moving those clones using the following steps:
5
steps each cycle (using the move 5 steps block).Test the game and you will discover that there is a problem. The clones won't show up or even if it does, only briefly. What is happening? Why are they disappearing so quickly? The answer is easy. We just instructed the clones to delete themselves when they are touching an edge. The clones start their life on the right edge of the stage, so they are immediately deleted after creation.
We can fix this problem by adding another loop to the script as shown in the following steps:
10
.5
.This will ensure that the clones will first move 10 x 5 = 50 steps. This gives them enough room to clear the right edge before starting to check for collision with the edge.
The first wave of enemies are now happily flying across the screen. We will add a bit more functionality later. The enemies will be able to kill the player character upon touching him, and likewise, they may be killed by the player if he uses his weapon.
But let's first add a few different enemies.
18.118.142.166