Adding levels – three simple steps

If you have not done so, test the current code. If you are a good gamer, you should ace this and finish both levels in no time. To make the game harder to beat and more interesting, let's add two new levels using Monster and Robot.

Prepare for lift off

For each game level, there are different enemy types, enemy counts, and level timeouts. The enemy type is the name of the enemy sprite, enemy count is the number of enemies to create, and the level timeout is the maximum time each level lasts. The level can move up before the level timeout if enough enemies are eliminated.

With the Configure Level () block, it's very easy to add new levels and we will do just that in this section. The following screenshot shows the complete level list when we are done:

Prepare for lift off

Essentially, we are going to add level information for the two new levels to the three lists: the enemy type, enemy count, and level timeout lists. According to the following diagram, level one has 15 Rock clones and would advance when current enemy count goes below 3:

Prepare for lift off

Engage thrusters

To do so, we need to update Game Manager's scripts. Go to Game Manager's Scripts tab to find the when <green flag> clicked script, and add the following levels to it:

Engage thrusters

The steps to add two additional levels are as follows:

  1. Add set <max_game_level> to () and change value from 2 to 4.
  2. Change level 2 to level 4 in the Configure Level: 2 block to make Configure Level: 4 enemyType: Mother Ship enemyCount: 1 enemyThreshold: 1.
  3. Add Configure Level: 2 enemyType: Monster enemyCount: 15 enemyThreshold: 3.
  4. Add Configure Level: 3 enemyType: Robot enemyCount: 15 enemyThreshold: 3.
  5. Then, drop Configure Level: 2 and Configure Level: 3 between the Configure Level: 1 and Configure Level: 4 blocks.

Tip

Matching the Enemy sprite name exactly

Ensure that the enemyType field exactly matches with the enemy sprite name, including the spaces. Also, make sure that there is no space before or after the name string.

There we have it. We've added two additional levels in three simple steps. The resulting script is as shown in the following screenshot:

Engage thrusters

Objective complete – mini debriefing

There, we did it! We have added two levels in three simple steps, check out the Classified intel section on updating Space Age to have more than seven levels.

Classified intel

The Enemy Ammo and Game Manager sprites come with enough costumes to go up to seven levels. This means that you can add up to seven levels with the steps described in this section.

To add more than seven levels, you need to add the matching number of costumes to both the Enemy Ammo and Game Manager sprites. For example, if you are really ambitious and want to have 100 levels in Space Age, you need to have at least 100 costumes for the Enemy Ammo and Game Manager sprites.

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

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