Robot Shootout With Scratch!

by JTOO in Circuits > Software

398 Views, 1 Favorites, 0 Comments

Robot Shootout With Scratch!

scratch 2.png

I will show you how you can code your very own Robot game in this Instructable. You will learn how to use text-to-speech, messages, and more. You can change this project anyway you want too!

Supplies

Lenovo_77231EU_H405_Desktop_Computer_749608.jpg

All you need is a computer and Scratch (Don't have it? Just Follow the instructions below to get it!)

Getting Into Scratch and Start (Only If You Don't Have Scratch)

download.png

First, go to your web browser. Type in 'Scratch'. Find the result that says, 'Scratch - Imagine, Program, Share'. Click on it. It will bring you to the homepage. Create a Scratch Account, then click on the 'Create' option. After it loads, it will bring you to the coding screen, where code blocks are on the left. You should see a cat on the screen to the right. Delete it by going to the small cat picture below it and click the" trash" icon near it. Finally, scroll your mouse over to the cat icon with a little plus sign above it at the bottom right-hand side of your screen. When you do, a list of four options should show up; click on the magnifying glass icon. This will bring you to the sprite selection page.

Choosing Your Sprites

download (1).png
download (4).png

*Note: You can choose whatever sprites you want if you don't like my sprite ideas

Once you are in the sprite selection page, go to the search bar in the top left corner. First, search up 'robot'. Choose the robot sprite shown in the picture above. Next, duplicate it 3 times by right-clicking on the robot sprite and choosing the option 'duplicate'. You should now see 3 robot sprites. Next, go to the search bar again and find the cross sprite you see above. You finished all your sprites!

Give a Stage

download (2).png

Right now, our friends' world is looking a bit empty. Let's choose a backdrop! First, scroll over to the 'picture' icon next to the 'new sprite' icon. Another pop-up will appear, and you want to click on the 'search' icon. Search up 'nebula'. There should only be one option so click that. Once you click on your selection, it should bring you back to the code page and your sprites will now be in space!

Adding an Extension

Screenshot_20230224_055500.png
Screenshot_20230224_055611.png

Below all your code options, you should see a block icon at the very end like the one above. Click that and find the extension named 'Text to Speech' (also above). Click that. You can now make your sprites talk!

Shrinking Time!

Change the all the robots size to 70. Now that's super easy! (I hope)

Coding (AT LAST!)

Screenshot_20230224_060221.png
Screenshot 2023-02-24 180744.png
Screenshot_20230224_063805.png

Okay, what you've all been waiting to do! First, click the cross icon on the bottom of the right-hand corner. On the left-hand side of your screen, there will be a few vertical columns with different options. Click on the 'Events' option in yellow. Once there, you should see a few code blocks. Click the cross sprite and then drag and drop the 'When I receive message 1' block into the Code Area in the middle (on top, first block). Change it into a new message named 'start'.

After that go to the 'Looks' option and drag and drop the 'Hide' and 'Go to front layer' blocks. Change the 'front' to 'back'. Attach it to your event sprite as shown above.

Repeat it in all your sprites, but leave it as 'back' layer. Also, add a block from the "Motions' option named go to random position' It should look like the third picture.

You're done with the beginning of your code!

Make the Cross Follow You

Screenshot_20230224_061029.png

Go to the 'Motion' option and drag out 'go to x:___ y: ____' 2 times. attach the one to your code. Change x to 0 and y to 0. LEAVE THE OTHER ONE! Go back to the 'Events' option and drag and drop the 'Forever' block and attach it to your code. Put the other motion block inside the 'Forever' block. Go to sensing and drag out the 'Mouse X' and 'Mouse Y' blocks and put them over the second 'go to x:___ y: ____' block. I put 'Mouse Y - 10' because it doesn't work properly for my mouse. You can do the same.

Make a Variable

Screenshot_20230224_062452.png

Go to the 'Variables' option and rename the 'my variable' into 'kills' or anything you like. You just made a variable!

Time for the Main Code

Screenshot_20230224_064349.png

First, create 3 messages, named 'shoot 1' to 'shoot 3' Then, click one of the robots and add a 'hide' , 'wait 1 seconds' ,'show', 'go to front layer', and 'go to random position. Change 1 seconds into 2 seconds and 'front' to 'back'. It should look like the code above. Repeat for all other robots, just change the 'shoot 1' to 'shoot 2' or 'shoot 3'.

Almost Done......

Screenshot_20230224_070526.png

You should be getting the hang of it, so why not try this code on your own? By the way, You need to search up the sound library for the sound 'pew'. Let's see if you have been paying attention in class. ;)

Not Yet Done, Sorry!

Screenshot_20230224_070711.png

Make the code above and duplicate it into every sprite.

Narrator Time!

Screenshot_20230224_071252.png

Drag a 'When flag clicked' block and a 'set backdrop to backdrop 1' block. Change 'backdrop 1' to 'Nebula' or whatever backdrop you chose. If you did step 4, you should be able to get the dark green blocks that you see. Drag in some of them and experiment with the blocks that you see there to get the perfect combination or just copy mine. Remember to add a 'broadcast start' block at the end of the code!

Done?

Screenshot_20230224_070900.png

Click on the backdrop icon. Make the code above. You can change the number of kills you must score to any number you like.

Done at Last!

clap.jpeg

Congrats! You have finally made this super-long project. (Even I did not expect the project to be so long!) I am so proud of you all! If you want to view my project, you can go to:

https://scratch.mit.edu/projects/809039903

(Sorry, there are 5 robots instead of 3 and I made a modified 'X' as well as add some extra code, but it's still actually the same!)