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 Appuie sur le champignon (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.

Choisir une extension
Modifie ton circuit
Ajoute un bouton qui change l'arrière-plan circuit.
Changement de costume
Change l'apparence des coureurs lorsqu'une touche est appuyée.
Appuie sur le champignon (Part 1 of 2)
Change la façon dont les coureurs se déplacent, puis fais-les ralentir sur l'herbe.
Appuie sur le champignon (Part 2 of 2)
Change la façon dont les coureurs se déplacent, puis fais-les ralentir sur l'herbe.
Bruitages d'accident
Joue un bruitage d'accident chaque fois que les coureurs se percutent.
Supporters
Programme un lutin pour qu'il effectue un compte à rebours pour le départ de la course et qu'il encourage les coureurs.
Trace de couleur
Ajoute un effet de trace de couleur aux coureurs.
arrow_backward Retour
Suivant arrow_forward
Instructions
  1. Choisis une extension, et clique sur le bouton "Regarder" pour découvrir comment la créer.
  2. Quand tu as fini, reviens à l'écran des extensions et essaies-en une autre !