#include	"StateEnd.h"

#include	"Common.h"
#include	"ppAliens.h"

// constructor
// create text for displaying 'game-over'
CStateEnd::CStateEnd() : CGameState(EGS_End)
{
	m_iGameOverTxtID = agk::CreateText("GAME OVER");
	agk::SetTextPosition(m_iGameOverTxtID, 130, 160);
	agk::SetTextSize(m_iGameOverTxtID, 40);
	agk::FixTextToScreen(m_iGameOverTxtID, 1);
	agk::SetTextColorAlpha(m_iGameOverTxtID, 0);
	agk::SetTextVisible(m_iGameOverTxtID, 0);
}

// destructor
CStateEnd::~CStateEnd()
{
}

// Run is called in each frame for the processing of the 'end-game' loop.
// displaying and flashing text 'game-over', wait for click to change 
// the state to 'start-state'.
EGameState CStateEnd::Run(float fFrameTime)
{
	// handle the end of the game
	static int	add = 4;
	UINT		alpha = agk::GetTextColorAlpha(m_iGameOverTxtID);

	if (alpha == 255 || (alpha < 32 && add < 0))
		add = -add;

	agk::SetTextColorAlpha(m_iGameOverTxtID, alpha + add);
	agk::SetTextVisible(m_iGameOverTxtID, 1);

	// have aliens moving across
	m_refAliens->UpdateAliens();

	// act on input
	if (agk::GetPointerPressed())
	{
		// reset scrolling
		agk::SetTextColorAlpha(m_iGameOverTxtID, 0);
		agk::SetTextVisible(m_iGameOverTxtID, 0);

		return EGS_Start;
	}

	return m_eState;
}

// reset state. hide text 'game-over'
void CStateEnd::Reset()
{
	agk::SetTextColorAlpha(m_iGameOverTxtID, 0);
	agk::SetTextVisible(m_iGameOverTxtID, 0);
}
