In the previous posts, I explained both the auxiliary sprites and the core sprite Land. In this post, I will analyze the other core sprite – Player sprite.
“when I receive Menu” Code Segment
There are two code segments of “when I receive Menu”. One of them is used to monitor the pressing of Space key. When that key is pressed, and Player sprite touches Green, Yellow or Purple color, a game level is selected. The program will then broadcast “Play” message. At the end of this code segment, it uses “stop this script” to stop the monitoring of Space key when entering into Play stage.
The second code segment of “when I receive Menu” is responsible for monitoring the pressing of Up, Down, Left and Right arrows, as well as s, d, a, w letters which have equivalent functionalities of the arrow keys.
Although it is an option to merge the two code segments of “when I receive Menu”, I would suggest to keep them separate. It is easier to read the code by putting different functionalities separately.
“when I start as a clone” Code Segment
Like Land sprite, the Player sprite also needs to create clone. If you play this game, you would notice the trails following the Player sprite, as circled in the below diagram. The trails actually are clones of Player sprite. Different from Player sprite itself, the clones use the “Trail2” costume which is a 2-D flat image and then change ghost effect till finally disappear. The final effect is a tail which shows the path of the Player sprite but fades away in a short time.
“when I receive Play” Code Segment
This code segment handles the behavior of Player sprite when the game enters into Play stage. It continuously monitors the key pressing behavior and checks if the Player sprite touches red or white color. Touching red color represents that the Player sprite moves onto the “burning” cube and invokes “Dead” message, while touching white color represents that the Player sprite moves out of the cube boundary, which would also end the game.
Please note that the costume of Player sprite changes to “trail2” and then restores to “Red2”. This step is completely necessary. Before judging if the Player sprite moves onto the red or white cubes, the game should switch its costume to “Trail 2”. Because “Red2” costume is a cubic shape, When its upper surface touches the neighboring cube, it will generate false positive death message.
“when I receive Beat Level” and “when I receive Death” Code Segments
These two code segments are easy to understand. They just hide the sprite and delete all its clones when the user passes one level or invokes “Death” status.
Till now, I have finished the analysis of the BeatCube! remix project. Feel fun for remixing projects? You could make it a try now on the Scratch website (https://scratch.mit.edu/) by starting from simple projects and sharpen your Scratch skills. 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.