Personaje Siguiendo a Personaje

The tell block image(s) need to be updated (see relevant piazza post). The solution file definitely needs to be updated too (both with tell and with the new sprite names), and perhaps also images in the TG. Also search site for other instances of tell. --MF, 11/6/17

Teacher feedback from 2017-2018: [students] not understanding the need to create their own phases after reading page 2, step 6 where other languages are shown --MF, 3/6/19

En esta página, tú vas a cambiar el programa para que el personaje no se mueva siempre, finalizando hasta que ellos se toquen.

  1. Change Follower's code to point towards Leader only until it is touching Leader. (The following instructions show how.)
    1. Select Follower by clicking its button below the stage.
    2. Replace the forever block with a repeat until block.
    3. Drag touching ()? into the hexagonal space in the repeat until block. Set it to repeat until it is touching Leader.
      Video needs to be rebuilt with new sprite names. --MF, 8/19/19
      Click for a video of this code being built.
      Replacing code
  2. Do the same for Leader. Change its code to follow your mouse only until it is touching Follower.
  3. Test your program to see if it does what you want:
    • When you click green-flag button, Leader (the gray one) should follow your mouse and Follower should keep turning to face Leader.
    • If you bring Leader close enough to touch Follower, both sprites should stop moving.
  4. So far, Follower points toward Leader, but doesn't move toward it.
    1. Add a line of code to Follower's script so that it chases Leader. Here's the idea:
      Fill the input slot in the move block with a small number so Follower doesn't catch Leader too quickly.
      when green flag clicked:
repeat until (touching (Leader)?)
{
    point towards (Leader)
    move () steps ← Comment: Type a small value in this empty input slot.
}
    2. AAP-2.K.5
    3. What happens if the sprites are already touching? That is, what happens if you drag one sprite on top of the other and then click the green flag? Why?
    4. AAP-2.K.4
    5. What happens if the input to move is 0?
    6. Need to add some text about infinite loops, like forever on 1.3.6. --MF, 8/6/19

    When a program keeps doing the same thing and doesn't ever stop, it's called an infinite loop.

AAP-2.K.3
The language used on the AP Exam doesn't allow spaces in names of inputs (such as number of fish) or in programmer-defined procedures (such as mouse y, which isn't built into their language). So this example translates them to
numFish
and
MouseY()
.
The reason for the
()
or box after
MouseY
is that
MouseY()
is a procedure call even though it doesn't take any inputs.

The script
repeat until (mouse y < 0) {say (number of fish)}
would be written as

I worry that the mouse Y procedure call block formatting might be wrong because we don't yet know what the correct APblocktran form of a procedure call will be. Waiting for the new exam reference sheet. --MF, 3/1/19

TODO: change mouseY() to camelCase and edit image to use a box instead of () after mouseY. --MF, 8/27/19

REPEAT UNTIL(MouseY() < 0)
{
    DISPLAY(numFish)
}
or a gray rounded rectangle containing all of the following: on the first line, first the words 'REPEAT UNTIL' in all caps and then a smaller gray rounded rectangle containing 'MouseY () < 0' and on the second line, a white rounded rectangle with a smaller white rounded rectangle inside that contains first the word 'DISPLAY' in all caps and then a smaller white rectangle containing 'numFish'

Remember, you don't need to learn to write the made-up language used on the AP exam. You just have to be able to read and answer questions about it.

  1. Test your program a few times.
  2. Pair Programming Swap
  3. 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 Leader's script. Make up your own conversation. You can use any language you can type.

    Leader does things itself. It also tells Follower what to do and when to do it. This code puts Leader in charge of Follower.
    CRD-2.B.2, AAP-2.B.2, AAP-2.B.6

    A code segment is a sequence of connected instructions that carry out a purposeful action, such as the one pictured on the left, which animates a conversation. The instructions in the code segment are carried out in order, from top to bottom.

    This image needs better alt/title text. --MF, 8/22/19
    Simple dialogue about going to lunch
To prevent the two sprites from being stuck to each other unable to move, the sprites will need some space between them and some time apart before the chase starts. Blocks such as these may help.
go to x:(-200) y:(-50); wait (1) secs & go to x:(200) y:(-50); wait (1) secs
Now Is a Good Time to Save
  1. Give the sprites costumes.
    You can use a picture from the Internet by dragging the picture into the Snap! window.
  2. Change the background on the stage.
    There are instructions in the If There Is Time section on Unit 1 Lab 2 Page 3: Customizing and Debugging.