The Game Manager sprite is the brain of the game. It manages game logic including scoring, level completion, winning, and losing.
When the user clicks on the green flag, Game Manager displays the start page with instructions and a start button. The game starts when the start button is clicked. After the game starts, Game Manager processes the broadcast messages sent from other sprites and decides on the following aspects:
At the beginning of each new level, Game Manager engages the user as well as the other sprites in the game. To users, it displays the level-up screen that scrolls up, giving the users time to wiggle their fingers before the next game. To the other sprites, it notifies that this level is over and the sprites then wrap up the current level and prepare for the next one.
Instead of creating the Game Manager scripts from scratch, we will use the complete Game Manager sprite from the starter project and add two new levels to it.
Game Manager is the most complex sprite in this game. The Space Age message flow diagram below shows that Game Manager is at the center of the happenings. It determines and announces each stage of the game play: start, level-up, and termination. Moreover, Game Manager scripts also enables existing levels to be configured and new levels to be added.
At system start (when <green flag> clicked), Game Manager displays the game rule to the user and prompts the user to play. It also initializes global variables and game levels. This initialization script is included in the starter project so that one can test the other sprites. Let's take a look at its when <green flag> clicked script:
8
and 13
, then switch costume to <Start Screen>, and show.2
.1
.0
.3
. If the enemy count goes below <min_enemy_count>, the player moves up a level.20
.
Add set <frame_rate> to () with the value 0.2
.15
and 20
. The enemy type must be exactly the same as the enemy sprite name. Make sure that there is no extra space.1
and 30
.The finished script looks like the following screenshot:
Game Manager also has a custom block to start a new level. It's called Start Level <level_num>. It's already included in the starter project so that one can test the other sprites. We do not need to make a change to the Game Manager scripts yet; let's take a look inside the Start Level () block:
-14
and -188
, then show and glide 4 secs to x: () y () with values -30
and 180
for x and y respectively. Then add hide.The finished script looks like the following screenshot:
To determine when to move the level up, an intuitive and simple way is to track how many enemies are left. If all the enemies have been shot down, then the level should go up, right? The answer is yes and no. Yes, if the game has very few enemy clones or if you do not use cloning at all. However, for a game such as Space Age, which uses many broadcast messages and clones, tracking the number of surviving enemies is not reliable. You can observe this for yourself by going to the Data tab and checking the current_enemy_count checkbox. Then, you can observe that the current enemy count does not always go down each time you shoot down an enemy, especially when the enemy clones are close to each other and you fire ammo rapidly.
To help with this problem, Game Manager uses current_enemy_threshold. If current_enemy_count becomes lower than current_enemy_threshold for that level, the game advances to another level.
Game Manager has a Configure Level () block that allows the user to configure existing levels or add new levels. Game Manager stores the configuration of each level in three lists: enemyTypeList, enemyCountList, and enemyThresholdList. The enemyTypeList stores the enemy sprite types for all the levels; the enemyCountList stores the enemy counts (how many enemy clones to create); the levelTimeoutList stores the level timeout.
The Configure Level () block is already included in the starter project so that one can test the other sprites. Let's take a look inside the Configure Level () block:
The following screenshot shows the final script:
3.142.133.54