Box Breaking

Durability

The boxes can have a resistance level to damage.  

Once that level reaches 0 - the box becomes breakable.

Code Explanation

When the Durability of the box is 0 or less

AND the Hit animation is NOT playing

Destroy the box

Play an assoicated sound effect.

Once Durability is <= 0 AND Hit is NOT playing:

Repeat the following code 4 times:

Spawn the broken box sprite

Set the current frame to the current loop number

Apply physics to send pieces in random directions

Wait for 2 seconds

Flash the broken pieces

Wait 1 second

Destroy the broken pieces