This object requires Java - Get Java

Fish! (version 2.0) is a simple game that can be built by a novice scratch programmer. The main character is a shark which is controlled by the mouse and wanders around the screen eating fish. Yellow fish taste nice but eating a red fish will give the shark indigestion. You can play the game on this page and also play and comment on the scratch website and view a video of how to make the game.

The basic principles behind of this type of game can be used to make many different games simply by changing the background and the graphics of the sprites. A game set in space with a rocket chasing astronauts and aliens would be simple to create using fish! as a base. Note that this second version of the game uses messages broadcast between the sprites to control behaviour.

We can build the game from scratch in simple stages:


  1. Create the shark sprite and control movement with the mouse.
  2. Create the yellow fish sprite with random movement.
  3. Add a variable to keep the score.
  4. Get the yellowfish sprite to broadcase a message if it is eaten by the shark.
  5. Add shark behaviour that receives a message when a yellowfish is eaten and animates the shark to look like it is feeding.
  6. Make the yellow fish disappear when it is eaten and then reappear a few seconds later.
  7. Duplicate the yellowfish sprite so that there are several fish in the game.
  8. Add a red fish and more broadcast and receive behaviour for the shark to get indigestion.

Please watch our video so you can see how we made this game or follow the instructions below. Download the completed Scratch project and change the costumes and background to make your own version of the game or take a look at fish online on the Scratch website.

Shark Costume

Select the default scratch cat sprite and change the costume to look like a shark by pressing the Import button on the Costumes tab. Select shark-a from the animals folder and then delete the other costumes by pressing the delete buttons. You should also rename the sprite to shark.


Mouse-following Shark

Creating sprite behaviour to follow the mouse is made easy by the point towards motion block available. Select the block and change the setting to show the mouse-pointer as shown below. A forever control loop is used to control the movement and the shark first points towards the mouse and then moves 5 steps. You can control the speed of the shark by changing this setting to speed up or slow down the action. You should attach the forever loop to the green flag so that the shark starts moving when the game starts. Notice also that the initial size of the shark is set here also.

Random Movement Sprite

The yellow fish sprites move randomly around the screen. Create the sprite by pressing the Choose new sprite from file button.

Choose the fish3 image from the animals folder and remember to name the sprite yellowfish.

Random movement is created by using a forever loop to make the fish move at a constant speed and the random block from the Numbers section to turn the sprite a little with each loop as shown below.

The game now has two sprites which move around the screen. The shark sprite follows the mouse and the yellowfish sprite moves randomly around the screen.

Create a variable to hold the score

We want to add to the score each time the shark eats a yellowfish so make a variable to show the score and make sure that it is made available to all sprites. Select the stage and add a green flag control block to set the score to zero each time the game starts.

Broadcast a message when the Shark eats the Yellowfish

Add an if control block to the forever loop for the Yellowfish to sense if the fish is touching the shark and is about to be eaten. Import and play a sound and hide the sprite so it disappears from the stage. Add one to the score variable each time a yellowfish is eaten. The shark behaviour is controlled by adding a broadcast message control block and creating a new message called sharktouchingyellowfish.

Control the shark eating Yellowfish behaviour

Import a second costume for the shark sprite using the shark-b image from the animals folder so that we can animate the shark to look as though it is eating. We can add a receive message control block on the shark sprite to change the costume three times so the mouth of the shark sprite moves. This will happen each time the shark touches a yellowfish and receives the message broadcast by the fish sprite.

Reset the Yellowfish after it has been eaten

The following block sequence hides the the yellowfish sprite which then reappers on one or either side of the stage after a few seconds. This behaviour waits up to five seconds and then places the sprite randomly on the left or the right of the screen by exploiting the fact the the coordinates of the screen vary from -240 to +240 on the x-axis and -190 to +190 on the y-axis. This behaviour occurs just after the sprite has been eaten.

The behaviour of the yellowfish sprite is now complete but we want to have more than one fish in the game. Rightclick on the yellowfish sprite and click the duplicate option to create as many copies of the sprite as you like (older versions of Scratch do not have this feature and you need to export and reimport the sprite and edit the touching shark block).

Create the Red Fish sprite

The game is nearly finished now but we need to create a bad-tasting red fish which resets the score to zero if eaten by the shark. Duplicate a yellowfish sprite and then import a different costume using the fish4 sprite image and delete the original costume and rename the sprite to redfish.

Change just one block on the redfish script to broadcast a message called sharkeatingredfish instead of the sharkeatingyellowfish message. You can now duplicate the redfish sprite if you want to have more in the game.

Control the Shark eating redfish behaviour

Import the shark-c costume from the animals folder into the shark sprite and add the following receive message control block to change the appearance of the shark and set the score to zero whenever a redfish is eaten.

Change the Background

The final step is to select the stage and import the underwater image from the nature folder as the background.

The game is now complete. It should be easy to change the background and sprite costumes to customise the game to whatever look and feel you want. Don't forget to view our video to see how to build this game from Scratch.

free tags: