Posted on

Scratch Coding – Penguin Feeder

The goal of this game is to keep the Penguin eating the fish. Too many fish will make him sick and not enough fish will see him go hungry.

Sprites

These are the two sprites I picked; a hungry penguin pal, and some yummy fish. Feel free to be creative when choosing your sprites!

The Penguin’s Name

We really need to name our Penguin, we will first ask the player to give our penguin a nice name.

We are going to select the tick box on the answer variable. If we double click on the variable in our main scene (the left view), we can make the variable look like a label.

Ask the player for a penguin name:

Setting the Hunger Level

We want to make our penguin tell us when he is hungry, we will need to use a variable to store how many fish he has eaten.

If the penguin has a hunger level of…

  • 10 or more: he is very full
  • 5 is the perfect amount
  • 0 is very hungry

Create a variable called hunger and set it to start at 5.

Fish Spawner

On our fish sprite, lets add some code to spawn new fish as clones:

When the sprite starts as a clone:

Our Penguin’s Health

On our penguin sprite, we are going to build a check to see if the penguins health changes. We are going to use a forever loop with some if statements that check the value of the health variable.