#include "EntLightBeam.h"
#include "GameLogic.h"

EntLightBeam::EntLightBeam()
{
    m_Image = NULL;
    m_vPosition.x = GetScreenX/2;
    m_vPosition.y = GetScreenY/2;
    SetSort(2000); //draw after most things

    Init();

    m_alphaTarget = m_alpha = 0;
    m_bFadeAlphaTo = true;
    m_alphaFadeSpeed = 0.01f;

}

EntLightBeam::~EntLightBeam()
{
    SAFE_DELETE(m_Image);
}

bool EntLightBeam::Init()
{
    //setup stuff
    m_Image = new CL_OpenGLSurface("lightbeam", GetApp()->GetResourceManager());
    m_Image->set_rotation_hotspot(origin_center);
    m_Image->set_alignment(origin_center);
    return true; //success
}


void EntLightBeam::Render()
{
    m_Image->set_alpha(m_alpha);

    m_Image->draw(m_vPosition.x, m_vPosition.y);
}

void EntLightBeam::OnMessage(Message &msg)
{

    switch (msg.msg)
    {
    case C_MESSAGE_START_NIGHT:
        m_alphaTarget = 1;

        break;


    case C_MESSAGE_START_DAY:
        m_alphaTarget = 0;
        
        break;

    }

    Entity::OnMessage(msg);
}


void EntLightBeam::Update(float step)
{
    Entity::Update(step);
        
    m_Image->set_angle(m_Image->get_angle()+ (GetGameLogic->m_lightHouseSpeed*step));
    m_Image->set_scale(GetGameLogic->m_beamScale, GetGameLogic->m_beamScale);
    

}
