Chapter 5. Stress Buster

0 3149 Easy

Have you ever encountered something unpleasant in your life? how did you deal with it? If you want to kick stress out of your life, this stress buster may be a good choice for you. It is a motion sensing game that can help you relieve the negative emotions or stress. Visualize the character in the stage as the people you dislike or the things that made you unhappy, make actions like punch, scratch and pinch in front of the camera, or shake micro:bit board to strike the character and deplete its blood to death.

5.1 Algorithms Analysis


- Open your imagination, draw a sprite as shape 1, then draw another picture 2 showing the sprite collapsed, picture 3 and 4 display that sprite got punched;

- When the program starts, display the shape 1, add a variable “blood volume” and set its value to 100;

- When the variation of the camera’s position is over 50, the blood volume decreases randomly, play screaming sound and switch to shape 3. If the blood volume is 0, switch to shape 2 and display the sprite “KO!”;

- Shake the micro:bit board , then the blood decreases greatly, paly the screaming sound and switch to shape 4. when the blood is depleted, change to shape 2 and display sprite “KO!”.


5.2 Programming


1. Create sprites


Create two sprites: unknown guy and KO. As shown below.

projectImage

Select the character “unknown guy”, right-click “Costumes” to add four costumes (figure 5-2 to 5-5) for him. Costume 1 is the initial state, costume 2 shows the character is struck down. Costume 3 means the man is suffering from minor wound. And in costume 4, the man is severely injured. Shown as below.

projectImage

Use the paint to create a sprite “KO!” One shape is enough for him.

projectImage

2. Add sound effect


Open the sound library, add two screaming sound effect. The method is shown below.

projectImage

Here we record a sound and name it as recording 1. Then we choose another one screaming 1 from the sound library. In the sound interface, we can make revises for the sound, for instance, make it faster, slower, or add specific features for the sound, even we can cut the sound to make it shorter.

projectImage

3. Load camera function


Click “Extensions”-> “Function”->” Video Sensing”, back to the previous interface we can see the extended function in the module area. Shown as figure 5-8.

projectImage
projectImage
projectImage

5.3 Program Description


Do actions like wave, punch, scratch, or strike the head in front of the camera. For the position changing range of the camera, we set the boundaries to 50. You may revise it to realize different game effects.

Except the above play modes, you can also shake the board to relieve the stress, by which to accelerate the decrease of the blood volume. The code is similar to that of the above playing modes. But the blood will be depleted more quickly by shaking. Besides, we set a different screaming sound for this mode and adopt shape 3 here.

We need to focus on the details when programming, for example, the value of the blood volume decreases by 5-10 randomly, but when the current blood volume is 4, the blood value will be negative after the last step. Besides that, after the blood of the sprite has been run out, can we still make him make screaming noise and switch shapes by punching? Absolutely not. Therefore, we set that if the blood value is less than 10, the blood volume is set to 0, and in this circumstance, stop playing sound and changing shapes. All programs stop running. We can use “if then… else” function to realize all of these.

projectImage

5.4 Programming Result


Right-click variable “blood volume” on the stage, and select slider then we can see the change of the blood volume visually. Shown as Figure 5-9.


projectImage

Start the game, the blood volume decreases gradually, as the figure 10 and 13 shows.

projectImage

5.5 Training Camp


How about making a survey to ask yourself what made you unhappy before playing the game? (detection->ask and wait). Create a variable, set its value as “answer” and display the variable, that’s all! To add more playability, we can also design a part to add blood volume for the sprite, come and try it!

License
All Rights
Reserved
licensBg
0