package com.Tutorial
{
    import com.adamatomic.flixel.*;
    
    public class Player extends FlxSprite
    {
        [Embed(source='../../data/Player.png')] private var ImgPlayer:Class;
        
        private var _move_speed:int = 1000;
        private var _jump_power:int = 800;   
        private var _max_health:int = 10;
        private var _hurt_counter:Number = 0;
		public var dir:int = 0;
		
        public function Player(X:Number,Y:Number):void
        {
            super(ImgPlayer, X, Y, true, true);//Max speeds
            maxVelocity.x = 30;
            maxVelocity.y = 30;
            //Set the player health
            health = 10;
            //Gravity
            acceleration.y = 0;            
            //Friction
            drag.x = 800;
            drag.y = 800;
            //bounding box tweaks
            width = 13;
            height = 18;
            offset.x = 4;
            offset.y = 2;
			addAnimation("0", [0]);
            addAnimation("1", [1]);
			play("0");		
			dir = 1;
        }
    
        override public function update():void
        {

            if(dead)
            {
                if(finished) exists = false;
                else
                    super.update();
                return;
            }
            if (_hurt_counter > 0)
            {
                _hurt_counter -= FlxG.elapsed*3;
            }

            if(FlxG.kLeft)
            {
                velocity.x -= _move_speed * FlxG.elapsed;
				facing = false;
				play("0", true);
				dir = 2;
            }
            if (FlxG.kRight)
            {
                velocity.x += _move_speed * FlxG.elapsed;  
				facing = true;              
				play("0", true);
				dir = 3;
            }
			if (FlxG.kUp)
			{
				velocity.y -= _move_speed * FlxG.elapsed;
				play("1", true);
				dir = 0;
			}
			if (FlxG.kDown)
			{
				velocity.y += _move_speed * FlxG.elapsed;
				play("0", true);
				dir = 1;
			}
            super.update();
        }

        override public function hurt(Damage:Number):void
        {
            _hurt_counter = 1;
            return super.hurt(Damage);
        }       
    }
}