Use scratch to create a game.
Create a simulation of how a virus works.
Use a mixute of Reapeat blocks, IF statments, and Variables.
https://scratch.mit.edu/projects/editor/?tutorial=getStarted
--> If you already have a scratch account you can log in.
--> If you don't you can create an account, if your not sure how to do this, please ask your parents for help.
Remembering from class that cat or other charitures and objects we see or add to the screen are called a "Sprites".
We want to first of all delete the cat sprite, by clicking on the X Bin on the cat in the sprite libary.
Click on the Cat Face Icon within the sprite bank.
For this game, we are going to use Gobo.
Once you have found Gobo, click on him, to add him to your stage.
We are going to let Gobo move around the screen freely, so his movement is controlled by the computer.
We need to start with an event, that means when i start the game. This this is the When GreenFlag Clicked event block (yellow).
Next we want to make Gobo continue to follow the instructions all the time. This means we need to use the Forever block in side control (orange).
Finally we want Gobo to move, so we are going to use a motion block (blue). There should be a block, that will let Gobo move to a radom position on the screen. The block we want to use is called gluide (1) secs to random posion . We are going to place this block inside the forever block, like a sandwhich.
Now click on the Green Flag above the stage to test what we have coded so far. When you have finished testing this step, click on the Red Octogon to stop it,
For our game we want to be able to tell how Gobo is. We are going to do this by using 3 different colour's for Gobo.
Click on the Costumes Tab. We can now see that their are 3 Gobo costumes already setup in scrach. Gobo-a is going to stay Yellow.
Gobo-B we are going to turn Green. Click on Gobo-B in the side menu, so that the blue box goes around it.
Next click on the Fill box, and change to colour to a Green. Use the sliders to adjust the colour until you are happy.
In the painting menu, find the Paint Spill icon, and click on it so that it highlights the box blue.
You can now click on the Gobo and re-colour it green.
Now Click on Gobo-C.
Can you change this Gobo's colour to RED.
For our game to work we will need more than one Gobo.
Click back on the Code tab.
In your sprite libary, RIGHT CLICK on Gobo, and choose Duplicate from the menu that pop's up.
Now we have two Gobo's - Gobo and Gobo2. Lets rename Gobo2 to Virus. You can do this with in the sprite libary, where it says Sprite (Gobo2).
We want this Virus sprite to alway be RED. To do this we need to choose Looks (purple) blocks. Find the block that says switch costume to goba-b . You can see the little drop down arrow, this will let us change the costume to the different costumes, a, b or c. For this one we want gobo-c.
Add this block under the when GreenFlag clicked block.
We are going to now add some code so that when we click on Gobo, he will turn Green. This is to simulate Gobo, washing his hands, so that he can stay healthy.
Click on the Gobo sprite, so the blue box apears around him in the sprite libary.
We are going to write a second alogrothim for Gobo. We will need a new event (yellow) block, this time drag the block When this sprite clicked to your page.
Once we have clicked on Gobo, we want him to change his costume, so he looks green. To do this we need to choose Looks (purple) blocks. Find the block that says switch costume to goba-b . You can see the little drop down arrow, this will let us change the costume to the different costumes, a, b or c. For this one we want gobo-b.
We want Gobo to stay green for 5 seconds, before turning back to yellow. We need to put a wait command block in, so that Gobo knows this too. This is in Control (orange). You are looking of the wait (1) seconds block. Once you have dragged this to your alogrithum, change the 1 to a 5.
Next we want Gobo to turn back to yellow. Can you add the switch costume to goba-a under the wait (5) seconds block.
Lastly we want to make sure that this Gobo always starts off the game yellow. So we need to add another switch costume to goba-a but this time under the When GreenFlag Clicked event from the first alogrithum we wrote.
Now click on the Green Flag above the stage to test what we have coded so far. When you have finished testing this step, click on the Red Octogon to stop it.
We are now going to write some code tha we let the Virus turn Gobo red (to show he is ill) when he touched it. This will simulate how virus can spread in the real world.
Make sure you click on Gobo, and the blue box is around him in your sprite libary.
We're going to write a thrid alogrithum for this sprite! We are going to start with another When GreenFlag Clicked event block.
We are now going to add two different control blocks, the first is forever, the second block is the If < > then block. Remember from our work in class that IF is a conditional word. This block goes inside the forever block, like a sandwhich.
Next we need to choose our condition, go to Sensing (light blue), and look for the hexagon block that says color ( ) is touching ( ) ? and put this inside the hexagon shape hole on the If < > then block.
We need to set the colours to match that of your two sprites. Click on the first colour (useally blue), we are going to set this to match your yellow sprite. Click on the on blue and then click on the eye drop selector at the bottom of the color menu that just opened.
Then move the mouse over to Yellow Gobo, and click when it the square is over yellow. This will now turn the first colour to the same yellow colour.
Repeat the step you just learnt, to change the second colour in the sensing block to the Red you used for your virus sprite.
We can now put the chose inside the IF Statment block. So IF a YELLOW gobo touches a RED gobo then the YELLOW gobo will become infected and turn RED.
Can you add a switch costume to gobo-c inside the IF < > Then block.
Now click on the Green Flag above the stage to test what we have coded so far.
When you have finished testing this step, click on the Red Octogon to stop it.
Before we can make LOTS of Gobo's we need to change their size, other wise they are too big.
Make sure you click on Gobo, and the blue box is around him in your sprite libary.
Find where it says Size ( 100 ) . Change 100 to 50.
Now do the same for the Virus sprite.
You can now Duplicate the Gobo Sprite a 4 more times. (so you have 5 Gobo's)
Remember the objection of the simulation is to demonstate how viruses spread. The Gobo should not turn red, if you have clicked on it, and turned it green. This is simulating washing the Gobo's hands. But remembering that it needs to wash its hands oftern other wise, it can become infected.
Now click on the Green Flag above the stage to test what we have coded so far.
When you have finished testing this step, click on the Red Octogon to stop it.
If you want to duplicate more Gobo's now you can.
We are going to use some variable to track how many Gobo's become infected.
Delete all the extra Gobo's you created, so just leave the orginal Gobo and Virus sprites.
Go to Variables (dark oranage) and click on the MAKE A VARIABLE button.
Name the new variable Infected, make sure it is for all sprites, and then click on OK.
Add the change [Infected] by (1) block to your IF statment under switch costume to gobo-c
Now also add a set [Infected] to (0) block under the When GreenFlag Clicked block but above the Forever block.
Test the game - You should now see the Infected count go up to 1 when Gobo becomes red.
We are going to use some variable to track how many Gobo's become infected.
Write a new alogrithum to Clone Gobo. Use the the following blocks:
- when GreenFlag clicked
- repeat (10)
- create a clone of myself
We now need to code the clones. RIGHT CLICK on the first set of code we wrote, that makes Gobo move. Choose Duplicate, and move the alogrithum to a new part of the page.
You need to replace the when GreenFlag clicked event on the duplicated block of code with when I start as a clone event block. (You can break the code apart by clicking on the block under the one you want and draggind downwards).
Do the same to the Forever IF statment.
You will now have 11 Gobo's when the game begins. 10 Clones + 1 orginal Gobo.
Now click on the Green Flag above the stage to test what we have coded so far.
When you have finished testing this step, click on the Red Octogon to stop it.
We are going to use another variable to track how quickly the Gobo's become infected.
How long can you keep them healthy for?
Make a new variable and call it time, it is to be used for all sprites
Use the when GreenFlag clicked event to start to write a new alogrithum.
Add set Time to (0) block. It may still say Infected, but you can use the drop down arrow to change this to Time.
We are going to use a repeat until block. This will repeat the instruction inside untill the Infected number of Gobo's reaches 11 (as we have orginal Gobo + 10 Clones)
Inside the hexagon of the repeat until 11 block we need to add the equals to operator (green) block. ( ) = ( ) we are going to type 11 in the second circle.
In the first bracket we are going to add the Infected variable oval. You can find this in Variables (dark orange).
We can now code the time. Add the change time by (1) block inside the repeate until, like a sandwhich. You may need to use the drop down arrow to change it from Infected to Time like we did earlier.
Also add a wait (1) second block inside too, other wise the counter go very fast.
Test the game - How long can you keep the Gobo's healthy?
Can you add a back ground?
Can you make the Gobo's move Faster or Slower?
Can you increase the number of Gobo Clones?
If you have increase the number of Gobo Clones, what other number do you also now need to increase?
Can you modify your game any more?
Send me share link for your game - I would love to see it.
https://forms.gle/HUbbyNMnmcomLbcc8