package Game.Mobs
{
	import flash.events.MouseEvent;
	import flinjin.graphics.Layer;
	import flinjin.sound.FlinjinSound;
	import Game.GameMain;
	
	/**
	 * ...
	 * @author Michael Miriti
	 */
	public class Mob extends Layer
	{
		static public const STATE_IDLE:int = 0;
		static public const STATE_MOVING:int = 1;
		static public const STATE_ATTACK:int = 2;
		static public const STATE_DIENG:int = 3;
		
		protected var _state:int = 1;
		
		protected var _healhPoints:Number;
		
		[Embed(source="../../snd/explosion.mp3")]
		private static var _explosionSnd:Class;
		
		protected var _explosionSound:FlinjinSound = new FlinjinSound(new _explosionSnd());
		
		public function Mob(layerWidth:uint, layerHeight:uint)
		{
			super(layerWidth, layerHeight);
			pixelCheck = true;
			addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
		}
		
		override public function Move():void
		{
			if (colorTransform.redMultiplier > 1.0)
			{
				colorTransform.redMultiplier -= 0.1;
				colorTransform.greenMultiplier -= 0.1;
				colorTransform.blueMultiplier -= 0.1;
			}
			super.Move();
		}
		
		private function onMouseDown(e:MouseEvent):void
		{
			(parent as GameMain).sun.Fire(position, this);
		}
		
		public function Hit(val:Number):void
		{
			colorTransform.redMultiplier = 1.5;
			colorTransform.greenMultiplier = 1.5;
			colorTransform.blueMultiplier = 1.5;
			
			_healhPoints -= val;
			if (_healhPoints < 0)
			{
				setState(STATE_DIENG);
				_healhPoints = 0;
				_explosionSound.play();
			}
		}
		
		public function setState(newState:int):void
		{
			_state = newState;
		}
		
		public function get state():int
		{
			return _state;
		}
		
		public function get healhPoints():Number
		{
			return _healhPoints;
		}
	
	}

}