Best Fruit So Far
When players merge fruits to make a bigger fruit we should keep track of which is the biggest fruit they have made so far.
When players merge fruits to make a bigger fruit we should keep track of which is the biggest fruit they have made so far.
Add a helper variable for this.
Add a helper variable for this.
Add a new function to the functions group
Add a new function to the functions group
Call it updateBestFruit
Call it updateBestFruit
Add a number parameter called justSpawned
Add a number parameter called justSpawned
Add two conditions to the function:
Add two conditions to the function:
If the value of the fruit which justSpawned is greater
If the value of the fruit which justSpawned is greater
than the current bestFruit
than the current bestFruit
If the animation fames match
If the animation fames match
The best fruit is the one which has just spawned
The best fruit is the one which has just spawned
Then you tween (smoothly move) the star to position it under the best fruit so far.
Then you tween (smoothly move) the star to position it under the best fruit so far.
This is essentially an algorithm to find the biggest number.
This is essentially an algorithm to find the biggest number.
Call this function after fruits have merged. Update the end of the processCollision function as shown by passing the animation frame name as the justSpawned number.
Call this function after fruits have merged. Update the end of the processCollision function as shown by passing the animation frame name as the justSpawned number.