Learn Create Your Own Split Screen

Next Page

So what's the bad thing?

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)