//the person class inherits the object class to give it all of the functonality
//of a character in the game. The person class is designed specifically to
//be a player-controlled object
class person : public object
	{
     private:
     	BITMAP *port;
        int keys;     //# of keys he holds
        int level;    //player's current level
        int lives;    //number of lives left
     public:

     	void init2(int n, int reset_lives);
     	void set_port(BITMAP *p);//sets protrate picture
        void draw_port(BITMAP *backgr, int xx, int yy); //draws portrate picture
        void draw_life(BITMAP *backgr, int x, int y); //draws life circle

        //checks to see if it's hit by a shot, and looses life appropratly
        void check_hit(object *enim);

        //draws the amount of left in the current gun
        void draw_ammo(BITMAP *backgr, int x, int y, FONT *f);
        void life_up(int n);    //increases life by n amount
        void die(void);
        void draw_keys(BITMAP *backgr, BITMAP *key, int x, int y);
        void up_keys(void);
        void down_keys(void);
        int ret_keys(void);
        void next_level(void);
        int ret_level(void);
        void set_level(int n);
        void move_to(float xx, float yy);
        int ret_lives(void);
        int lives_down(void);
        void check_die(void);

	};

void person::check_die(void)
	{
    if(life<=0)
       die();
    }

int person::lives_down(void)
	{
     lives--;
    }

int person::ret_lives(void)
	{
	return lives;
    }

void person::set_level(int n)
	{
     level=n;
    }

void person::move_to(float xx, float yy)
	{
     //move player to xx,yy and also adjust the screen position
     x=xx;
     y=yy;
   //  screen_x=x-320;
     screen_y=y-240;

     if(screen_x<0)
       screen_x=0;
     if(screen_y<0)
       screen_y=0;
    }

int person::ret_level(void)
	{
     return level;
    }

void person::next_level(void)
	{
     level++;
    }

void person::down_keys(void)
	{
     if(key>0)
     	keys--;
    }

int person::ret_keys(void)
	{
     return keys;
    }

void person::up_keys(void) //increase the player's keys
	{
     keys++;
    }

void person::draw_keys(BITMAP *backgr, BITMAP *key, int x, int y)
	{
     for(int n=0; n<keys ; n++)
        {
         draw_sprite(backgr,key,x+2+(n*key->w),y);
        }
     }

void person::die(void)
	{
     //lives--;
     if(lives>0)
       {
     	level=-1;  //level of -1 means the player lost a life
       }
     else if(lives<=0)
       {
        level=-2;  //level of -2 means the player lost all lives (go to menu
       }
     }

void person::life_up(int n)
	{
     life+=n;
     if(life>256)
       life=256;
    }

void person::draw_ammo(BITMAP *backgr, int x, int y, FONT *f)
	{
    if(gun[wep].send_ammo()>0)
    	textprintf(backgr,f,x,y,136,"%5d",gun[wep].send_ammo());
    else if(gun[wep].send_ammo()==0)
    	textprintf(backgr,f,x,y,136,"Empty");
    else if(gun[wep].send_ammo()==-1)
    	textprintf(backgr,f,x,y,136,"Unlimited");
	}

void person::check_hit(object *enim)
	{
     //passes the current player as a pointer to the enemy passed to it in
     //a function to check to see if any of the enemy projectiles hit.
     //the check_proj_col function returns the ammount of damage done
     //by any projectile hitting the player, returns 0 is nothing hits
	 int damage=enim->check_proj_col(this);
     if(damage>0)
       {
        life-=damage;
       }
     if(life<=0)
       die();


    //screen_x+=.5;
    
    
    }

void person::init2(int n,  int reset_lives)
	{
     life=256;
     keys=0;
     level=n;

     //reset the value for the background scrolling
     p_x=0;
     p_y=0;
     p_x2=0;
     p_y2=0;

     if(reset_lives==1) //only reset live to three if 'reset_lives==1'
     	lives=3;
    }

void person::draw_life(BITMAP *backgr, int x, int y)
	{
      circlefill(backgr,x,y,20,0);

      //goes through all the points of the circle in the array
      for(int a=256-life ; a<256 ; a++)
        {
         //and draws a line from the centre to the current point
         line(backgr,x,y,x+(int)circle_points[a].x,
              y+(int)circle_points[a].y,
              circle_points[a].c);
        }
      circle(backgr,x,y,20,136);  //outline
    }

void person:: set_port(BITMAP *p)
	{
     port=p;
    }
void person::draw_port(BITMAP *backgr, int xx, int yy)//draws the player's portrate
	{
     draw_sprite(backgr,port,xx,yy);
    }
