Algorithms in Action #1: Code your own Cookie Clicker
- Aug 15, 2025
- 5 min read

Video games have a way of leaving their mark on us. From the pixelated playgrounds of Minecraft to the fast-paced chaos of Papa’s Pizzeria, each one offered an endless world that was also endlessly addictive. But for me, no game was more dangerously captivating than Cookie Clicker. Just one giant cookie in the center of the screen, surrounded by a sea of eager mouse clicks, and I was hooked. The hypnotic rhythm of tap after tap became its own kind of music to my ears.
The beauty of learning computer science is realizing you can make worlds like that yourself: digital landscapes that capture someone else’s imagination in the same way. That’s why CARE emphasizes computer science education through our free programs for young students. When I set out to make my own take on the cookie craze, I didn’t just want to copy what worked. I wanted to add my own flavors, surprises, and maybe even a few twists to the classic.
In this first Algorithms in Action, we’ll be covering one of our Scratch Game Design workshops: the Cookie Clicker. Cookies of all different colors and flavors will rain from the sky, in which the player will need to click them before they touch the bottom of the screen. It’s a beginner-friendly introduction to some basic concepts like loops and if-statements, so let’s get started!
First, go to the Scratch website and make a new project. If you don’t have an account, your progress won’t save so be sure to create one if you don’t have one already! It only takes a few minutes, so we highly recommend starting your own account to keep all of your work. When you have time, consider adding a profile picture and biography to customize your account as well!
Next, click on the “Create” option at the top of the homepage. This will launch your first project, which comes with a default cat sprite in the middle. If you haven’t used Scratch before, you may want to proceed through the tutorial first. You can also learn through the diagram on the right.

The basic steps you need to know are that the stage is where your sprites (or characters) move, which you control through the programming blocks on the side. You can run your code by clicking the green flag at the top bar, and end it by hitting the red sign to the right. The backdrop option on the right controls what the stage looks like. Go ahead and remove the cat by clicking on the trash can on the top right of the sprite’s square at the bottom.
Now, we will create our sprites. In my version, I will be using cookies as the main object but you can choose whatever object you would like. Pick a pizza sprite, or a unicorn! The possibilities are endless. Add a sprite to the game by clicking the cat inside the circle on the bottom right, and select the import, random, paintbrush, or gallery options from the menu.

Once we have our sprite, we need to tell it to create duplicates of itself by creating clones. We are going to use the yellow start command “when green flag clicked” to prompt the cookie sprite to start duplicating when the game starts. The first cookie - think of it as the “original” - will hide itself and immediately start cloning itself forever through a forever loop. Notice that you can’t add anything to the bottom of the forever loop, we need to add another initiator block to give more directions to the sprite.

Now that we have plenty of clones, we will code the actions for these duplicates. Using the yellow initiator block “when I start as a clone”, the new sprite will show itself (remember we hid the original before), and start in a random location by using the blue “go to random x and y” move block. Find the green “pick random” block and drop it into the circle with the values -180 to 180. We are keeping the y value constant at 181 so it will start at the top of the screen.

Finally, we need to command the clones to disappear when touched or end the game if they fall to the floor. We need to use the forever loop to ensure the sprite is always checking if it is touching the mouse or floor. The blue move block “change y by -2” tells the sprite to continuously fall to the bottom. Underneath, we have two yellow “if statements”. Make sure they are not in each other, it is crucial that these are separate.

Before we start coding the if loops, we need to create a variable called “Points”. This will track how many sprites have been clicked so far in the game. Click “Make a Variable”, then name it “Points”. Ensure that the left checkbox is clicked so the variable is active, or else it will not affect the game. Additionally, make sure to add a “set Points to 0” underneath the previous “when green flag clicked” to rest the counter for each new game.
For the first loop, this will be the action that the sprites take if they are touched by the mouse clicker. Drag a blue touching statement to the hexagon-shaped box and toggle “touching mouse pointer” in the drop-down. Then, assuming the sprite has been touched, we will “change points by +1” and play a sound effect by “start sound pop”. After it has reacted to the touch, delete this clone to prompt it to disappear.
Next, for the second loop, add a green “ ___ < ___ “ inequality statement to the if loop box. Add a blue “y position” variable to the left and “-175” to the right (the y value for the bottom of the screen). Inside, we will use the yellow “broadcast message” to signal that the player has lost the game. To make a special broadcast, click the drop down and hit “New message” to create “Lose Game”. Underneath, use the delete clone block to end the loop.
Finally, in the same sprite, drag a “when I receive” initiator block out and toggle the message to “Lose Game”. Then, for special effect, play the sound “Lose” and then “stop all” to finish the game. Congratulations! You have finished your first Cookie Clicker game.

If you would like to keep on improving this project, such as by adding a home page or background music, check out the completed project here. You can also attend one of our in-person programs to learn more or register for an online course taught by us! There, you’ll be able to delve much deeper and get real-time feedback from our talented teachers.
By continuously creating and iterating on our game, these small steps slowly build into something much bigger. Each block of code adds to the last, turning an idea into a real project. These initial programs can lead to something much bigger if you continue to develop your skills in computer science and take it to the next level with advanced programs like Python and Java. Coding isn’t just about creating fun games, it’s about learning to bring ideas to life from our boundless imagination.





Comments