Lovely!
An important detail and our game is over!
Almost all games played on a computer count points.
It is obvious that in our own game we would also like to count the bananas eaten by the monkey.
So players will be able to compete with each other for who has the highest score making the game more interesting!
In order to keep the score information for the player, we need to use variables.
This is where I will need the help of the specialist. What are variables?
Just as in all programming languages so in Scratch the variables are used to store information.
Essentially there are boxes in our computer's memory that store information that can be changed there.
This is why they are called variables. Because their value may change over the course of the program.
In games almost always there is the "score" variable.
It is a box called a score and it holds the number of points won at any moment in the game.
Of course this number in the course of the game can change.
So let's create the "score" variable.
Go to the “Data” Command palette and hit the button
"Make a variable".
The name of our variable is “score” and it applies to all sprites.
Note that the counter for the variable already appears at the top left of the screen.
We want the variable to be set at 0 when the game starts. This value should be increased by 1 as soon as the banana touches the monkey.
Let me use the appropriate instructions and try the script.
Perfect. Our game is ready!
Let's set up another little detail to improve it.
It is good when a game gets progressively difficult.
So we will adjust the lion that follows the monkey to run at a speed proportional to the score.
The higher the score, the faster it moves.
The "Move 2 Steps" command will change to "move score steps".
Do not forget that when we use the name of a variable we mean the value it has in it.
In this way the lion at the beginning of the game when the score is small will move very slowly.
As the score rises, its movement will become faster and the monkey's attempt to avoid the lion tougher.
Let me run my game to try it out
It works well. But it is still difficult.
I will somehow reduce the speed of the lion hunting the monkey.
After various tests I came to the conclusion that the best number for its move is the score / 4.
I will also minimize the speed of the other lions.
I will also set the positions of all objects when the game starts to always be the same.
Congratulations! Your game is ready. Enjoy it!