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 add-on, you’ll make the object appear in a random place each time the user plays the game. This makes the game less predictable and more fun.

In the core project, the object shows when the game switches to a specific backdrop.

Since the object should show on a random backdrop, select the object, detach the “when backdrop switches to” block, and delete it. Click the stage, then the “backdrops” tab. There are four different backdrops: one for the town, and one for each of the three locations. Each of these backdrops has a number. Click the “scripts” tab, then open the “looks” menu. Find the “backdrop number” block, and click it to see what it does.

This block outputs the current backdrop’s number.

Add this block to the “objects” sprite by dragging it on top. Then, click the “objects” sprite. Cool. The “backdrop number” block appears in the scripts area.

Click “data,” then click “make a variable.” A variable holds a value. In this case, this variable will hold a random backdrop number where the object will appear. Name the variable “object location,” then click “OK.” Set this variable to a random number. Drag out a “set object location” block, then place a “pick random” block from “operators” into it. Type “2” and 4” in the value spaces, because backdrops 2, 3, and 4 represent the three possible locations where the object can be found.

Test this block by clicking on it a few times. The value next to “object location” on the stage changes to a random number between 2 and 4 each time. Great! Place this block above the “forever” block, so the program decides where the object will hide at the start of the game. Next, build a conditional statement that checks if the current backdrop equals the object location. Drag out an “if” block. Place an “equals” block inside the condition slot. Click data, and drag the “object location” block into one slot, and the “backdrop number” block into the other.

If this statement is true, make the object show, then detect if the player is touching it. Put this conditional around the “touching character” conditional, and move the “show” block into the “if” statement. Add a “when flag clicked” block on top so this code runs when the flag is clicked.

Finally, open the “data” menu, and uncheck the box next to “object location.” This hides the variable display on the stage so the player can’t see the answer.

This code now reads: When the flag is clicked, set the object location to a random number between 2 and 4. If the current backdrop number is equal to that random number, meaning the character is at that location, then, the object shows.

Test it out by playing the game more than once. The object now appears at a random place each time. Now, it’s your turn!

Select the object sprite, and discard the “when backdrop switches to” block for the “touching character” conditional. Drag the “backdrop #” block from the stage into the “objects” sprite. Create a “object location” variable, and set it to a random number at the start of the program.

Build a conditional that checks if the backdrop number equals the object location variable.

If the condition is true, show the “object” sprite, and turn on the winning condition.

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