1) Now we have one person moving randomly, we just need to add some more. What we need to do is set up the program to clone our sprite.
To do this, we need to split the code into some that runs when the
program starts, which will generate clones, and some that starts when a clone is born, which
will do all the movement etc. Start by pulling the code you've written off the
When [flag] clicked
startup block. Add in a When I start as a clone
block at the top
instead.
Now we need to write the code that will generate the codes. Add the following:
Try running it, and then removing the show
and hide
statements. What happens? Why do you think this is? (answer at the bottom of the page).
2) Now one of our sprites needs to be infected. First we need a new costume for our infected zombies. Click on its "costumes" tab and then right-click the current costume, and choose Duplicate:
Rename the new duplicate "infected" and use the colour palette and "tipping paint bucket" tool to fill the green circle with red paint. If you are colour blind and using different shapes, please still use a different shade from the healthy colour as we're going to use the fact that they are different colours shortly.
Go back to the "scripts" tab.
3) Now we have two costumes, we need to make sure one sprite starts with the "infected" costume. To do this, we need a counter variable that all the sprites can see. If we increase this each time we make a clone, we can tell the first one to change costume.
In the Data block set, make a new variable counter
that can be used by "all sprites".
Then change the code to the following:
Go on to Making the people bitey.
PS. The hide
block, mentioned above, is used to hide the sprite that is the parent of all the clones. As
the sprite isn't a clone, it doesn't use the code we added to the When I start as a clone
block. This means it doesn't move. There are other solutions. One, for example, is copying the movement code into the When [flag] clicked
area of the sprite, which doesn't run for the clones, but this means twice as much code to keep track of. Better to just get rid of the parent sprite.
The show
statement just makes the original sprite reappear before it is cloned if the code is run again -- without this the sprite stays invisible and the clones are
therefore hidden as well. Note that variables etc. aren't reset when you run the code twice, so you need to set variables etc. to zero at the start of any code.