Page 274 - Scratch Programming Playground
P. 274

at first, the movement variable is set to a random num-
                         ber between 1 and 6 that decides which movement the crab
                         will make.
                             the rest of the Crab sprite’s code defines these movements.
                         find any code from the Cat sprite code that used the when
                         key pressed blocks and replace those blocks with blocks that
                         check the movement variable. (If you ran the program right
                         now, the keyboard keys would control the Cat and Crab sprites,
                         because they have the same code!)
                             Modify the Crab sprite script that checks whether the player
                         is pressing the a key or d key to match the following code.

































                             as with the Cat sprite, this code lets the Crab sprite walk
                         left and right. Change the values in the walk blocks to -4 and
                         4 to make the crab move slower than the player.
                             then change the script that handles the player pressing
                         the W key to jump to match the following code.











      248   Chapter 9
   269   270   271   272   273   274   275   276   277   278   279