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 the core project, you enabled the character sprite to move around the locations. It even moves straight through trees! In this add-on, you’ll make it impossible for the character to walk through some objects. Click on the character sprite. Program it to move backwards if it touches a color that the obstacle contains. Open the “control” menu, and drag out an “if” block. Then, open the “sensing” menu, and drag a “touching color” block into the condition of the “if” block. Click the colored square, then click on an obstacle to select the color. This example uses the dark green on the outside of the trees.

Then, open the motion menu, and add a “move” block into the “if” block. Change the value to negative 10 so that the sprite will move backwards.

To test this, drag the character on top of the trees, then click the stack. The sprite should move backwards 10 steps. Cool! Make the sprite continuously check whether it needs to move backwards by putting a “forever” block around the “if” block. Then, add a “when flag clicked” block on top. Click the flag to test, and use the keyboard to move the sprite to the trees. Nice! The sprite can’t move into the trees.

To make the sprite react to other obstacles, duplicate the “if” block. Program this code outside the forever loop first, to make it easier to select a color. Click on the new color swatch on the “touching color” block, then select a new color unique to an obstacle, such as the light grey in the house. Test this out by moving the sprite to the house. Cool! Now it can’t move into the house, but it can still go through the door.

You may need to tinker with the color a few times to get this to work.

Since each backdrop contains different colors and obstacles, the color rules that work for one backdrop may not work for another. To make these rules only work on the “town” backdrop, put an “if” block around the “if touching color” blocks. Place an “equals” operator in the condition field. Then, click “looks,” and place a “backdrop name” block on the left. Type “town,” or the name of the backdrop, on the right. Now these color rules only apply when the backdrop name equals “town.”

Use the same method to make the sprite bump into obstacles in the other locations of the RPG. It will take some tinkering and creativity to get this to work. Don’t be afraid to make mistakes! Now, it’s your turn!

Make the sprite move backwards when it bumps into obstacles using the “touching color,” “move,” “if,” and “forever” blocks. Ensure that the color rules work only for a specific backdrop using the “backdrop name,” “equals,” and “if” blocks.

Add as many color rules as you like using the same blocks.

Scegli un’estensione
Risistema gli accessori
Personalizza l'aspetto di ciascun luogo.
Cucù
Rendi il gioco più impegnativo mostrando l'oggetto solo se il personaggio si trova nelle vicinanze.
Codifica una conclusione
Aggiungi alcune slide per concludere la storia quando il giocatore vince.
Oggetti musicali
Aggiungi elementi interattivi che emettono un suono quando il personaggio ci cammina sopra.
Ostacoli ostruenti
Rendi le mappe più realistiche, impedendo al personaggio di imbattersi in ostacoli come alberi o edifici.
Nascondino
Nascondi l'oggetto in un luogo casuale ogni volta.
arrow_backward Indietro
Avanti arrow_forward