Make a Virtual Pet Game in Scratch for Kids
![]() |
| KidsKod original illustration. |
Have you ever wanted a pet that lives inside your computer? Today you will build one! In this KidsKod project, you will make a Virtual Pet game in Scratch where your pet gets hungry, sleepy, and bored, and it is your job to keep it happy. If you are brand new to Scratch, start with our friendly guide What Is Scratch? A Fun Guide for Kids, then come right back.
What you need
- A computer or tablet with a web browser
- Free Scratch at scratch.mit.edu (a free account lets you save your work)
- About 30–45 minutes
- A grown-up nearby if you are making an account for the first time
What you will learn
- How to use variables to keep track of Hunger, Energy, and Fun
- How
foreverloops make things change over time - How
if ... thenblocks help your pet react - How to use buttons and broadcasts to feed, play, and rest
- How to make costumes change to show your pet's mood
Step 1: Pick your pet and backdrop
- Open Scratch and click Create.
- Delete the cat (or keep it if you like cats!).
- Click Choose a Sprite and pick an animal such as a dog, dinosaur, or monster. Name it
Pet. - Choose a cozy backdrop, like Bedroom or Room.
Step 2: Make three variables
- Go to the orange Variables section and click Make a Variable.
- Make
Hunger,Energy, andFun(choose For all sprites). - Tick the boxes so they show on the Stage. Right-click each one and pick slider or large readout if you want them easy to see.
Step 3: Start the game
Click the Pet sprite and add this script:
when green flag clickedset Hunger to 100set Energy to 100set Fun to 100go to x: 0 y: -40
Now your pet starts every game feeling great.
Step 4: Make your pet need you
Real pets get hungry and tired over time. Add a second script to the Pet:
when green flag clickedforeverwait 2 secondschange Hunger by -3change Energy by -2change Fun by -4
Click the green flag and watch the numbers slowly go down. That is a loop doing its job!
Step 5: Add Feed, Play, and Sleep buttons
- Add three new sprites as buttons. The Button2 sprite works well, or draw your own. Use the costume editor to write Feed, Play, and Sleep on them.
- On the Feed button add:
when this sprite clicked→broadcast feed. - Do the same for Play (
broadcast play) and Sleep (broadcast sleep). - Back on the Pet, add:
when I receive feed→change Hunger by 20→say Yum! for 1 secondswhen I receive play→change Fun by 20→change Energy by -5→repeat 4(turn 15 degrees,turn -15 degrees)when I receive sleep→change Energy by 30→say Zzz... for 2 seconds
Step 6: Keep numbers between 0 and 100
Without limits, your pet could have 500 food points! Add this to the Pet's forever loop (or a new one):
if Hunger > 100 then→set Hunger to 100if Hunger < 0 then→set Hunger to 0
Copy the same two blocks for Energy and Fun.
Step 7: Show your pet's mood
- Open the Pet's Costumes tab. Duplicate the costume and draw a sad face or tears on the copy. Name the costumes
happyandsad. - Add to the Pet:
when green flag clicked→foreverif Hunger < 30 or Fun < 30 then→switch costume to sadelse→switch costume to happy
Now your pet looks sad when it needs help. Kids who test this always rush to the Feed button!
Step 8: Add a game-over (optional)
if Hunger = 0 and Fun = 0 then→say I ran away to find snacks! for 2 seconds→stop all
Keep it gentle and funny so the game stays friendly for younger players.
Step 9: Test and share
- Click the green flag and look after your pet for two minutes.
- Is it too easy? Make the numbers drop faster. Too hard? Make them drop slower.
- Give your project a fun name, like My Pocket Dino, and click Share (ask a grown-up first).
Wrap-up and challenge
Great job! You built a real game that uses variables, loops, conditions, and broadcasts, the same ideas programmers use in big apps and games. Ready for more?
- Challenge 1: Add a
Scorevariable that goes up by 1 every 5 seconds your pet stays happy. - Challenge 2: Add a Bath button and a new
Cleanvariable. - Challenge 3: Make day and night by switching backdrops every 30 seconds.
Want another Scratch game next? Try our Catch the Stars game. Happy coding from KidsKod!
