Time for action - add new paddle controls

Moving the paddle with the mouse works, but users on a laptop may find the trackpad a bit difficult to use. We're going to use the left and right arrow keys for our movement:

  1. Select the paddle sprite from the sprites list.
  2. From the Control palette, add when space key pressed to the scripts area.
  3. Change the value to left arrow.
  4. From the Motion palette, add the move 10 steps block to the when left arrow key pressed block.
  5. Change the value to -10 steps.
  6. Add a second control block that uses the right arrow key to move 10 steps.
  7. Play the game and use the arrow keys to move.
  8. Let's try to take bigger steps. Change the number of steps to a larger number, such as 50.
  9. Clean up the script by removing the original when flag clicked block that used the mouse x value to control the sprite. We no longer need it.
  10. From the Motion palette, uncheck the x position block.
Time for action - add new paddle controls

What just happened?

The complexion of our game has changed. If you did the hero exercise, your paddle sprite probably has a smaller surface to hit the ball than the original paddle. The arrow keys restrict how fast the sprite moves across the stage.

Each time we pressed the key, the sprite stepped to the left or right depending on which arrow we used. The move 50 steps block moved five times as far with one keystroke than the move 10 steps block.

Play theme music, forever

A video game just wouldn't be any fun without some music, but before we can add music, we need to find some. You can use an MP3 from your music collection, search Creative Commons, or use a site such as free-loops.com. If you're musically inclined, you could build your music loop using the sounds we learned about in Chapter 5.

If you don't have a favorite sound, don't worry. Scratch includes a library of sounds you can use.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.3.175