Un Personaje siguiendo al Ratón

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

En esta página, tú vas a programar el primer personaje que sigue el apuntador del Ratón y programaremos un segundo personaje que apunta en la dirección del primer personaje en preparación para seguirlo.

  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.
Now Is a Good Time to Save