Halloween is just around the corner and the candy hunt is on! Instead of going door to door, let’s use code to get our candy fix.

Complete this easy Scratch coding tutorial to build your own trick-or-treat candy collector game.

What is Scratch? Scratch is a 100% free block-based programming language that lets you drag and drop code blocks to build fun games and apps. Scratch is a preferred introductory programming platform for younger students and it teaches powerful programming concepts like variables, loops, and conditionals.  

📌 [Download] Printable Scratch Coding Tutorials Get 2 printable Scratch tutorials, Rocket Landing and Flying Space Cat, to code your own games step by step. Download Now

Code this easy Scratch game then compete with your friends and family for the most candy this Halloween. 

Play Halloween Candy Collector 

What you need:

  1. Scratch account: Create a free Scratch account 
  1. Starter files: Download the images we are using in our game. You can also use your own images to customize your application. Download starter files

No coding experience is necessary for this tutorial. Beginner-friendly for ages 8 and up. Give it a try!

Scratch Coding: Halloween Video Tutorial

Step 1: Create a new Scratch project

Let’s start by creating a new project. 

Visit https://scratch.mit.edu/, login to your account, and click on the “Create” button.

Scratch tutorial step 1

Now, we can code your game! 

Hint: You can also remix this project and others to see the code.

Step 2: Upload background and character images

A new project will open up and you can see the Scratch interface.

In the starter files, we’ve included images for your player, the candy, game over screen, and 5 different spooky settings. 

Scratch tutorial step 2

Hint: You can use any of your own images as sprites to customize your game, select images from Scratch, or even draw your own.

Step 3: Change the size of your characters

In Scratch, your character images are called sprites. Click on each sprite, then change the “Size” property.

You can also click on your “gameover” image in the preview area and drag to move the image around.

Scratch tutorial step 3

Hint: Make the candy bigger for an easier game or make it really small for a harder game. 

Step 4: Hide the “gameover” sprite

We don’t want our game to be over before we start, so let’s hide our “gameover” sprite. 

In the Scratch interface, you can see the code blocks on the left under the “Code” tab. They are arranged in categories by color. Simply click and drag the block you want into the blank code area. 

Scratch tutorial step 4.1
Scratch tutorial step 4.2

Hint: The “When Green Flag Clicked” block helps us start our program. Just click the green flag near the preview screen to run your code.

Step 5: Get your ghost moving

Next, we want our ghost follow our mouse cursor to get it moving. 

We can use a “Forever” block, which acts like a loop to repeat code. Paired with the “Go to mouse pointer” block means the ghost will forever go to the location of the mouse.

Click on your “boo” sprite to add code to it. 

Scratch tutorial step 5.1
Scratch tutorial step 5.2

Hint: You can also code your ghost to move when you press up, down, left, and right using motion blocks. Check out bonus step #10 in our KidWizardsHQ group to learn how.

Step 6: Make your candy appear in random spots

Our candy shouldn’t stay in one spot, that’s too easy. Let’s make the candy appear in a random spot each time our ghost touches it. 

Click on your “candy” sprite to add this code to it.