Skip to content

Please update your browser

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

arrow_back Die Geheimtür verstecken (Herausforderung)

Transcript

This add-on is slightly more challenging than some of the others. After program this add-on, the user will be able to control the movements of the main character. Also, the main character will only notice the secret door once it touches it.

First, program the character to move with the arrow keys.

Drag out a “move 10 steps” block, and click on it.

The character will probably move right.

Place a “when key pressed” event above the “move 10 steps” block, click the dropdown, and select “right arrow.” Test this. Press the right-arrow key. The character should move right. Great. Now, create similar code to make the character move left. Right click on the code to move right, and click “duplicate.” Change the dropdown to “when left arrow clicked.” Negative numbers in Scratch do the opposite of positive numbers. If “move 10 steps” moves a sprite right, “move negative 10 steps” moves it left. Add a negative sign in front of the 10 in “move 10 steps” to code for the left-arrow key. Test your code. Pressing the left arrow should move the sprite left, and pressing the right arrow should move the sprite right.

This is a basic way to make characters move. If you’d like more information about how to make it look like sprites are actually walking, watch the add-on “Walking.” Instead of putting the walking code inside an “if-else” statement, put it under the appropriate events.

Next, make sure the sprite starts in the same spot each time the story is told, regardless of where it gets moved during the story. To do this, move the character to where it will start. Then, place the “go to x y” block just under the “when green flag is clicked” block. Now the main character walks, but it still immediately mentions the secret door, rather than waiting until it is touching the door to notice it. To make your program wait for a condition, use the “wait until” block. First, fill out the condition.

The sprite can see the door when it is touching it.

The door is part of the background, however, it is the only part that is black. The character can tell it is touching the door if it is touching the color black.

Drag the “touching color” condition into the “wait until” block.

Next, make sure the color in the condition matches the color of the door. Click on the color, then click on the door. Now the block should read “wait until touching color black.”

Figure out where to place the “wait until” block.

Watch what happens when the “wait until” block is placed immediately after the “when green flag is clicked” block. The character doesn’t reset its position, and the scene doesn’t reset to the brick wall!

That happened because when the green flag is clicked, the program waits until the character is touching black before doing anything else. Instead, try moving the wait block after all the set-up, placing it before “should I go through the secret door?”

Test the code. The character begins in its starting position, and the background starts as the brick wall. Move the character. As soon as it touches the black door, it asks if it should go through it. Great. Next, tell the user how to make your program work using the right and left arrow keys. To do this, add a “say” block after the “go to” block. In this example, the character goes to its starting position, then says, "Use the arrow keys to make me move!”

Then, once it touches the black door, it asks the user if it should go through the door. Computer scientists rarely program what they want correctly the first time. They have to be persistent and keep trying until they solve the problem. When you keep working at a problem to figure out how to fix it rather than giving up, you are acting like a computer scientist! Now, it’s your turn: Use the “move” and “when key pressed” event blocks to make the character move when the arrow keys are pressed. Use the “wait until” block to make the character wait until it touches the door before asking if it should go through it.

Make the condition in the “wait until” block “touching color black.”

Tell the user to press the arrow keys to move your sprite by adding a “say” block after the “go to” block.

Erweiterung auswählen
Die Figur gehen lassen
Die Figur sich auf die Tür zu oder von ihr wegbewegen lassen
Ein Passwort hinzufügen
Ein geheimes Passwort programmieren, das der Nutzer eingeben muss, um durch die Geheimtür gehen zu können
Regen programmieren
Das Lager in Scratch dazu nutzen, um den Regen aus dem Projekt von Aktivität 3 in dieses Projekt einzufügen
Die Geheimtür verstecken (Herausforderung)
Die Hauptfigur so programmieren, dass der Nutzer sie mit den Pfeiltasten steuern und bewegen kann, um die Geheimtür zu finden
Eine neue Figur hinzufügen (Herausforderung)
Weitere Figuren zu eurer Geschichte hinzufügen
Eine neue Szene hinzufügen (Herausforderung)
Eine neue Szene hinzufügen und ein paar Ideen für euer Projekt erhalten
arrow_backward Zurück
Weiter arrow_forward
Anweisungen
  1. Wählt eine der Erweiterungen aus und schaut euch das Video an, um zu sehen, wie sie programmiert wird.
  2. Wenn ihr mit einer Erweiterung fertig seid, probiert eine andere aus!