#include	"StateStart.h"

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

// constructor
// main initialization of CStartGame.
// create text for displaying 'start game'
// load and play music.
CStateStart::CStateStart() : CGameState(EGS_Start)
{
	m_iStartTxtID = agk::CreateText("START GAME");
	agk::SetTextPosition(m_iStartTxtID, 100, 160);
	agk::SetTextSize(m_iStartTxtID, 40);
	agk::FixTextToScreen(m_iStartTxtID, 1);
	agk::SetTextColorAlpha(m_iStartTxtID, 0);
	agk::SetTextVisible(m_iStartTxtID, 0);

	m_iTrack1MsxID = agk::LoadMusic("space/track1.mp3");
	agk::SetMusicSystemVolume(70);
	agk::PlayMusic				(m_iTrack1MsxID, 1);
}

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

// Run is called in each frame for the processing of the 'start-game' loop. 
// Lets the text flashing and waiting for a click to change the 'game-state'.
EGameState CStateStart::Run(float fFrameTime)
{
	static int	add = 4;
	UINT		alpha = agk::GetTextColorAlpha(m_iStartTxtID);

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

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

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

	// wait for input
	if (agk::GetPointerPressed() == 1)
	{
		// reset aliens
		m_refAliens->ResetAliens();

		// hide 'start game' text
		agk::SetTextColorAlpha(m_iStartTxtID, 0);
		agk::SetTextVisible(m_iStartTxtID, 0);

		// switch to in game state
		return EGS_Play;
	}

	return m_eState;
}

// reset the text.
// hide text
void CStateStart::Reset()
{
	agk::SetTextColorAlpha(m_iStartTxtID, 0);
	agk::SetTextVisible(m_iStartTxtID, 0);

	agk::SetViewOffset(0, 0);
}
