Learn Create Your Own Split Screen

Next Page

Instead, we'll declare a variable called fruit_remaining, and set it equal to the length of the fruit array after we've loaded all our fruit.
add_fruit(20, 20) ; add_fruit(-20, 220) ; add_fruit(-50, 320) ; add_fruit(290, 170) ; add_fruit(390, 100) ; add_fruit(200, -60) ; var fruit_remaining = fruit.length;

Then, every time a bad thing happens to some fruit, we'll reduce it by one.

function make_bad_thing_happen_to_fruit (berry) { if (berry.costume < 5) { fruit_remaining--; berry.animation_continuous = false; berry.animation_final_costume = 9; berry.costume = 5; berry.animation_rate = 8; } }