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 Segnapunti


This add-on will make your game more competitive by adding a score that counts the number of times the athlete misses the ball. To keep score, use a computer science concept called a variable. Variables are places where computers store information, like numbers and phrases. You’ll learn more about them in later activities in this club as well.

First, select the ball sprite. To make the score variable, go to the “data” menu.

Click “Make a Variable,” and type in “score.” If you’ve added a second player, call this variable “score 1,” then create a second variable using the same process, and call it “score 2.” Click “OK” to create the variable, and notice the new blocks that show up telling you the things you can do with your new variable.

Here’s a quick overview: Every time you click the flag, the score variable or variables should reset to zero. Then, every time the ball sprite moves past the athlete and hits the red goal line, the first player’s score variable should go up by one. The same should happen for the second player. So, the lower your score, the better you are at the game!

First, build the scoring conditional. If the ball sprite is touching the red part of the stage, the score should go up. Start with an “if” block. The condition is that the ball sprite must be touching red. From “sensing,” drag out “touching color,” and snap it in as the condition. To select the right color to detect, click the square swatch in the block so that the pointer turns into a hand, then move the hand to the stage, and click the red goal area. Check that the right color is selected!

In “Data,” click the “change by” block. When you do this, the number inside “score” goes up by one. Place this block inside the conditional.

If you click the whole stack now, nothing happens unless you *drag* the ball sprite onto the red goal area. Click again. Success! The score again goes up by one.

To make this work for two players, right-click and duplicate the whole “if” block, then snap the duplicated stack below. In the second conditional, choose the blue “Goal 2” color and the “score 2” variable in the “change by” block.

Whether you’re building this add-on for one sprite or two, the ball sprite should continue checking if a goal is scored, so drag a “forever” loop around the conditional stack. Top off the stack with a “when flag clicked” block, but remember that the score needs to reset to zero at the start of each new game.

Do this by placing a “set to” block right under the event, but not inside the forever loop. If you have a second player, do this for their score as well.

Test and see what happens. You may notice that whenever the ball hits the goal area, the score goes up by more than one. Look at the code to figure out why. As soon as the score increases, the code loops back to the beginning… wait! It goes through so quickly that the ball is still touching the red - so the score increases again!

To fix this, add a “wait” block after the “change by” block inside the “if” block. Two seconds is fine, and it fixes the problem.

Here’s the game plan: Make one or two variables to keep track of the score. Use a “forever” block, an “if” block, a “touching color” block, and a “change by” block to make sure the score increase by 1 each time a goal is scored. Start the script with an event, and reset the score or scores to zero.

Scegli un’estensione
Reazione al rimbalzo
Ordina allo sprite Palla di fare o dire qualcosa quando rimbalza.
La maglia della squadra
Fai indossare all'atleta la maglia della tua squadra del cuore.
Secondo giocatore
Aggiungi un altro atleta per creare una partita a due.
Aggiungi un segnapunti al gioco.
Sfida il computer
Programma uno sprite che giochi contro l'utente.
Rimbalzo casuale
Fai rimbalzare la palla in una direzione a caso
arrow_backward Indietro
Avanti arrow_forward
  1. Scegli un componente aggiuntivo e fai clic su "Guarda" per scoprire come costruirlo.
  2. Una volta terminato un componente aggiuntivo, scegline un altro da provare!