package entities 
{
	import org.flixel.*;
	
	public class Cog extends FlxSprite
	{
		[Embed(source="../../assets/images/CogGreen2.png")]public var cog1PNG:Class;
		[Embed(source="../../assets/images/CogGold2.png")]public var cog2PNG:Class;
		[Embed(source="../../assets/images/cogBlue2.png")]public var cog3PNG:Class;
		[Embed(source = "../../assets/images/CogRed2.png")]public var cog4PNG:Class;
		
		[Embed(source="../../assets/audio/COG.mp3")]public var cogSND:Class;
		
		private var isRunning:Boolean = false;
		private var cogTimer:FlxTimer;
		public var col:int;
		
		public function Cog(_x:int, _y:int, _color:int) 
		{
			if(_color == 2)
			{
				loadGraphic(cog1PNG, true, false, 48, 48, false);
			}
			else if(_color == 1){
				loadGraphic(cog2PNG, true, false, 48, 48, false);
			}
			else if (_color == 5){
				loadGraphic(cog3PNG, true, false, 48, 48, false);
			}
			else if(_color == 0){
				loadGraphic(cog4PNG, true, false, 48, 48, false);
			}
			
			addAnimation("run", [0, 1, 2, 3, 0, 1, 2, 3], 16,false);
			
			x = _x;
			y = _y;
			col = _color;
			this.
			cogTimer  = new FlxTimer();
			offset.x = 8;
			offset.y = 8;
			width = 32;
			height = 32;
		}
		
		public function runCog():void {
			if (!isRunning) {
				FlxG.play(cogSND,0.2);
				play("run");
				cogTimer.start(0.1, 5, onTimer);
			}
		}
		
		private function onTimer(Timer:FlxTimer):void
		{
			Registry.fx.explodeBlock(x, y);
			
		}
	}
}