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 Renvoyer le ballon

Transcript

This add-on will show you how to get the receivers to pass the ball back to the starting point.

You can see in the example that whenever a sprite receives the ball, it immediately passes it back. First, build the code to make the ball turn around. Click the ball sprite to program it. From "motion," grab a "turn right" block, and snap it below the "repeat until" loop inside the conditional that checks if the space key is pressed. This "turn right" block should turn the sprite all the way around to reverse its direction. There are three hundred sixty degrees in a circle, so a half-circle is half of three hundred sixty, or one hundred eighty degrees.

Enter one hundred eighty into the "turn right" block.

Now, the ball sprite will go back to the starting point. Drag out a second "repeat until" loop, and snap it below the "turn right" block. Inside the loop, drag another "move" block to make the sprite keep moving back in its original direction after it turns around.

Find a condition that makes the loop stop running at the right moment. When the sprite touches an edge, you know it's back at its starting point. Go to "sensing," drag a "touching" block into the blank, and select "edge." Testing time! Click the flag, then send the ball flying toward a receiver. When it touches the receiver, it should bounce back. Cool.

Test again by aiming for the edge. The ball should bounce and come back, but it just jumps back to the start. This is because your new loop stops before it can start moving the sprite. It’s still on an edge when the next loop checks, so it exits immediately.

Fix this by placing an extra “move” block right after the turn block. That’ll get the sprite away from the edge. Great, test again. If the "go to" block is still in the right place, then the ball sprite will reset after coming back to the start.

Finally, change the receiving costume back to the kicking one for each receiver sprite.

This makes them look like they kicked the ball back. Just select that sprite in the dropdown on the second "switch costume" block. Here's the game plan: Use a "turn right" and a second "repeat until" block to make the ball sprite bounce back.

Switch the receiver costume to the kicking costume when it touches the ball sprite.

Choisir une extension
Renvoyer le ballon
La balle rebondira toujours à la position de départ.
Puissance / vitesse du receveur
Ajoute des variables réalistes avec des curseurs qui contrôlent la vitesse de la balle et celle des lutins Receveurs.
Enregistrer le score
Comptabilise le nombre de passes que tu as réussies.
Viser et faire des passes
Change l'apparence du lutin Balle.
Enthousiasme
Ajoute un dialogue aux receveurs.
arrow_backward Retour
Suivant arrow_forward
Instructions
  1. Regarde la vidéo de présentation.
  2. Défile vers le bas pour voir les extensions proposées.
  3. Sélectionne une extension et commence la création !
  4. Choisis une autre extension et continue à créer.