Scratch Lesson 13
Scratch Lesson 13
If youve have played one or more platform games (video games characterized by jumping to and from suspended platforms), you shouldve seen scrolling platforms. In this lesson, I will show you how to add platforms and make them scroll. Lets do it! Platform Sprites are usually immobile sprites that look like stage backgrounds but can interact with other sprites on stage. Moreover, they often are located at the bottom of the Stage and they could look like ground, wall, grass field, or brick pavement. Today, I will show you how to turn our simple Mini Mario game from Lesson 12 to a basic platform game using Platform Sprites.
ShallWeLearn | http://shallwelearn.com
Create a wide bar that spans the whole width of the drawing area.
Draw a wide bar which is enclosed in the pink wide bar. You can pick any color.
ShallWeLearn | http://shallwelearn.com
Click OK to save and rename this costume as Level 1. Then click Level1s Copy button.
ShallWeLearn | http://shallwelearn.com
ShallWeLearn | http://shallwelearn.com
Then use Stamp Tool to make copy of this brick and stack them as below. Then click OK to save.
ShallWeLearn | http://shallwelearn.com
With Platform sprite selected, click Scripts Tab, and then select Motion Tool Kit. Drag out go to x: 2 y:-164 block to the Scripts panel. Note that the x and y values of your go to x: ? y:? might be a bit different than 2 and -164. Its OK these numbers are filled in for you automatically by Scratch when you move a sprite on the Stage. Build a combo block as followed so that Platform sprite shows at the bottom of the Stage every time the game starts.
Create a combo block that repeatedly moves Mario down (change y by -4) until Marios shoe color is touching the color of the platforms top.
ShallWeLearn | http://shallwelearn.com
With this combo block, we need to change the combo block that does the jumping. This is what we had from Lesson 12 jumping involves going up (increase y) as well as going down (decrease y).
But since now weve added the combo block that moves Mario down until his shoes hit the platform, jumping now only needs to involve going up. Moreover, make Mario jump higher by increate the change from 30 to 60, so that Mario can jump over Crab.
Also, I modified where Mario shows in the beginning so he will fall down from the sky, just like the original Mario game.
TRY IT! Start the game now and you should see Mario fall down from above and
landed right on top of the Platform sprite. Try jump around and see Mario fall back down on the Platform.
ShallWeLearn | http://shallwelearn.com
Rename the duplicate sprite to CoinToPass. Delete all script in CoinToPass and add the following script block so that when CoinToPass sprite is touched by Mario, it would send out a broadcast message called next_level.
The Platform sprite would catch the next_level message and change its costume to Level2.
ShallWeLearn | http://shallwelearn.com
TRY IT! Now you can test your jumping skill. Note that you can do multiple jumps (by hitting UP multiple times) so it looks like Mario is flying or sky-walking. I just thought that its nice to let him have a bit more power.
Step 4: Bullets If you are like me, then you probably find this game pretty tough. If not, then you can skip this step. I guess you are pretty good at sky-walking. But for me, my Mario needs a bit help to fend off his enemies. Lets give him bullets, shall we?
Click this:
to create a new sprite and create a simple bullet trace that looks like
ShallWeLearn | http://shallwelearn.com
To tell bullet which direction to fly to, create a variable called facing_right and set it to true (set to 1) when Mario turns right and to false (set to 0) when he turns left. The updated relevant scripts look like this:
Now lets update Bullets script so that, when space key is pressed, it flies out from Mario to the right if Mario faces right and to the left if otherwise. Also, Bullet will keep flying until it touches the edge of the Stage, then it would hide.
10
ShallWeLearn | http://shallwelearn.com
Finally, lets add a combo block to Bat and Crabs scripts so that they disappear when hit by Bullet.
TRY IT! Try attacking by hitting the space key. Liberating eh? THIS CONCLUDES LESSON 13. ITS TIME FOR MY BOBA TEA BREAK.
11
ShallWeLearn | http://shallwelearn.com