Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 137 - 2505_CoreGPT(Podar)_Flipbook_C5
P. 137

    Becomes true when the sprite touches a
                                                  defined colour
                                                  Becomes true when color1 touches color2

                                                  Becomes  true  when a specified key is
                                                  pressed on the keyboard
                                                  Asks a question from the user and waits

                                                  for the answer
                                                  Stores the answer or input given by the

                                                  user

                     Let us develop a simple program where the cat

                     sprite moves towards a basketball when right
                     arrow key is pressed. The code for the cat sprite
                     can be similar to this.

                           USING THE KEYBOARD KEYS

                     In Scratch,  you  can  control  your  sprite's actions  with  the  keyboard  using

                     specific blocks from the  Control and  Sensing blocks categories.  Here's a
                     detailed overview  of the blocks you can use to work  with keyboard  inputs:

                                      Control Block                                     Sensing Block

                                                                                                 It can  be used in
                                           It allows you to trigger
                                                                          if-else statements to  make decisions
                      actions when a specific key is pressed. You
                                                                          based  whether  a  specific key is
                      can  select from several  keys, including
                                                                          currently pressed, returning a true or
                      arrow  keys, letters and other  keys like
                                                                          false value.
                      spacebar, enter, shift, etc.
                     Let us create a small project using the above blocks. Add a sprite and a background

                     of your choice.
                     Now, create the following script:

                     You will observe that
                     pressing  the  chosen  key

                     will activate  the  project
                     and cause the sprite to
                     perform the assigned task.

                                                                                     Basic Programming in Scratch       135

| 132 133 134 135 136 137 138 139 140 141 142 |