Introduction: What Floats? in Scratch
This is for the Make it Float contest. While reading the contest instructions, I remembered something from when I was younger. I was always really curious to see what floats or not! So, I thought, "what if I create something that kids can ask what floats, and it would show them if it floats or not?" So, I created this game on Scratch. This Instructable will teach you how to make a simple and educational game in Scratch where the user chooses an object and the game will show if it floats or not. If it floats, it shows the object above water. If it doesn't, it shows the object underwater. It is really simple block code that anyone can do! Here is the link to the completed game on Scratch: https://scratch.mit.edu/projects/1260536860
Supplies
-A computer
-A Scratch account (free)
Step 1: Set Up the Background
This step is really simple. First, create the project on Scratch. Just click create on the top of the screen as shown in the first picture. Then, name your project. You can name it whatever you like. I named mine "What floats?". Now, add the first background. You can see how in the second picture above. You can choose any background that you would like, just not one that has to do with water. This is because we will use both above-water and underwater backgrounds later. I chose the "blue sky" background.
Step 2: Create the Text
Now it's time to create the text that says the objects that the user can choose from. First, click on the costumes tab on the top left of the screen as shown in the picture. Click on each part of the cat and delete it. Click on the "T" in the menu next to the build area. Click on the build area to create a text box. Type in a number and then a object. Do this about 8 times, clicking "enter" after each time to put each object on a new line. You can use the same objects as me (in the picture). You can move the text box around in the build area to move it on the game screen.
Step 3: Time to Code!
Now it is time to code! Go back to the "code" tab. From the events blocks, drag the "when (green flag) clicked" block onto the build area. Then, from the sensing blocks, drag the "ask () and wait" block onto the build area. Change "What's your name?" to "Choose an object's number to see if it floats". Then go to the control blocks and drag the "if ___ then" conditional block to the build area. Then go to the operator blocks and drag the "___ = 50" block to the gap between the if and then. Change 50 to 1. Go to the sensing blocks and drag the "answer" block into the ___ in the ___ = 50 (now 1) block. If these instructions are confusing, just look in the pictures.
Now, the harder part. First, add two more backdrops. Click the backdrops button again and add "City with water". Then, click the backdrops button again and add "Underwater". Go to the backdrops tab (as shown in the picture) and click on the underwater backdrop. Click the textbox button and click on the build area. Type in the textbox "It doesn't float!". You can move the textbox to the preferred spot. Then, repeat this for the city with water backdrop but write "It float's!" in the textbox instead.
Step 4: Continue the Code
Now you can finish the code! Go back to the code tab. Go to the looks blocks and drag the "Switch backdrop to ___" block into the if conditional. If the object floats, make it change the backdrop to city with water. If it doesn't, change the backdrop to underwater. Go to the events blocks and drag the "broadcast message1" block under the last block you added. Change message1 to "New message" and name the new message the name of your first object. Make a new sprite with the button next to the new backdrop button. Look for one that is the same as your first object. If you don't see one, make one by going back and hovering over the add a sprite button. Click paint.
Step 5: Code the Sprites
Click on your new sprite. Drag the "when I receive message1" block onto the build area. Change message1 to the message that you recently created. Go to the events blocks and drag the "when (green flag) clicked" block onto the build area. Go to the looks blocks and drag the "hide" block under the event "when (green flag) clicked". Drag the "show" block under the "when I receive (message)" block. Drag the sprite on the screen to where you want it to appear.
Step 6: Finish the Code
Now you can finish the code! Repeat steps 4 and 5 for each object you have left. I'll help you start the next one. Drag the if conditional under the other if conditional in the code for the backdrop. Then do step 4 again. Instead of writing one, write two. Make sure to choose the correct backdrop for if it floats or not. Make a different message for it to broadcast. (Name it the same as your current object). Then finish step 4 and do 5. Remember to repeat these for each object and change the variables in them appropriately.
Once you have coded everything, there actually is one more...
Go to the text sprite and add the "when (green flag) clicked" block to it. Connect the "show" block under that block. Then drag one "When I receive (message)" block for each object. Make each one have one of the messages you created. Connect the "hide" block to each of them. I have attached pictures of the completed code for the main program, a sprite, and the text.
Step 7: Try It Out!
Now you can run your game with the green flag button. Once you have played it a few times, try to add more features to your game!




