How to Make a Flyswatter game using Scratch(TM)

Scratch is a simple coding website that shows the code using blocks like “move forward 10 steps” instead of real code language. Today I will show you how to make a simple flyswatter game using Scratch.

Step 1: The Flyswatter
For your flyswatter game, you might want a flyswatter instead of your mouse. Because there aren’t any flyswatter sprites* in the Scratch sprite library, you will have to draw your own or download an image from the Internet. To make the flyswatter follow your mouse, you can put a “go to mouse-pointer” block in a “forever” block inside a “when green flag clicked**” block. This will cause the flyswatter to infinitely follow your mouse when you run your code.
*That’s the word they use for the characters that you add on the screen, not the soda drink.
**How you run your code in Scratch.

Step 2: The Flies
Now that you have a flyswatter, you will need some flies. I suggest you fully code one fly and then use the “duplicate” tool to make more copies. I found two good tactics that you can make the fly look like it’s randomly flying around.

The first tactic is to put a “move forward 10 steps” block and an “if on edge, bounce” block in a “forever” block. This will cause the fly to infinitely fly forward on the screen while bouncing back every time it hits the side of the screen. It is also important that you put a “set rotation style left-right block before the “forever” block, or else the fly will turn upside down every time it hits a wall. Increase the steps in the ”move forward 10 steps” if you want to make the fly go faster. Don’t forget to put all the codes in a “when green flag clicked” block!

The other tactic to make the fly look like it’s randomly flying around is a bit more complicated. You have to place a “glide 1 secs to y:(blank)x:(blank)” block in the “forever” block. Then, take two “pick random 1~10”blocks and change the first “1~10” block to -240~240. You then change the other block to -180~180. All this is because the Scratch screen’s x-axis is from -240 to 240 and the y-axis is -180 to 180. Now, the fly should fly around randomly. If you want the fly to move faster, decrease the amount of seconds in the “glide 1 secs to x:(blank)y;(blank)” block. You don’t have to set it to full seconds, you can use something like 0.2 secs.

Step 3: Swatting the Flies
Now, you have to make the flies stop when you hit them with the flyswatter, or the game would be pointless. You can make this happen by putting a “stop other scripts in sprite” block inside a “when this sprite clicked” block. That will make the fly stop moving once you click it. If you want to make the fly look like a splat or something else once you hit it, you can first draw or download a picture of what you want the flies to look like after you click them in the costume area, and then put a “change costume to costume(blank)” block after he “stop other scripts in sprite”block.

Step 4: Boss
If you want, you can make a fly that is harder to swat than the other flies to make the game more fun. You can do this by draw a new fly that looks different from the others. You could make it smaller and harder to hit by using the “shrink” tool and shrinking it. To make it faster, you can increase the steps in the “move forward 10 steps” block if you used tactic one, or you can decrease the secs in the “glide 10 secs to x: (blank y: (blank)” block.

Step 5: Backdrop
You might want an interesting backdrop for your game rather than a blank screen. You can either choose a backdrop from the Scratch backdrop library or you can draw your own.

Step 5: Obstacles
To spice up the game, you can add obstacles that the flies can’t go in to.

To do this, you can add some obstacle sprites into the stage. Go to the code workspace in your flies and add a new “when green flag clicked” block. Under it, add a forever block and put a “if touching mouse-pointer” block inside of it. Change “mouse-pointer” to whatever you called the obstacle sprite. Put a “turn 90 degrees” block and a “move forward 10 steps” block in the “if touching(whatever you called the obstacle sprite) block”, and change 90 degrees to 360 degrees. This will cause the fly to bounce back and start going the other direction if it touches the obstacle sprite.

So, that’s it! I’m still not sure how to make it more like a real game with a menu screen, levels and objectives, but it’s still pretty fun to make your own flyswatter game.

留言

  1. This is such a great, detailed description. I can't believe you learned all this by yourself. Very impressive. I'm going to try this if I have time.

    回覆刪除

張貼留言

這個網誌中的熱門文章

新的寵物魚!

The Trip to the Philippines