To finish off all the attack moves for the boss, let's create a third attack pattern script.
For this attack pattern, we are going to use an interesting mathematical formula called a sine wave. You might recognize this pattern from mathematics or from a radio wave readout. This pattern causes the sprite to move up and down in a regular curved wave pattern.
It looks very good and can be quite hard to dodge if you're not careful. It serves as a perfect "killer" move to close this part of the tutorial with.
This third attack pattern script starts and closes in exactly the same way as the other two. We start with receiving the message pattern3
and close by picking a new random pattern from the list, as follows:
170
and 0
respectively. This will be the starting position.-90
.500
times.The finished script will look like the following screenshot:
Now we get to the interesting part. We will use a sine wave formula to determine the vertical position of the sprite based on its horizontal position. This is why we needed to slow down the horizontal movement. At regular speed, the movement would be way too fast and bouncy.
0.5
. The resulting number determines how frequently the sprite completes a full wave (up-down and back to center). The higher the number, the shorter the wave.4
(using multiply). This number determines the overall speed of the wave motion. It's an optional number. It's not necessary to complete the formula, but it gives us more control.150
(using multiply). This part determines the amount by which the wave deviates from the center line. This number is literally the maximum vertical distance from the center line.This concludes our last attack pattern. We used a sine wave formula to create a smooth, waving pattern for our boss sprite. Now we can fully test the boss enemy's movement. Let's test it a few times to see how it looks. If desired, you can experiment with the different values for the movement patterns. The sine wave can especially change a lot if you play around with the numbers for a bit. Just keep in mind the previous explanation to estimate what changing a certain number will do to the wave.
3.139.86.18