We will create two more enemy types that follow different attack patterns. The starfish in our first sprite are moving in a straight line one after the other. For the second enemy sprite, we will create a script that causes that enemy to spread out, making it a bit harder to avoid. For the third enemy, we will write a script that makes this enemy type a bit unpredictable, moving in a wavy pattern and turning unexpectedly.
Before we begin scripting, we need two more enemy sprites, which we will create using the following steps:
The sprites are automatically renamed as Starfish2 and Starfish3 as shown in the following screenshot. This is fine for our purposes, so there is no need to manually change the names.
We can now modify the script to create varied movement patterns. The basic idea stays the same. We generate a few clones over time that move across the screen independently based on their instructions.
Let's change the script for the blue enemy sprite to make the clones spread out instead of following behind each other:
-30
and 30
respectively, out of the point in direction () block and place it inside the turn <clockwise> block.-90
degrees (towards the left side).3
in the repeat () block.0.3
in the wait () secs block.The following screenshot shows the final script:
These enemies will spawn a bit slower and in smaller groups than the red enemies. With a small addition to the script, they also have a very different movement pattern. The blue enemies will start moving at different angles. This makes them spread out as they advance.
The yellow enemy will also take the red enemy script as a basis. To make this enemy move even more erratically, we will place a turn command inside the clones instead of placing it inside the original sprite.
We will focus our attention on the clone script first.
-30
to 30
respectively, from the point in direction () block in the <green flag> script to the newly created turn block inside the clone script.-10
and 10
to decrease the angle variation.-90
(left) degrees.5
to 4
.The following screenshot shows the final scripts:
As a final step in this project, let's make the enemies an actual threat to the player. When an enemy touches the player sprite, it should be game over for the player. Now that we have created all enemies, we can easily check for collisions with them.
When a starfish touches the diver, the game will freeze immediately by effectively ending the game.
We now have three similar yet distinct enemies to challenge the player. Run the game with the <green flag> button to see all of them go at once.
This project shows that a few simple changes can have big results for your game. It's often not necessary to invent a completely new script for each sprite. Clever copying and reusing of what you already made can save you a lot of time.
3.15.34.39