package com.isartdigital.game.sprites;
import com.isartdigital.utils.game.BoxType;
import com.isartdigital.utils.game.factory.MovieClipAnimFactory;
import com.isartdigital.utils.game.GameStage;
import com.isartdigital.utils.game.StateGraphic;
import com.isartdigital.utils.system.DeviceCapabilities;
import pixi.extras.MovieClip;

/**
 * ...
 * @author Nathan
 */
class Foule extends StateGraphic
{

	public static var arrayFoule : Array<Foule> = new Array<Foule>();
	public static var nbFrame : UInt = 20;
	
	public function new()
	{
		super();
		factory = new MovieClipAnimFactory();
		boxType = BoxType.SIMPLE;
		arrayFoule.push(this);
	}
	
	public function init() {
		start();
		setModeNormal();
		//position.set(DeviceCapabilities.getScreenRect(GameStage.getInstance()).x + DeviceCapabilities.getScreenRect(GameStage.getInstance()).width / 2,
					//DeviceCapabilities.getScreenRect(GameStage.getInstance()).y + DeviceCapabilities.getScreenRect(GameStage.getInstance()).height / 2);
	}
	
	override function doActionNormal():Void 
	{
		super.doActionNormal();
		untyped anim.onComplete = function() { finished(); }
	}
	
	
	private function finished ():Void {
		arrayFoule.splice(arrayFoule.indexOf(this), 1);
		GameStage.getInstance().getDecorContainer().removeChild(this);
		this.destroy();
	}
	
	override function setModeNormal():Void 
	{
		setState(DEFAULT_STATE);
		untyped anim.animationSpeed = 0.15;
		super.setModeNormal();
	}
	
	public static function doActionManager(): Void {
		if (nbFrame == 0) {
			var lFoule = new Foule();
			GameStage.getInstance().getDecorContainer().addChild(lFoule);
			lFoule.init();
			nbFrame = 20;
		} else {
			nbFrame -= 1;
		}
	}
	
}