Escape the Robot Scratch Game

Welcome to this step-by-step animated tutorial for creating Escape the Robot, a cat and mouse scratch game. For a handy guide on some of the main scratch blocks used  in the game click here!  In Escape the Robot, you control Scratch the cat trying to collect as many doughnuts as possible whilst trying to avoid being caught by the robot. Here is the game in action!

To play and the view the code for the game within the online version of scratch click here. Alternatively, to download a copy of the full code for the game as an .sb2 file click download now below!

Part 1: Game Design

Before we start to make a game we should first plan and design it. As well as sketching out what you envisage your game will look like, three good questions to try and answer are (i) What is the aim of the game, how can I win and/or lose the game, (ii) What variables will I need, and (iii) what sprites and costumes will I need. Here is a sketched out game design along with considerations of such questions for the Escape the Robot:

Part 2: The Player Sprite

First, we need to decide (or design) what the player will look like. In escape the robot Scratch the cat is the player, but of course you could choose or design your own player. Next we should change the sprite’s name to “player” and then start adding blocks to its script, starting with a . After this we want to set the default location of the player to the bottom right of the screen with

and also ensure the player stays upright with Next, we need to add blocks to control the player through the arrow keys. We will need a Forever block and inside it, 4 If blocks one for each direction (up, down, left & right) which we will use to determine how the player moves when an arrow key is pressed, through either a change x block, for moving left and right, and a change y block, for moving up or down. For example, to move left with  Additionally, when moving left and right to make the player face the correct direction we also add point in direction blocks (to point left would be ). Finally, to stop the player from ever moving off the screen, we add inside the loop  So together all the code for the player sprite, and what it looks like in action, is:

Part 3: The Enemy Sprite

Next, we need to decide (or design) what the enemy will look like. The robot is the enemy here but, you could choose or design your own enemy. We should change the sprite’s name to “enemy”, add a  to its script, and then to set the default start location add . In the game the enemy will slowly speed up; to achieve this we need to create a variable, called Speed, and then set a starting speed . We do not want this variable to be displayed so right click on its name in the game screen and select hide. Next, to make the enemy always move towards the player we need a forever block and inside it add  and then to move the speed variable amount add To determine if the enemy is touching the player we add a touching block in an if block, which if it is then its game over so stop all. To slowly speed up the enemy we change the speed variable with , try experimenting with this number and its affects upon the games difficulty! So together all the code for the enemy sprite, and what it looks like in action, is:


Part 4: Making Items to Collect

The final sprite we need is an item to collect, here scratch is collecting doughnuts but you could choose or design your own items! We should name the sprite Item and add a  to its script. To keep track of how many doughnuts the player collects we need to create a variable called score which, at the start of the game, we want to set to 0 with . Then, to position the item at a random location on the screen we pick random x and y values within a to go block like this . Next, to determine each time the player collects (touches) the item we add a Forever block and then within it add a touching player block inside an if block like this:  

If the item is touching the player, then we want to add a point to the score variable,   , and then move the item to a new random location exactly like before. Finally, to change the item’s appearance each time it is collected we can setup multiple costumes, as various different doughnut colours, and the cycle through the costumes with  each time the item is collected (see if you can use the same idea to make it looks like the player is running as they move!) So together all the code for the item sprite looks like this:

Part 5: Gameplay extensions and ideas

Now we have all the sprites and blocks for the basic Escape the Robot game 🙂 However this is only the beginning, and there is so much more that could be done to extend the game. For example, giving the player a number of lives which decreases each time they are caught. What other extensions can you think of? What about some of the ideas below for inspiration, how might some of these be realized with scratch blocks?

Any suggestions or questions get in touch, and check back again for more tutorials, and games coming soon. Happy Scratching 🙂

If you liked this article please consider donating to help support future content.

Leave a Reply

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