Sprite Interaction

Now, change the script so that the sprites don't move forever, but only repeat until they touch.

  1. Change Sprite(2)'s code to point towards Sprite only until it is touching Sprite. The following instructions and animation show how.
    1. Select Sprite(2) by clicking its button below the stage.
    2. Replace the forever block with a repeat until block.
    3. Drag touching sprite into the hexagonal space in the repeat until block. Set it to repeat until it is touching Sprite.
      Replacing code
  2. Do the same for Sprite. Change its code to follow your mouse only until it is touching Sprite(2).
  3. Test your program to see if it does what you want:
    • When you click green-flag button, Sprite (the gray one) should follow your mouse and Sprite(2) should keep turning to face Sprite.
    • If you bring Sprite close enough to touch Sprite(2), both sprites should stop moving.
  4. So far, Sprite(2) points toward Sprite, but doesn't move toward it. Add a line of code to Sprite(2)'s script so that it chases Sprite. Here's the idea:
    Fill the input slot in the move block with a tiny number (probably less than 1) so Sprite(2) doesn't catch Sprite too quickly.
    repeat until touching, point toward sprite, move a tiny amount
  5. Test your program a few times.
  6. Pair Programming Swap
  7. Right now, when the sprites meet, they just stop. Make them have a conversation when they stop. You can do that by adding code like this to Sprite(2)'s script. Make up your own conversation. You can use any language you can type.

    Sprite(2) does things itself. It also tells Sprite what to do and when to do it. This code puts Sprite(2) in charge of Sprite.

    Import Tools

    In the current version of snap, the tell block isn't installed automatically. Click on the File File menu icon menu at the top of the snap window and select "Import Tools." The tell block will appear toward the end of the Control palette. You'll need to import tools once into each new snap project where you need tell.
    Simple dialogue about going to lunch
  8. Now Is a Good Time to Save

You can personalize this project in lots of ways...

  1. You can give the sprites costumes. You can even use a photograph or picture from the Internet by dragging the picture into the costume area for that sprite. If the picture you choose is too big, set its size to something less than 100% using set size to (100)%.
  2. You can make a dialogue about school or home or work.
  3. You can add a third sprite and have it do something, too.
  4. You can even change the background on the stage.
    change the background on the stage