#include "explosion.h"

void CExplosion::Init(IMovableEntity* entity, CSprite* sprite)
{
    m_X = entity->m_X;
    m_Y = entity->m_Y;
    m_XVel = entity->m_XVel/2;
    m_YVel = entity->m_YVel/2;
    m_Sprite = sprite;
    m_Sprite->m_PlayOnce = true;
}

void CExplosion::Update( int deltaT )
{
    float newDest = m_X + m_XVel * ((deltaT)/1000.f);
    if (newDest > 0 && newDest < (640 - m_Sprite->m_DestRect.w))
        m_X = newDest;

    newDest = m_Y + m_YVel * ((deltaT)/1000.f);
    if (newDest > 0 && newDest < (480 - m_Sprite->m_DestRect.h))
        m_Y = newDest;

    m_Sprite->m_X = m_X;
    m_Sprite->m_Y = m_Y;
    m_Sprite->Update( deltaT );

    if (m_Sprite->m_NumOfLoops >= 1)
        m_Alive = false;
}

void CExplosion::Draw( SDL_Surface* screen )
{
    if (m_Alive)
        m_Sprite->Draw( screen );
}
