Optimize explosion animation code with loop