Sprite Following the Mouse

Need to change sprite to be age-appropriate. --MF, 12/14/18

In many programs, the visual elements on the screen need to interact—follow each other, avoid each other, react a certain way when they meet each other, etc. In this lab, you will program two sprites. One sprite will follow your mouse. The other sprite will chase the first. When they meet, they will have a short conversation.

Puppy chase

On this page, you will program the first sprite to follow your mouse and program the second sprite to point in the direction of the first sprite in preparation for following it.

  1. "U1L5-SpriteChase"Create a new project called U1L5-SpriteChase
  2. Talk with Your Partner Read and think about this script before you build it. What do you expect it to do?
    when green flag clicked{forever{go to x:(mouse x) y:(mouse y)}}
  3. Now build the script and run it. Move your mouse around the stage while the program is running.
    To stop this script, click the red stop sign: stop button
  4. Talk with Your PartnerDoes the program work the way you expected?
  5. The new sprite, named Sprite(2), appears on the stage. It's brand new, so it has no scripts. The buttons beneath the stage let you select the sprite you want to program.
    Create a second sprite by clicking on the add a new turtle sprite button just below the stage.  
  6. To make your sprite names meaningful, change the name of Sprite to Leader, and change Sprite(2) to Follower.
    To change the name of a sprite, look for the name in a gray box above the scripting area. Click inside the name and you'll be able to edit it.
  7. While a script is running, its border lights up. If the running time is short, you may not notice the brief flash.
    Write a script for Follower so that once the green flag is clicked, Follower will point towards [] Leader forever.
  8. Both sprites' scripts use Whengreen-flag buttonclicked, so both scripts run when green-flag button is clicked.
    Click green-flag button and check that your scripts do what you intended:
    • Leader always follows your mouse when you move your mouse around.
    • Follower stays in one place, but always points toward Leader.
Save your work
I think we agreed that this icon should be an LI. No? There is one on 1.1.5.4 and 1.2.2.8 too. See comment on 1.1.2.9. --MF, 5/30/20