#include "Entity.h"
#include "GameLogic.h"

int Entity::m_nextID = 1; //start 'em off here

Entity::Entity()
{
  m_ID = m_nextID++;
  SetDeleteFlag(false);
  m_vScale = CL_Vector2(1,1);
  m_vVelocity = CL_Vector2(0,0);
  m_vPosition = CL_Vector2(0,0);
  m_vHeading = CL_Vector2(0, -1);
  m_sort = 1000;
  m_radius = 10;
  m_bScaleToNothing = false;
  m_bScaleUp = false;
  m_bFadeAlphaTo = false;
  m_alphaTarget = 0;
  m_alpha = 1;
  m_alphaFadeSpeed = 0.05f;

}

Entity::~Entity()
{
    if (GetGameLogic->ShuttingDown() == false)
    GetGameLogic->GetMessageDispatcher()->KillAllMessagesToThisEnt(this);
}

void Entity::Update(float step)
{
    if (m_bScaleToNothing)
    {
        m_vScale.x = LerpFloat(m_vScale.x, 0, 0.05f * step);
        m_vScale.y = LerpFloat(m_vScale.y, 0, 0.05f* step);
    }


    if (m_bScaleUp)
    {
        m_vScale.x = LerpFloat(m_vScale.x, 3, 0.05f * step);
        m_vScale.y = LerpFloat(m_vScale.y, 3, 0.05f * step);

    }
  
    if (m_bFadeAlphaTo)
    {
       m_alpha = LerpFloat(m_alpha, m_alphaTarget, m_alphaFadeSpeed * step);
    }

}

void Entity::OnMessage(Message &msg)
{

    switch(msg.msg)
    {
    case C_MESSAGE_KILL_ENTITY:

        SetDeleteFlag(true);
        break;
    }
}