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 Piede sul gas (Part 2 of 2)

Transcript

In step 2 of this add-on, I'll show you how to program the racer to drive quickly on the grey concrete, and slowly when on the green grass.

To code this, you will use an “if-else” block. This block will end up reading: “If touching the grass, set speed to something slow. If touching anything else, set speed to something fast.” To start, click on player 1.

Select events, and drag out a "when green flag clicked" block to start this block stack.

Then, go to Control, and select a forever loop.

Inside this forever loop, I'll put an "if-else" statement which is also found in Control.

Now, program this to say: The computer can sense if a sprite is touching a color, so use a "touching color" block found in the Sensing menu to see if the sprite is on the green grass.

Click on the color in this block, then on the green color in the project to change the value of this block.

Then, click on data and select a “set speed block," and change the value to 2.

Remember, this block won’t be there if you haven't completed the previous screencast. In the “else” space in the if-else statement, place another “set speed” block. Change this value to something faster, like 7.

Your code now reads: When the flag is clicked, if the sprite is touching green, set speed to 2.

If the sprite is touching anything else, set speed to 7.

The forever loop makes sure that this if-else statement runs forever, not just once. Let's try it out!

Click the green flag to start.

to tell the computer when to run this code. Test your code by clicking the flag.

Now my player 1 sprite moves slowly when on the green grass and quickly when on the gray concrete.

You can also program this for player two.

Scegli un’estensione
Cambia la tua pista
Aggiungi un pulsante per cambiare lo sfondo della pista.
Cambia il costume
Cambia l'aspetto dei piloti quando viene premuto un tasto.
Piede sul gas (Part 1 of 2)
Modifica la velocità di movimento dei piloti e poi falli rallentare sull'erba.
Piede sul gas (Part 2 of 2)
Modifica la velocità di movimento dei piloti e poi falli rallentare sull'erba.
Suoni di schianto
Riproduci il suono di uno schianto ogni volta che i giocatori si tamponano.
I fan della gara
Programma uno sprite a fare il conto alla rovescia alla partenza della gara e a fare il tifo.
Scia colorata
Aggiungi un effetto scia colorata ai piloti.
arrow_backward Indietro
Avanti arrow_forward
Istruzioni
  1. Scegli un componente aggiuntivo e fai clic su "Guarda" per scoprire come costruirlo.
  2. Quando hai terminato, torna sulla schermata dei componenti aggiuntivi e prova un altro componente aggiuntivo!