#include "HitBox.h"

HitBox::HitBox()
{
  shape.assign("Circle");
  wasHit=false;
  size.clear();
  size.push_back(0);
}

HitBox::~HitBox()
{
  shape.clear();
  size.clear();
}

//sets up position
void HitBox::setPosition (int x, int y)
{
  posX=x; posY=y;
}

//accesses wasHit
bool HitBox::getWasHit ()
{
  return wasHit;
}

//position: The center of where the HitBox was placed.
int HitBox::getPosX ()
{
  return posX;
}

int HitBox::getPosY ()
{
  return posY;
}

//position where the HitBox was hit
int HitBox::getWasHitX ()
{
  return wasHitX;
}

int HitBox::getWasHitY ()
{
  return wasHitY;
}

//button used to hit
int HitBox::getWasHitMouseButton()
{
  return wasHitMouseButton;
}

//sees if it was hit
bool HitBox::wasHitBoxHit(int mouseX, int mouseY, int mouseButton)
{
  //clear previous hit check
  wasHit=false;

  //do relative position math
  wasHitX=mouseX-posX; wasHitY=mouseY-posY; wasHitMouseButton=mouseButton;

  //check according to shape
  if (shape=="Rectangle")
    wasHit=pointRectangleCollision(mouseX, mouseY,
                                   posX-(size[0]/2),
                                   posX+(size[0]/2),
                                   posY-(size[1]/2),
                                   posY+(size[1]/2));

  if (shape=="Circle")
    wasHit=pointCircleCollision(mouseX, mouseY, posX, posY, size[0]);

  return wasHit;
}

//sets the shape.
void HitBox::setShape (const string & shapeType, vector <int> & shapeInfo)
{
  if (shapeType=="Circle")
    {
      shape="Circle";
      size.resize(1);
      if (shapeInfo.size() > 0)
        size[0]=shapeInfo[0];
      else
        size[0]=0;
      return;
    }

  if (shapeType=="Rectangle")
    {
      shape="Rectangle";
      size.resize(2);
      if (shapeInfo.size() > 1)
        {
          size[0]=shapeInfo[0];
          size[1]=shapeInfo[1];
        }
      else
        {
          size[0]=0;
          size[1]=0;
        }
      return;
    }
}

//get Shape information
void HitBox::getShape (string & shap, vector <int> & info)
{
  shap=shape;
  info=size;
}

//clears wasHit
void HitBox::clearWasHit()
{
  wasHit=false;
}

//get radius, assuming it's a circle hitbox
int HitBox::getRadius()
{
  if (shape=="Circle")
    return size[0];
  return 0;
}
