Scratch: Gerry the Giraffe (1)

The Scratch Giraffe game – loosely based on Trick the Turtle, a Greenfoot tutorial by Michael Kölling.  My original idea had been to re-engineer Trick the Turtle, but in an effort to make it as easy as possible for my students, I used sprites that are pre-installed in Scratch.  The basic functionality of Trick (a keyboard-controlled animal, that eats something, and the avoids a predator) is retained.  Maybe, by the end, we’ll import the Trick images.  I don’t know yet.

Anyway, the objectives are to get students to think beyond worksheets; to learn keyboard control; to reflect on the effectiveness of solutions; to introduce object interaction; to use variables.  At this stage, they have used a pile of worksheets, with another teacher who was looking after my classes for a while.  I want to bring in a bit of “ooooooh!”

My intro: Show them the finished game (you can download it, here), tell them this is where they have to get to. Show the code for each sprite and (briefly) discuss it.


We have a giraffe – with keyboard control.  Notice that once it starts running, it keeps going.  The bowls of fruit jump around, and respawn once eaten.  The lions come towards the giraffe, and are there to be avoided.


Making the giraffe

First, a new Scratch project is needed, with a giraffe instead of a cat. So, create the project and delete the cat.  Create a new sprite. Use giraffe1-a. Yes, it does have to be this image (because I say so).  The real reason is because there is a giraffe1-b that we can use later to animate the running giraffe, if we decide we want that.



Simple keyboard control

So far, the class have used the green flag or space-bar, to start a program that either runs to completion, or that does a pile of stuff forever. To start, the giraffe will be given four programs. Bring four When Space Key pressed instructions over to the giraffe’s script.




Demonstrate making the first instruction into when up arrow pressed, move 10 steps.


Now, ask the students to change the remaining when-space key pressed to give you a giraffe that:

  • goes 10 forward (up arrow)
  • goes 10 backward (left arrow)
  • turns right (right arrow)
  • turns left (left arrow)


I give them a few minutes, have a walk round and discuss a few solutions. Most will have the solution below.  Some will have different amounts of turning, and other variations. That’s ok – the turn-amount (etc) were not specified in the ‘challenge’.  The important thing is forward/backward and turning left/right.



“But Sir, it doesn’t keep moving….”

The original giraffe kept moving, once you pressed the arrow key. It did not rely on the user pressing arrow keys over and over.

Ask the class to modify their solution to keep going backwards, and keep going backwards. Probably nobody will get a perfect solution -that’s ok. This is a thinking and learning and discussing exercise.

Give them time, and then talk through the various options, below.


Most will manage this modification – keep going forward by repeating forever:


It fails when the giraffe runs off the screen.


“Why does it run off the screen, folks?”  – an interesting discussion should follow.


Some manage this.  It’s a good effort.  It’s important to congratulate them for having a go, even if it isn’t perfect yet.  We’re still learning, and when we make mistakes we are simply finding out what doesn’t work.

Press forward and watch it go….

Press backwards, and watch it stop!



Q: “Why does it go forward, and then simply stop when you press back?”

Ans: it has been told to forever go forward and forever go backwards. This produces a continual back-forward effect. It looks a bit like a failed moonwalk.


Some clever ones managed a repeat 10 times variation. This is good, and it shows they are thinking and trying to fix the problem, but is still a compromise.  Remember, the original giraffe in the original game kept moving forever and would reverse (forever) also.  I demo the repeat-10-times version and and let them discuss it.

Actually, after getting to this point with a few different classes, I was fairly pleased with their willingness to have a bash at it.  Some classes had built reasonably good animations and games, with worksheets, in my absence.  Others had not touched Scratch at all.  With all classes, I was pleased with the half-a-go attempts and their willingness to talk about what does/does not work.


Anyway, how do we get it working like the original giraffe?

First, clear the scripts we have just made. Yes, everything. Wait for the grumbles. It’s OK, we haven’t failed so far, we haven’t got it wrong – we have just found one thing that isn’t going to work the way we want. This is precisely how I went with it when I hacked the original solution together inside a couple of hours.

(Yes, I did hack it, no hacking it not always bad and evil – let them think about that and if you want and if you have time, you can discuss the real meaning of hacking with the more common meaning given nowadays)


Back to the giraffe: create a variable, Speed. For this sprite only.


It will start at zero. That’s ok.

Now we start building the script. First, we reset the position (in case it has ran off-screen) and reset the speed.


It won’t do anything exciting yet.

Now we tell it to forever, move, at ‘speed’. Move the giraffe to the edge and press space. Once the giraffe is centered, nothing happens – “Why is it just sitting there, folks?”


Answer: it is moving, at speed zero….


Now, we add some keyboard control. Add two ‘ifs’.



We discuss what an IF is and what it does.

Q: “IF up arrow is pressed do we want to happen? What about when DOWN is pressed?”


Then I show them the IF construct for UP:


‘When space key pressed’ comes from the ‘sensing’ block – we change to ‘up arrow’ pressed.


I let the class figure out backwards movement for themselves.


There’ll be lots of oohs and aahs at this point.

This is the finished product (for now).



Now we save our work, as the bell’s about to ring.  My version of the end-of-lesson game is here.

Next day – speed limits, turning, something for the giraffe to eat.




Leave a Reply

Your email address will not be published. Required fields are marked *