Coding in the Classroom: How to code a platformer game with your class

At Code Rangers before we start a new project we ask:

  • are there quick wins, and natural checkpoints where everyone will have something that ‘works’?
  • can the keenest students be truly challenged?
  • does it involve both visual creativity and good coding logic?
  • will our students be delighted with their results?

With a simple platformer game, all the boxes are ticked, and we’ve seen some stunning results in class the last few weeks. (Play a platformer built by an 8 year old here.) Working out how to incorporate coding in the classroom can be tricky, but a platformer is engaging and touches on many curriculum elements.

PlatformerCodedWithScratchScreenShot.png

 

What is a platformer?

It’s a simple game where a character travels from left to right across the screen, avoiding obstacles, catching rides, and reaching a goal before moving to the next level. Usually gravity will drag a character towards earth, while keystrokes move the character up, left and right. Here’s our starter project.

How do you code a platformer?

We use Scratch - we’ve talked before about why we love it, and why it’s so great in the classroom.

You can download full instructions for our starter platformer from our website. In summary, in our coding class we worked together to:

  • create a character (a cat, a dog, an astronaut…) either by choosing one from the sprite library or drawing it

  • code arrow keys and the space bar to move the sprite left, right, and up - this is our first checkpoint and students can now move a sprite around the screen

  • discuss gravity: how we can make a sprite forever fall downwards

  • create the ground - a single colour block on which the sprite can rest. This introduces sensing blocks and also conditionals - ‘if touching colour… then... ‘ and is a great starting point for a discussion about how we cancel out the impact of gravity - here’s our second checkpoint

Once students have the idea of using conditional, or ‘if’ statements together with colour blocks - then the fun starts:

  • choose a range of colours to be: springs, lava, magic carpets, and goals: the logic is all the same - if touching a colour, then do something (move, travel up, move at the same speed as the coloured block, move to a new backdrop.)

  • Create multiple backdrops with the same colours repeated to make increasingly challenging levels

  • Add sound effects

  • Make your new sprites fade in and out / spin, move.

  • Add a timer to make the game harder

Once our coding kids are through checkpoint 2 it really is up to them how far they take it, and projects can take many weeks to complete.

If you’ve got access to a makerspace (lucky you) with makey makey sets, this project is a great one for making a controller - all you need is to design a controller making use of the arrow keys and / or space key.

 

The Australian Digital Technologies Curriculum

The logic of a platformer is fairly simple and students swiftly build confidence to make the game their own. At the same time a Scratch project like this touches on the following points in the Stage 2 Australian Digital Technologies Curriculum:

ACTDIK007: Identify and explore a range of digital systems with peripheral devices for different purposes, and transmit different types of data.

The platformer uses the keyboard to perform input functions, and if a makey-makey is used this is an additional input. The monitor and classroom projector display information from the project.

ACTDIK008: Recognise different types of data and explore how the same data can be represented in different ways.

The project includes images, sounds, and animations which are all forms of data when stored or viewed using a digital system.

ACTDIP010: Define simple problems, and describe and follow a sequence of steps and decisions (algorithms) needed to solve them.

Students are encouraged to solve problems in creating their platformer: how can I create a new challenge feature? How does it behave? What happens when it touches another sprite?

ACTDIP011: Implement simple digital solutions as visual programs with algorithms involving branching (decisions) and user input.

Students use decisions to design their project, for example if a sprite touches a colour, then do something. Scratch is a visual programming language. User input is via the keyboard (or makey makey set).

ACTDIP013: Plan, create and communicate ideas and information independently and with others, applying agreed ethical and social protocols.

Students are encouraged to plan their projects together, to play each others games when complete and to provide constructive feedback.

Scratch is an online community where students are able to view others users work, and comment. There is a full set of Scratch community guidelines.

What other projects have you coded in the classroom? Do you have a go-to project for stage 2 students? How else are you using makey makey sets? Find other resources for teachers on our teachers’ page.