This add-on will make your gamemore competitive by adding a scorethat counts the number of times the athlete misses the ball.
To keep score, use a computer science conceptcalled a variable.
Variables are places where computers store informationlike numbers and phrases.
You'll learn more about them in later activitiesin this club as well.
First, select the ball sprite.
To make the score variable, click Make a Variable,and type in score.
If you've added a second player, call this variable score1.
Then create a second variable using the same processand call it score2.
Click OK to create the variable,and notice the new blocks that show uptelling you the things you can dowith 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 athleteand hits the red goal line,the first player 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 spritemust be touching red.
From Sensing, drag out touching colorand snap it in as the condition.
To select the right color to detect,click the square swatch in the block,then the stage, and click the red goal area.
Check that the right color is selected.
Click the change by block.
When you do this, the number inside score goes up by one.
Place this block inside the condition.
If you click the whole stack now,nothing happens unless you drag the ball spriteinto the red goal area.
Success, the score 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 two colorand the score2 variable in the change by block.
Whether you're building this add-on for one sprite or two,the ball sprite should continue checkingif the goal is scored,so drag a forever loop around the conditional stack.
Top off the stack with a when flag click block,but remember that the score needs to be reset to zeroat the start of each new game.
Do this by placing a set two 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 and try to figure out why.
As soon as the score 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 blockinside the if block.
Two seconds is fine, and it fixes the problem.
All right, 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 blockto make sure the score increases by oneeach time the goal is scored.
Start the script with an eventand reset the score or scores to zero.
Choose an Add-On
Program the ball sprite to do or say something when it bounces.