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 forever loops make things change over time
  • How if ... then blocks 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

  1. Open Scratch and click Create.
  2. Delete the cat (or keep it if you like cats!).
  3. Click Choose a Sprite and pick an animal such as a dog, dinosaur, or monster. Name it Pet.
  4. Choose a cozy backdrop, like Bedroom or Room.

Step 2: Make three variables

  1. Go to the orange Variables section and click Make a Variable.
  2. Make Hunger, Energy, and Fun (choose For all sprites).
  3. 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 clicked
  • set Hunger to 100
  • set Energy to 100
  • set Fun to 100
  • go 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 clicked
  • forever
    • wait 2 seconds
    • change Hunger by -3
    • change Energy by -2
    • change 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

  1. 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.
  2. On the Feed button add: when this sprite clicked → broadcast feed.
  3. Do the same for Play (broadcast play) and Sleep (broadcast sleep).
  4. Back on the Pet, add:
    • when I receive feed → change Hunger by 20 → say Yum! for 1 seconds
    • when 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 100
  • if Hunger < 0 then → set Hunger to 0

Copy the same two blocks for Energy and Fun.

Step 7: Show your pet's mood

  1. Open the Pet's Costumes tab. Duplicate the costume and draw a sad face or tears on the copy. Name the costumes happy and sad.
  2. Add to the Pet:
    • when green flag clicked → forever
    • if Hunger < 30 or Fun < 30 then → switch costume to sad
    • else → 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

  1. Click the green flag and look after your pet for two minutes.
  2. Is it too easy? Make the numbers drop faster. Too hard? Make them drop slower.
  3. 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 Score variable that goes up by 1 every 5 seconds your pet stays happy.
  • Challenge 2: Add a Bath button and a new Clean variable.
  • 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!

Next Post Previous Post
No Comment
Add Comment
comment url