Scratch Programming Basics Course Outline
Learning to code is not only about understanding the given programming language. It is also…
This is an epic bite size game where two cars, one green and one red, are having fun by throwing colored fire balls at each other.Start by opening a new Scratch project, and delete the cat sprite. Now add the ‘start’ backdrop from the Scratch library. This will give a nice space setting for this shooter game. Then go to the character library and add the ”cat2” sprite, with top-down view. Then click on the costumes tab, and use the ‘filling bucket’ to change its color to red. I am now going to make a program that will allow me to control the cat across the stage. Click on the Scripts tab, and add the first block from the Events category. It will run the script when the green flag is clicked. Then go to the Looks category, add the set size to 75% beneath it. Next add the ”forever” loop block. This block runs blocks inside it endlessly. Place the ”if-then” Controls block inside it. This block runs blocks inside its mouth, if the condition in its window is true. Now I have to set up conditions that will allow me to control the cat. In its window, add one ”key pressed” Sensing block. Duplicate this set of blocks to have 4 individual conditions, for each arrow key. For the first and the second condition, pick the left and right arrow key. Add the ”turn 10 degrees anti-clockwise” Motion block for the left arrow key, and add the ”turn 10 degrees clockwise” block for the right arrow key. Then add the ”move 5 steps” block for up arrow key, and ”move -5 steps” block for down arrow. Run the program, and test if the cat is listening to your controls. If you run into any problem, simply check the script thoroughly to find the error.
Now add the ”red fireball” picture I have provided in this article. Simply right-click on it and save it on your computer where you will easily find it. To add this sprite to the Scratch program, simply click on the ”upload sprite from computer” from the sprites area. It is time to make a program that make the cat spit fire, out of its mouth. Pick and drag the ”when green flag clicked” block to the scripts area. Then go to Data category and make a variable ”reload speed”. Drag the ”set reload speed to” block under the Event block, and set it to 0.75. Next add one ”forever” block, and inside it place one ”if-then” condition block. Go to Sensing category and add the ”key space pressed” block inside the condition window. Now, when I press the space key, I want this sprite to ”create clone” of its self. Add one ”create clone of myself” block. The drag the ”wait 1 secs” block, and inside it place the ”reload speed” variable. It will wait the amount of time we specified in the ”set reload speed to” block. Awesome, we are half way through the space shooter on Scratch.
Awesome, this script will create a fireball clone. Next, I will make it fly straight out of the cat’s mouth. Grab and drag the ‘when I start as a clone’ block. This block will execute blocks under it once the ”create clone of myself” block is executed. When it starts as a clone, I want it to be visible. Therefor, add the ”show” block from the Looks category. Otherwise it will appear to be invisible. Then go to Motion category and add the ”go to Cat” block. This block will make the fireball sprite stick to the cat sprite in this space shooter on Scratch. Then add the ”point in direction” block, and inside it place the ”direction of cat” Sensing block. This block will make the fireball point in the same direction as the cat sprite. Next we have to make it shoot out. To do so, add the ”repeat until” Control block. Inside the conditional window, add the ”touching edge” Sensing block. In this control’s block mouth, add one ”move 10 steps” block. Now, this part of the script will repeat the ”move 10 steps” block until the ”touching edge” condition becomes true. It will make the fireball fly straight away. And finally, add the ”delete this clone” block at the very end of this script. To make the fireball disappear once it hits the edge. Otherwise it will appear to be standing still near the edge.
Awesome! This is it for one player, to make this a multiplayer game, duplicate the cat’s sprite, and color it in green color. Its script will be duplicated too, but it has to be changed a little bit. Change its control keys to A,W,S and D, for left, up, right and down movement. Next upload the green fireball sprite. Then click on the red fireball and duplicate its scripts to the green fireball. Then go to the green fireball scripts area, and change the key for making its clones. Also, change its ”point in direction” to ”point in direction of cat2”. That is it. This is a very simple space shooter on Scratch.
Enjoy the game, and feel free to remix the game. I recommend taking my Scratch Programming course to learn how to program on Scratch. I offer a 25% discount on it. Click on the image on the right side. It includes thorough tutorials about the editor itself, its categories, and I provide examples with real game mechanics. And, on top of that, it offers 4 different game, art and animation projects. See you there!