This add-on will make your game more competitive by adding a score that counts the number oftimes the athlete misses the ball. To keep score, use a computer science conceptcalled a variable. Variables are places where computers store information, like numbersand 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 thisvariable “score 1,” then create a second variable using the same process, and callit “score 2.” Click “OK” to create the variable, and notice the new blocks thatshow 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 variablesshould reset to zero. Then, every time the ball sprite moves past the athlete and hitsthe red goal line, the first player’s score variable should go up by one. The same shouldhappen 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 thestage, the score should go up. Start with an “if” block. The condition is that theball sprite must be touching red. From “sensing,” drag out “touching color,” and snap itin as the condition. To select the right color to detect, click the square swatch in theblock so that the pointer turns into a hand, then move the hand to the stage, and clickthe 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 spriteonto 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, thensnap 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 shouldcontinue checking if a goal is scored, so drag a “forever” loop around the conditionalstack. 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 foreverloop. 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 thescore increases, the code loops back to the beginning… wait! It goes through so quicklythat 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 ofthe score. Use a “forever” block, an “if” block,a “touching color” block, and a “change by” block to make sure the score increaseby 1 each time a goal is scored. Start the script with an event, and resetthe score or scores to zero.
Choisir une extension
Réaction au rebond
Programme le lutin Balle pour qu'il dise quelque chose lorsqu'il rebondit.
Dessine ton athlète pour qu'il représente ton équipe favorite.
Ajoute une second athlète pour créer un jeu à deux joueurs.
Enregistrer le score
Ajoute un compteur de points au jeu.
Jouer contre l'ordinateur
Programme un lutin pour qu'il joue contre l'utilisateur.
Fais rebondir la balle dans une direction aléatoire.