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

Let’s continue the analysis of Grids the puzzle game. In the previous post, I analyzed the Grids sprite. Now, I will analyze another core sprite – player. Let’s start!

Player sprite

The player is super mini. It is of the arrow shape with different colors as its costumes. The Player could face different directions.

When I receive “nextlevel” Code Segment

The message “nextlevel” is broadcast by Level sprite. When Player sprite receives this message, it adjusts its initial direction and position based on the current level.

For example, when the current level is 5, the Player sprite will face the direction of 90 degree and be located at the position of (-35, 95), which is the place of 3rd grid.

When I receive Start Code Segment

This segment is the core one for the Player sprite not only because it is super long, but also because it handles the logic of when and how the Player sprite could move to the next grid.

Firstly, the code segment will judge if Instruction page is hiding and if current backdrop is “Gameplay”. When both conditions are met, it indicates the time to play the game. The whole code segment is then divided into four sections to judge if Up arrow key (or w key), Down arrow (or s key), Left arrow key (or a key) or Right arrow key (or d key) is pressed.

Take the example of when Up arrow key (or w key) is pressed. The program will judge the value of SquareSelected variable. If its value > 6, it means that the player is not located at the 1st row, but is located at the 2nd, 3rd or 4th rows, thus moving up is valid. The program also checks if the grid of “SquareSelected – 6” (the grid just above the current grid) has been passed before. If it is not included in TilesCovered list, the player should be able to move to that grid.

Continue analyzing this long code segment.

Some levels have a special white grid, which have to be passed twice. When the player enters into a white grid, that grid will become grey as if it has not been passed, so that it could be just like other unoccupied grids to wait for the passing in the following steps. This behavior of the grid has been handled in the code of Grid sprite.

Here in Player sprite, the white grid affects whether the player would create a clone of itself. When it is not a white grid, a clone of Player sprite is created. So what is the purpose of creating clone of Player? You could scroll down a little bit to check “when I start as a clone” code segment. Basically, those player clones show the trace of the player and also increase the visual effect of the game.

Continue this long code segment of “when I receive start”.

The following is another section which handles the condition of when Left arrow key (or a key) is pressed. The code structure is similar to that of Up arrow key (or w key). In this scenario, the program would judge if the current grid index is 1, 7, 13 or 20 which represents the 1st column grids. When it is, the left movement should not work.

Continue analyzing this long code segment.

The program will wait till the Down arrow key (or s key) is released, so that each pressing of key will pass through only one grid. Without this judgement, one keystroke will pass through several grids and makes the program over-sensitive.

When I start as a clone Code Segment

When Start clicked Code Segment

This code segment is easy. It generates a visual effect of player sprite.

That is all for the analysis of Player sprite. Keep tuning in our posts for the analysis of Level sprite. 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.

2 thoughts on “Learn Scratch by Analyzing Others’ Project – Grids the Puzzle Game Part 2

  1. I think this is among the most vital information for me. And i am glad reading your article. But want to remark on few general things, The website style is ideal, the articles is really great : D. Good job, cheers


Comments are closed.