Learn Scratch by Analyzing Others’ Project – Grids the Puzzle Game Part 3

Let’s continue the analysis of Grids the puzzle game. In the previous posts, I analyzed the Grids sprite and Player sprite. Now, I will analyze the core sprite – Levels. Let’s start!

Levels sprite

The levels sprite appears just like Grids sprite. It exists to allow player choose the level he/she wants to play. Only those passed levels could be selected for replaying. For example, if the player is playing level 3, he/she could choose to replay all the previous levels, but could not jump to play level 4 or above.

When I receive “levelselect” Code Segment

When player clicks the LEVEL SELECT button, which I circle it in yellow in the below diagram, the button will send out the “levelselect” message.

Once Levels sprite receives “levelselect” message, it will create 12 clones by arranging them in 2 rows by 6 columns, representing 12 levels.

When I start as a clone Code Segment

Here comes the main code segments for Levels sprite. Thanks to the code parallelism mechanism of Scratch, the three code segments of “when I start as a clone” implement different functionality. Let’s take a look at them one by one.

1st code segment:

This code segment will verify if the clone number “LevelSelectCostume” is included within LevelsUnlocked list. I it is included, the program will present a colored costume, otherwise, the program will show a gray costume (the Locked costume).

After that, the program will continue monitoring the mouse pointer. If the clone touches the mouse pointer, it will play a sound and change its size a bit to simulate the pressing effect.

2nd code segment:

This code segment will continue monitoring the mouse pressing down behavior. When the mouse presses on the clone, and the selected level is already included in the LevelsUnlocked list, it will set Level variable, play a sound and then broadcast messages of “start” and “nextlevel” to inform the beginning of a level.

3rd code segment:

This code segment will wait till Level variable changes to “-” and then delete the obsolete clones. Please note that Level variable is set to “-” in the above code segment “when I receive message of levelselect”.

When Start clicked Code Segment

This is the initialization segment for Levels sprite. It deletes all items of LevelsUnlocked list and then adds item value “1” to it. The result is that only level 1 could be played at the beginning of the game.

That is all for the analysis of Levels sprite. Till now, we have finished analyzing all of the three core sprites of the game. Like this puzzle game? It now has another Deluxe version since early players said that this version was a bit too easy. Check the more advanced version here: https://scratch.mit.edu/projects/246436261

Most of all, don’t forget to enjoy the coding and have fun!

Note: All the analysis articles are copyright products of http://www.thecodingfun.com. Anyone re-posting them should credit author and original source. Anyone using them for commercial purposes or translating them into other languages should notify TheCodingFun and get confirmation first. All Rights Reserved.