So what's the
bad thing?
- Change the costume to number five (the start of the eating sequence)
- Limit the animation so it only runs to costume 9
- Make it not a continuous animation, so it gets to the end then stops
- Set a much faster animation rate (because nobody wants to be eaten slowly)
But, we only do all this if the costume number is less than 5. In other words, if the berry is
already in the process of being eaten, don't restart the eating sequence. Otherwise berries would only
finish getting eaten when the hero moves away again.
function make_bad_thing_happen_to_fruit (berry) {
if (berry.costume < 5) {
berry.costume = 5;
berry.animation_final_costume = 9;
berry.animation_continuous = false;
berry.animation_rate = 8;
}
}
(You may notice I haven't done anything to remove the dead berry from from the fruit array. I certainly could, but because we're only dealing with a small number of fruit, I'll just leave it there. Also, it lets us leave a red smear on the canvas where the berry used to be, which is kind of pleasing)