Page 55 - 2501_KVS_C-5
P. 55

Now come back to our game project again.
                 Step 5:    In  the  figure  5.4,  in  “go  to…”  block

                             “spaceship” option is to be chosen to move
                             the sprite “missile” to the position of the
                             sprite  “spaceship”.    Then  “point  towards
                             “spaceship”  block  is  used  and  after  that

                             “move  40  Steps”  block  is  used  to  move
                             the sprite “missile” till edge of the sprite
                             “spaceship”.  So  that  it  looks,  as  missiles
                             are coming out of the spaceship nozzle.

                 Step 6:   Now,  choose  the  sprite  “spaceship”  and
                             do  the  following  code  on  it  (see  figure

                             5.12). First Set the position of the sprite
                             “spaceship” at left side with position value
                             as -200 and y position value as 0 using “go
                             to x… y…” block. Also set the size of the

                             spaceship  to  the  50%  of  its  actual  size.
                             Now do coding in “forever” block, to move
                             the  sprite  “spaceship”  left,  right,  up  and
                             down  as  per  the  arrow  keys  pressed.    If

                             the  left  arrow  key  press,  the  sprite  will                  Fig. 5.12
                             move horizontally in backward direction (left side) by the block “change
                             x to -10”. The sprite will move horizontally in forward direction (right
                             side) by the block “change x to 10” block. The sprite will move vertically in

                             upward direction by the block “change y to 10” block. The sprite will move
                             vertically in downward direction by the block “change y to -10” block.




                                  Aryan: OK! I understood now how to move the sprite horizontally and vertically
                                  and how the missile will move towards the spaceship, when its clone appears on the
                                  stage. Ok! then what is this “point in direction” block and “key pressed?” block.




                     Gowri:  Aryan,  “point  in  direction”  block  turns  the  direction  of  the  sprite
                     towards left, right, up, down (according to the given value) or towards any
                     other sprite. And “key pressed?” block is used to check which key is pressed
                     by us. Lets see “point in direction” block first.







                                                                                      Scratch                       53
   50   51   52   53   54   55   56   57   58   59   60