Platform Game in Scratch

This week in Advancers, Oliver was out so Mark covered.  We built a platform game engine which will be really useful for powering all sorts of games and projects!

Download the completed Scratch Platform Game here!!

How did we build the game?

We did a list of the things we needed to happen and went through them one by one!  The list was:

  1. Get gravity working so the hero could fall – we did this by creating a gravity variable and adding it to the speed each frame
  2. Get the hero to stop when he hits the ground – we did this by using a custom block to stay above ground – the run without screen refresh was needed in all our blocks to make them instant!
  3. Get the hero to jump – we did this by setting the hero’s falling speed to a number.  We had to then figure out how to stop him from jumping when you hit jump and he’s in the air.  We did this by making sure he could only jump when he was touching the ground.
  4. Get the hero to “bump” his head – this was very similar to how we got the hero to stay above ground – in fact, we changed the same block to do the same thing for him when he was rising!
  5. Make sure the hero can’t walk up really tall pillars – this bit was TRICKY and Mark had to scratch his head for a while to remember the best way.  We got around this by setting a maximum height that he could climb over the ground.

I added some coins and death to the game to give an idea of how to use it.

The code is here for the main routine:

platform_hero_main

And the important “Stay above ground” custom block was here (remember to click the screen refresh option):

platform_hero_stay_above_ground

Lastly the tricky “Move” block which had the code to check for pillars:

platform_hero_move

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s