SCRATCH 3
Escape from the evil space squids!
Captain Les Pounder of the USS Rentaprize has to evade the clutches of the evil space squids, but can he do the maths to escape the planet?
OUR EXPERT
Les Pounder is associate editor at Tom’s Hardware and a freelance maker for hire. He blogs about his adventures and projects at bigl.es
YOU NEED
> Any Raspberry Pi
> Raspberry Pi OS
> Breadboard
> LED 330 Ohm resistor (Orange- Orange-Brown- Gold)
> 2x femaleto-male jumper wires
> Code: https://github. com/lesp/ LXF275- PiUser- SpaceEscape/ archive/main. zip
Block-based coding is a great way to introduce the concepts of coding, via an easy-tounderstand mechanism. Blocks of code are stacked to create a flow, and if we encounter a mistake, we can easily pull the code apart to “debug”.
Scratch is a popular block editor and in this tutorial we’ll create a space escape game, where our rocket is trapped on an alien world and we need to calculate the correct thrust for lift-off. If we get it wrong more than 10 times then the evil space squids will get us.
Scratch 3 should come pre-installed on your Raspberry Pi OS image, but if it’s missing it can be installed from the main menu, under Preferences> Recommended Software. Scratch 3 is found in the Programming category; place a tick in the box and click Apply to install. Once installed,Scratch 3 can be found in the main menu under Programming.
Open Scratch 3 . Before we write any code, let’s understand the interface. On the left are a series of colour-coded, categorised blocks of code. These blocks fall under categories that identify what they do: Motion to move a sprite, Looks to change their appearance, Control to create the logic for our code. The blocks are dragged into the centre area and then assembled into a project. In the top right of the screen we have the Stage – this is where our code will run, we see things move and we can interact with the code. Finally, in the bottom right is where all of the sprites, the characters in our game and the backdrop of our stage can be edited.