Sprite Interaction

Now, change the script so that the sprites don't repeat their movements forever, but repeat until they touch each other and then stop.

  1. Change Sprite(2)'s code to point towards Sprite only until it is touching Sprite. Follow these instructions or watch the animation below:
    1. Click the Sprite(2) button below the stage.
    2. Replace the forever block with a repeat until block.
    3. Drag a touching sprite block into the hexagonal space in the repeat until block, and set it to repeat until it is touching Sprite.
      Replacing code
  2. Change Sprite's code to follow your mouse only until it is touching Sprite(2).
  3. Try out your program.
  4. When you click green-flag button, Sprite (the gray one) should follow your mouse and Sprite(2) should keep turning to face Sprite. But once you bring Sprite close enough for the two to touch, both sprites should stop moving.
  5. Sprite(2) points toward Sprite, but doesn't move toward it. Add a line of code so that Sprite(2) chases Sprite. Here's the idea:
    You may want each "tiny number" to be even less than 1 step so that Sprite(2) doesn't catch Sprite too quickly.
    repeat until touching, point toward sprite, move a tiny amount
  6. Test your program a few times.
  7. Pair Programming Swap
  8. 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
Now Is a Good Time to Save

If you like, 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 or play.
  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