Fart Catcher

Moving Platforms

The reason I asked you to use my version of level 2 is the gap you might have noticed in the middle of the layout. You’re going to create a platform that moves through this gap and that the player can jump on and ride!

Another level with different platforms

First, you’ll need the sprite for the platform.

Add a new sprite, name it Moving-Platform, and using the costume customisation tools in the Costumes tab to make it look like the other platforms (use vector mode).

Now, let’s add some code to the sprite.

Begin with the basics: to make a never-ending set of platforms moving up the screen, you’ll need to clone the platform at regular intervals. I picked 4 seconds as my interval. You also need to make sure that there’s an on/off switch for making the platforms, so that they don’t show up in level 1. I’m using a new variable called create-platforms.

Add code to create clones of your platform sprite.

Here’s how mine looks so far:

whenclickedhideforeverwait4secondsifcreate-platforms=truethencreatecloneofmyself

Then add the clone’s code:

whenIstartasacloneshowforeverifyposition<180thenchangeyby1wait0.02secondselsedeletethisclone

This code makes the Moving-Platform clone move up to the top of the screen, slowly enough for the player to jump on and off, and then disappear.

Now make the platforms disappear/reappear based on the broadcasts that change levels (so they’re only on the level with space for them), and the game over message.

whenIreceivelevel-1setcreate-platformstofalsehidewhenIreceivelevel-2setcreate-platformstotruewhenIreceivegame overhidesetcreate-platformstofalse

Now, if you try to actually play the game, the Player Character falls through the platform! Any idea why?

It’s because the physics code doesn’t know about the platform. It’s actually a quick fix:

In the Player Character sprite scripts, replace every touching “Platforms” block with an OR operator that checks for either touching “Platforms” OR touching “Moving-Platform”.

Go through the code for the Player Character sprite and everywhere you see this block:

touchingPlatforms?

replace it with this one:

touchingPlatforms?ortouchingMoving-Platform?