Page 66 - 2501_KVS_C-5
P. 66

Aryan:  What is this “reporter” block now? I have heard to this name for the first time in
                     scratch.

                     Gowri: Yes dear! These are the blocks, which are designed to fit in the input area of other
                     blocks and gives or returns the value of that variable or block.


                     Aryan: Ok dear, that’s interesting. Now, please tell me the script to calculate the score of the
                     game and code to decrease the life of the “spaceship” when “planet” hits the “spaceship”.

                     Gowri: Yes, let’s learn this with the activity given below:







                                Activity 6.5

                    Calculate the score in the game created above. Increase the value of the score

                    variable, when the sprite “missile” hits the sprite “planet” and also delete its
                    clone. Also set the life of the sprite “spaceship” as 5 and decrease its value,
                    when the sprite “planet” hits the sprite “spaceship”.





                  Answer

                  Step 1:   Choose the sprite “planet” and create two variables named as “score” and
                              “life”.

                  Step 2:   Two new reporter blocks named “score” and “life”
                              are also created with “variable” block (shown in
                              Fig. 6.7) and now set the value of the variable
                              “score” to 0 and variable “life” to 5 by dragging

                              “set… to…” block under “when flag clicked” block.
                              When this sprite hits the sprite “missile”, then
                              change  the  value  of  variable  “score”  by 1.  Also
                              change the value of the variable “life” by -1 to                         Fig. 6.7

                              decrease its value, when this sprite hits the sprite “spaceship”.  See
                              the coding for the sprite “planet” as shown in Fig. 6.8.















                64                         KVS DELHI REGION 2025
   61   62   63   64   65   66   67   68   69   70   71