Creating attack pattern 2

Having only one pattern isn't all that exciting. So let's quickly continue with creating a second one.

Prepare for lift off

Attack pattern 2 will be quite different from attack pattern 1. We let the boss first pick a corner of the screen. We will use a new kind of script method for this called a switch case.

It then zigzags across the screen, forcing the player to keep moving about to avoid being hit.

Prepare for lift off

Engage thrusters

This script structure follows the same pattern as the first one. We start with receiving a pattern message. In the end, we let the script take another random pattern.

The interesting part takes place in the middle:

  1. First, we use set rotation style <left-right> so that the sprite stays upright while moving. It looks better with this pattern.
  2. Then we create another variable named switch (by choosing variable only for this sprite). We are going to use this as a random selector for the corner that the boss sprite will initially move to.
  3. Enter 1 and 4 in the set <switch> to pick random () to () block respectively.
  4. Then we create four if () statements called "cases" in this type of construction. Each case holds a different instruction and only one case can be valid each time:
    • The first case is if switch = () then glide () secs to x: () y: (). The values for the top-left of the stage are -200 and 150 respectively.
    • The second case is if switch = () then glide () secs to x: () y: (). The values for the top-right of the stage are 200 and 150 respectively.
    • The third case is if switch = () then glide () secs to x: () y: (). The values for the bottom-right of the stage are 200 and -150 respectively.
    • The fourth case is if switch = () then glide () secs to x: () y: (). The values for the bottom-left of the stage are -200 and -150 respectively.
    • Once a corner is chosen, we make the sprite point in direction -100 to angle it just off the horizontal line.
  5. Then we start a fixed repeat loop that will run 500 times.
  6. In each cycle, we move using the move () steps block. Due to the angle, we just set the sprite to move horizontally a lot and vertically a bit.
  7. We also check when it reaches the side of the stage and prevent it from getting stuck with an if on edge, bounce block.

These two blocks inside the loop will cause the boss sprite to move in a zigzag pattern across the stage.

Engage thrusters

Objective complete – mini debriefing

We now completed our second movement pattern. We changed the rotation style and created a list of starting points for the script to choose from. When the proper starting point and direction are set, we can smoothly move the enemy and have it bounce off the edges to create a zigzag pattern. Just one more to go and we have a complete boss fight (well, almost).

We can test the game now, but sometimes the movement of the boss will freeze when the third attack pattern gets selected. We can also test each attack pattern separately by just clicking on the proper script stack instead of running the entire program with the <green flag> button.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.167.183