Skip to content

Please update your browser

Your browser version is not supported by this site. CS First may not work properly. Learn more

Transcript

In this video, you’ll learn how to make it look like the character is moving towards or away from the door. Start by programming the character to move.

Drag out a “move ten steps” block. People don’t walk without moving their feet.

Several Scratch sprites come with different costumes that make it look like they are walking the way people do.

To check if the sprite you chose is one of them, click on the costumes tab. This example uses the Scratch cat, who can switch between these two costumes to look like it’s walking.

If you did not choose a walking sprite for your story and you would like one, click on “choose new sprite from library,” then the walking menu. To copy your code from one sprite to another: Now, you can get rid of the old sprite and use a walking sprite instead. To make use of the walking costumes, you need to switch between them. To do that, go back to the scripts tab. Click on the looks menu, and find the “next costume” block. Click on it to switch costumes.

To keep switching costumes without clicking the block over and over, place it inside a repeat loop. To move while switching costumes, place the “move” block inside the repeat loop as well. Test the code. Now, it looks like the character is walking as it moves in a direction. But, you want the character to walk toward the door and go through it if a certain condition is met. To make that happen, Place the code below “if answer = yes” and above “switch backdrop to.” Test the code.

If you answer “should I go through the secret door” with “yes,” the sprite should walk towards the door. It does. If the answer is “no,” the sprite should move in the other direction. The code to make the character walk in the other direction is the same, so duplicate the walking code you made already.

Before the character walks, though, it needs to change direction. That is where the “point in direction” block comes in handy. “Point in direction 90” faces the sprite right. You want the sprite to walk left, away from the door. Place the “point in direction” block above the copied walking code. Click on the dropdown, and switch it to negative 90. That should point the character in the opposite direction. Click on the block to test it.

Wait! The main character is upside down! That is because of how the character is rotating, or turning. The “set rotation style” block will fix this.This sprite should only turn left or right. Click on the dropdown menu, and select “left right.” Now, click on the block. The character should only face left or right. You’ll notice that it turned right-side up. To make sure it stays that way, place this block at the beginning of this character’s code, just below “when green flag is clicked.”

Place the walking code in the “else” section of the “if answer = yes” block. Test your code again. Try saying “no” when the code asks if you want to walk through the door. The character should walk away from it. Then, try the code, but enter “yes” instead.

What!? The character still goes left. This is because the character continues to move in the direction it was last told to go. To make the character move right, place another “point in direction” block above the walking code in the “answer = yes” section. Click on the dropdown menu to make sure it is telling the character to go right.

Test the code by clicking on the green flag. Type “no” first, and watch the character walk left. Then, type “yes,” and watch the character move right. Nice job!

So you can control where the character goes, it should always start in the same spot. Pick a spot where you want the character to start, and drag your sprite there. Then, place a “go to x y” block under the “when green flag clicked” block so that the character will always start in that spot. Test your code by clicking the green flag. It works!

Tinker with the values in the “move” and “repeat” blocks to change how far the character moves.

Scegli un’estensione
Cammina
In questo video scoprirai come fare avvicinare il personaggio alla porta e come farlo allontanare.
Qual è la password?
Con questo componente, programmerai una password segreta che l'utente dovrà inserire per attraversare la porta segreta.
Fai piovere
Con questo componente, scoprirai come usare la valigetta per inserire nel progetto la pioggia che hai creato durante la terza giornata.
Trova la porta segreta
Con questo componente, farai muovere il personaggio su comando dell'utente con i tasti freccia.
Aggiungi un altro personaggio
Con questo componente aggiuntivo, inserirai nella storia altri personaggi.
Aggiungi un'altra scena
In questo componente ti guiderò nell'aggiunta di una nuova scena e ti darò qualche suggerimento su come programmarla.
arrow_backward Indietro
Avanti arrow_forward
Istruzioni
  1. Scegli un componente aggiuntivo e fai clic su "Guarda" per scoprire come costruirlo.
  2. Una volta terminato un componente aggiuntivo, scegline un altro da provare!