This is done as a multiple step process and will be done over several classes. A five lesson plan is shown below. Each student will create their own version of this game with their own character and background, and their own rules for movement/food/enemy. There are enough variations to keep the game interesting and different from any other game in the class.
1. Choose a background and character.
Click on stage and Backgrounds tab and either import one of the Scratch backgrounds provided or paint your own. In this example the default Underwater background is used.
Delete the cat (use scissors) on the top and either create your own character or import one of the Scratch characters or import a character designed elsewhere (e.g. cute character designed as part of Inkscape lesson).
Once a character has been imported, it can be further modified. Even default Scratch characters can be customized. E.g. this lesson uses a standard Scratch fish with the color changed.
2. Move the character with arrow keys. Add the following script to move character each time the keys are pressed. The important new block is the ‘Point’ block. Click on the ‘Always face left/right’ or Do not rotate if the character should not flip around when moving.
1. Add a new sprite (the food) for the character to catch/eat.
In this example a small yellow circle (a simple gold coin) is created and named ‘food’.
Set position of character and food, have food disappear when eaten, have character indicate it ate the food.
2. Set position of food using the xy cordinates. Have it disappear or be eaten when touched by the character.
The following script shows how to set the coordinates of the food and have it disappear when the character (yellowfish) touches it. It uses the Hide/Show in the Looks blocks.
It also broadcasts a message ‘eaten’ that the fish will use to change or say something when it eats food.
Script for the food is as follows
Script to add to the yellow fish along with the arrow keys movement scripts is
In this lesson, expand on the above by explaining the use of random numbers, and the use of broadcast.
Each time the game is played (the green flag is clicked) the food is always in the same place. Instead of picking the x,y coordinates, let the computer pick it randomly, by using random numbers.
See updated script for food. In this it also hides and reappears after waiting second at a different place.
Use the broadcast message (food is eaten) to change the fish, example below shows fish getting bigger, and changing color.In this case it is necessary to reset the fish to original. See below on changing fish on broadcast and resetting on green flag.
Use scripts similar to that of food to create an enemy, example the shark. After the shark waits and touches the fish, it can broadcast a message to tell that the game is over. The Game Over sprite can then listen for this message and show itself and stop the game. In this example, the Shark also moves slowly around forever in the tank, starting by pointing at a random angle and then bouncing off the edges.
Create a sprite called GameOver and set it to stop the game when the Shark touches the fish, and the broadcast message is received. In this example, the Game is also over if time runs out using the wait as a timer.
If there is a definite way to win the game, example catching all the food (in this example the count of food is 4), then another sprite called YouWin can be used as follows.
In order to count the food caught, create a variable called count and use it as follows in the YouWin sprite.