Introduction: How to Make a Simple Scratch Coding Chase Game (for New Scratchers)

About: My Moto: Making projects FROM Scratch IN Scratch

Are you new to Scratch? No problem! That's awesome because everybody starts off new to the things they become best at! In this quick, fun, easy tutorial for new Scratchers, we will be learning how to make an addictive Chase Game where your main player has to collect the stars and escape the bombs! We'll be focusing on character movement, variables (the score), and sound effects. Let's start!

Supplies

You will need to make a Scratch account by going to the Scratch website. Just search up 'Scratch' on your browser and make a new account or log in. Then make a new project by clicking the 'Create' button in the top left corner. Remember to delete the cat sprite before you start! Scratch is best used on a laptop or computer and an optional mouse. Got everything? Great! You're ready to code! My Scratch moto: making games from Scratch in Scratch!

Step 1: Assets

First, we need our assets (the sprites and backgrounds of the game). Because, well, we can't make the game without them! Let's get our main player. Hover over the little cat symbol in the bottom right corner. It will say 'Choose a Sprite'. Perfect! Click on that and you'll be greeted by a whole library of sprites! Choose a character for your game (the one you will make move and collect stars). In my example, I'm choosing an octopus, but you can choose what you like!

Now we'll need a background. It's a very similar process to getting a sprite! Hover over the little mountain symbol in the bottom right corner. It will say 'Choose a Backdrop'. Awesome! Click on that and, again, there will be a whole library of backgrounds to choose from! Choose a background that relates to your main player. In my example, I'm choosing an underwater background because my octopus lives in the ocean.

TIP: If you are struggling to find something you are looking for, use the topic buttons at the top of the sprite/backdrop library to find things related to that topic. You can also just search up what you are trying to find in the search bar!

Step 2: Player Movement

We want the main player to be able to move! Making sprites move is actually quite easy because we can just use some movement blocks. Don't be scared! It is easier than it looks. Press on your main player in the sprite section below the stage (mine's an octopus). On the very left side of your screen, there will be a vertical row of coloured circles. These are the types of code that we can use. But we are just using the 'Motion' blocks for now. Press on the dark blue circle called 'Motion'.

Scroll down the blocks for a moment and you'll come across some 'change x by 10' and 'change y by 10' blocks. Drag both of those onto your coding area (the place where you drag coding blocks and all the magic happens). Now drag 1 more of each. You'll now have 2 'change x by 10 blocks' and 2 'change y by 10 blocks'. On one of each, change the '10' to '-10'. So now you'll have 'change x by 10', 'change x by -10', 'change y by 10', and 'change y by -10'.

Press the yellow coloured circle called 'Events'. Drag 4 'when space key pressed blocks' to the coding area and connect 1 motion block to each of them. Press on the 'space' button on the block that has a little downward arrow next to it. It will come up with some options to change the text from 'space' to another key. Check the images I provided above so you know what key goes with what block!

Step 3: Improving the Movement

If you have experimented the movement of your main player by pressing the arrow keys on your keyboard than you'll notice that the movement is not very smooth. We can fix that easily! Remember to check the images that I have provided at the top because that will show what the code should look like. Go to the orange coloured circle called 'Control'. We are still on the main player sprite. Scroll down until you find the 'repeat until' block. It will look a bit different to the other blocks because it has a hole in the middle. That's okay! We put blocks into that hole.

Drag that block onto your code so that each of the motion blocks are inside it (check the image above). Then go to the green coloured circle called 'Operators'. There will be a 'not' block with a dark green gap next to it. Drag that inside the gap next to the 'repeat until' text for each of them. Now for the last part of improving the movement! Go to the light blue coloured circle called 'Sensing'. Find 'key space pressed?' and drag that inside the gap next to the 'not' text. Press on the 'space' button on the block that has a little downward arrow next to it. It will come up with some options to change the text from 'space' to another key. Check the images I provided above so you know what key goes with what block!

Step 4: The Star and Bomb

Now, like said in the introduction, the main player would need to collect the star and avoid the bomb. The star will give the player points (we'll work on points and scoring later) while the bomb would decrease points. First, go back to the sprite library and search up 'star' in the search box. Now we have our star sprite (remember to stay on the star sprite in the sprite section for the following code)! Look at the image of code above. In 'Events', find the 'when green flag clicked' block. Then go to 'Control' to find the 'forever' loop. And place a 'glide 1 secs to random position' from 'Motions' inside of that. This code means that the star will glide around the stage randomly!

Now we need a bomb! You'll soon find out that there isn't a bomb in the sprite library. So what now? Let's do some DIY digital art. On Scratch, you can also create your own sprites with the paint tool! Or you can just upload a sprite you want to use... But let's try the drawing option. Let's go back to square-one with the first step: assets. You must remember how to get a sprite! By hovering over the little cat symbol. But this time we will move our mouse up to the paint symbol and click on that instead.

TIP: Look at your code. You'll notice some blocks are orange or yellow while others are blue or green. These different colours relate to what type of block they are. So orange is connected to 'Control' and blue is related to 'Sensing'.

Step 5: The Paint Tool

The paint tool lets us create our own sprites. We've come across a problem - there is no bomb sprite in the sprite library so we will make our own one. Now that you've clicked on the paint tool symbol, we can start drawing. On the left side, there will be a vertical row of tools used for making shapes and selecting things. Press on the circle shape. Now just make a circle - not too big though! Press the mouse pointer tool at the top then click on the circle. Well, the purple circle. Bombs aren't purple so we can just adjust the colour to... black! Just press the fill button and use the sliders to change it to black. Change the 'brightness' to 0!

Press the brush tool on the side. It will look like a paint brush. Now draw an angled rectangle sticking out from the top of the bomb like in the example picture above! Now, still on that brush tool, we will change the fill colour to yellow by changing the 'Brightness' slider to 100 and 'Colour' slider to 16. Let's draw a rope sticking out from that rectangle. Actually, just check the example image!

TIP: To add that cool shading effect to the bomb, click on the circle in the bomb using the mouse-pointer tool and go to the fill button. At the top, you'll see some different gradient effects. Press the circle themed one! Make sure the inside colour is lighter than the outside colour. Then you'll get that awesome effect for your bomb!

Step 6: Adding a Score

Finally, we're just about done! After we add the score, your game will be good to go. We've come pretty far with this tutorial. You've learnt how to make a sprite move, how to recognise different types of code, how to use the paint tool, and you'll soon be able to add sound effects and make a score variable! Variables are like things that store information and they can change or vary when we code them to. Let's make one! Go to the dark orange coloured circle called 'Variables'. Now right-click on the 'my variable' and delete it. Press the 'Make a Variable' at the top! Name it 'Score'.

Select the bomb sprite. Let's add some code so that it will move around like the star. To do that, just add the exact same code as the star sprite! Just copy it! That's right. But we will add one single thing. On the stage, move the bomb to the very corner. Then drag a 'go to x: y:' block under the 'when green flag clicked' block. It will have some numbers already typed in there. This will prevent the bomb from spawning where the main player is right when the game starts because that just wouldn't be fair!


Step 7: The Final Pieces of Code

Now we are onto the last steps! These final pieces of code will make it so that when the main player touches either the bomb or the collectible star, it will play a sound effect and decrease or increase the score! Here's what you need to do. Drag a 'when green flag clicked' block into your coding area so we can start coding a new script. Then, in 'Motions', drag a 'go to x: y:' block underneath it. Change the 'x' to 0 and the 'y' to 0. The x: 0 and y: 0 position is the centre of the stage. So when the game starts, the main player will quickly teleport to the middle of your screen.

Go to the dark orange coloured circle called 'Variables' again to drag a 'set Score to 0' to the script. This will reset the score when the game starts. Drag in a 'forever' loop from 'Control'. And then put an 'if then' loop inside that. Yes, you can put loops inside loops! Go to 'Sensing' and put a 'touching mouse-pointer' into the empty gap next to the 'if' text on the loop. Press 'mouse-pointer' and change the text to 'Star'. Then inside the 'if then' loop, drag in a 'change Score by 1'. Remember to check the example images if you're stuck!

Look at the top left corner - there will be some buttons called 'Code', 'Costumes', and 'Sounds'. To get sound effects, we will go to 'Sounds'! Just click on that button. Near the bottom left corner, there will be a sound icon with a plus. Press that to access the amazing library of sounds! For the star, we will want a sort of 'collecting' sound effect. In the search bar, search up 'Wand' and click on the 'Wand' sound effect. Go back to the code and press the pink-purple coloured circle called 'Sound'. Drag a 'play sound Wand until done' block under the score variable block.

Step 8: Final Touches (Code Continued)

We've coded the star, but now we must do the same thing with the bomb. Right-click on the code you've recently done and select duplicate. Let's alter a few things. Firstly, we want to change the 'touching Star' text on the 'Sensing' block to 'touching Bomb'. Just click on it to change it. Next, instead of the score increasing by 1, we want it to decrease by 2. Click on the number '1' and type in '-2'. Finally, go back to the 'Sounds' section at the top. Go back to the sound library and search up 'Bonk'. This will be a great sound for when the main player touches the bomb and gets points taken off them. Go back to 'Code' and change the wand sound to the bonk! We've finished the code! Test out your game!

Now you have completed the game! Good job. Remember to check the example images provided to just double-check all your code. There are some extra things we can include in the game. For example, you could duplicate the bomb sprite to create a second bomb! You could even change the speed of the main player. Find the 'change x or y by 10 or -10' blocks and change the number '10' to something higher like '15'. Don't forget the minus! You can even add some code so that when the score reaches a certain number (like 10) then the background can change! Or some cool things like that. Make a copy by clicking 'File' then 'Save as a copy' so you can experiment and have fun!

TIP: Not sure on what sound you want to have? In the sound library, you can hover over the small pink-purple play button in the corner of sounds to hear them before you decide which one to use.