/***********************************************
 * _explosion2.zes
 * 
 * Author: GD
 * Date:   12 June 2002
 *
 * Desc:   An Explosion script for creating small explosions
 * 		   on the fly, for small things like when two swords hit
 *		   each other etc..
 *
 * Usage:  Use CreateEntity, it will delete itself
 *		   When it runs out
 *         
 *         
 * Sprites: _MiscSheet.spt
 *
 ***********************************************/
#include <entity>
#include <general>
#include <animation>

new MainAnim[20];	// String to hold animation identifier
new x;
new y;

//----------------------------------------
// Name: main()
//----------------------------------------
main()
{
	if (FirstRun())
	{
		// Create and set up the animation
		CreateAnim( 16, MainAnim );
		AddAnimframe(MainAnim, -4, -4, "_explosions1");
		AddAnimframe(MainAnim, -4, -4, "_explosions1a");
		AddAnimframe(MainAnim, -8, -8, "_explosions2");
		AddAnimframe(MainAnim, -8, -8, "_explosions3");
		AddAnimframe(MainAnim, -8, -8, "_explosions4");
		SetAnimLoop(MainAnim, false);
		x = GetX("this");
		y = GetY("this");
		SetActiveDist("this", -2);
	   	SetActiveInGroups("this", true);
	}
	
	if (isActive("this"))
	{		
		// Draw the Explosion
		if (isVisible("this"))
			DrawAnim(MainAnim, x, y, y + 240);
		
		// Check if anim is over
		if (FinishedAnim(MainAnim))
		{
			// Delete it all
			DeleteAnim(MainAnim);
			DeleteEntity("this");
		}
	}
}
