//@STATE=嶌惉拞
//@DESCRIPTION ---------------------------------------------------------------
// StartImpl.cpp: StartImpl 僋儔僗偺僀儞僾儕儊儞僥乕僔儑儞
// $Log: StartImpl.cpp,v $
// Revision 1.1  2001/10/28 21:40:37  fujiwara
// DLL偵暘妱
//
// Revision 1.5  2001/07/09 20:30:10  fujiwara
// 椺奜張棟偺慻傒崬傒
//
// Revision 1.4  2001/07/01 21:30:34  fujiwara
// 儊儌儕儕乕僋僠僃僢僋尒捈偟
//
// Revision 1.3  2001/07/01 01:03:44  fujiwara
// const 偺尒捈偟
// 攝抲僄僨傿僞偼搑拞宱夁
//
// Revision 1.2  2001/05/12 00:48:55  fujiwara
// 俠倁俽傪摫擖偟丄儘僌昞帵傪捛壛
//
//@DESCRIPTION_END -----------------------------------------------------------
//@AUTHOR=S.F.
// Copyright (C) 2000 Satoshi Fujiwara. All Rights Reserved.
#pragma warning( disable : 4786 )	//STL偺寈崘奜偟
// 儊儌儕乕儕乕僋専弌梡
// 儊儌儕乕儕乕僋専弌梡
#include "sfdebug.h"


#include <stack>
#include <list>
#include <vector>
#include <map>

#include "exception.h"
#include "system.h"
#include "sound.h"
#include "console.h"
#include "Obj.h"
#include "Obj2D.h"
#include "ObjRectangle.h"
#include "ObjQuadrangle.h"
#include "input.h"
#include "Scene.h"
#include "s2001.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

#include "main.h"
#include "fade.h" //僼僃乕僪僀儞丄僼僃乕僪傾僂僩僔乕儞
#include "AbstractScene.h"
#include "StartImpl.h"

//////////////////////////////////////////////////////////////////////
// 峔抸/徚柵
//////////////////////////////////////////////////////////////////////
using namespace sf::application::scene;


const int StartImpl::PERIOD = 1000 / sf::system::TIMER_INTERVAL * 3;
const char StartImpl::BGM_FILENAME[sf::system::MAX_PATH_] = "select.sgt";

StartImpl::StartImpl()
{
	mTimer = PERIOD;
	mTimer1 = 0;
	mState = INITIALIZE;
	mpScene = NULL;
}// StartImpl()

StartImpl::~StartImpl()
{
	if(mpScene)
		delete mpScene;
}// ~StartImpl()

// 僗働僕儏乕儔 ---------------------------------------------------------------
void StartImpl::move(void)
{
	switch(mState)
	{
	case INITIALIZE:
		initialize();
		return;
	case FADE_IN:
		fadeIn();
		return;
	case MAIN:
		main();
		return;
	}
}// move()

// 弶婜壔 --------------------------------------------------------------------
void StartImpl::initialize()
{
	Fade* pfade;

	mpSound->load(0,BGM_FILENAME);

	mState = MAIN;
	
	// 僼僃乕僪僀儞愝掕	
	mpScene = scene::createScene(FADE);
	mpScene->addListener(this);

	// 僼僃乕僪僆僽僕僃僋僩屌桳懏惈偵傾僋僙僗
	pfade = dynamic_cast<Fade *>(mpScene);
	pfade->startColor(0xff000000);
	pfade->endColor(0x00000000);
	pfade->speed(0.05f);
	pfade->fadeType(Fade::FADE_IN);
	pfade->fadeVolumeFlag(false);

	mState = FADE_IN;
	sleep();
}// intialize()

//丂儊僀儞 亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅
bool StartImpl::main()
{
	mTimer --;
	
	if(mpInput->exit(true))
	{
		exitKeyPressed(this);
		return true;
//		return end();
	}

	if(!mTimer){
		return end();
	}

//	mpMain->printPlayerInfo();
	printMessage();
	
	return true;
}// main()

//丂廔椆張棟丂亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅
bool StartImpl::end()
{
	callSceneEvent(&Listener::endOfScene);
	delete this;
	return true;
}// end()

// 僼僃乕僪僀儞 亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅
bool StartImpl::fadeIn()
{
	printMessage();	
	return true;
}// fadeIn()

// 僼僃乕僪僀儞偺廔椆 亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅
void StartImpl::endOfScene(Scene *pScene)
{
	switch(mState)
	{
	case FADE_IN:
		// BGM 墘憈奐巒
		active();
		mpSound->play(0,1,true,true);
		mState = MAIN;
		mpScene = NULL;
		break;
	}
}// endOfScene()

// 僼僃乕僪僀儞拞偵俤倃俬俿僉乕偑墴偝傟偨両亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅
void StartImpl::exitKeyPressed(Scene *pScene)
{
	callSceneEvent(&Listener::exitKeyPressed);
	delete this;
}// exitKeyPressed()

// 僗僞乕僩儊僢僙乕僕偺昞帵 亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅亅
void StartImpl::printMessage()
{
	using namespace sf::system::console;

	mTimer1 ++;

	// 僗僞乕僩暥帤楍傪僽儕儞僋昞帵
	if(mTimer1 & 0x8)
	{
		mpConsole->print(
			0,
			viewport::X + viewport::WIDTH / 2.0f - 12.0f / 2.0f * text::COLUMN_PITCH,
			viewport::Y + viewport::HEIGHT / 8.0f,
			0.0f,
			1.0f,
			0xffffffff,
			"Game StartImpl!!");
	}

}// printMessage()
