//---------------------------------------------------------------------------------------------
//
//	Chromatic Wing Mod
//	
//	Power variable setting / declare
//
//	Type
//	0	= Score
//	1	= Point
//	2	= 1UP
//	3	= Power (Small) +5
//	4	= Power (Large) +50
//	5	= Power (Perfect) +100
//	6	= Fever
//	
//---------------------------------------------------------------------------------------------

script_enemy_main
{

	let SY_ItemImg = GetCurrentScriptDirectory~"..\img\system_item.png";
	let SY_ItemX1 = 0;
	let SY_ItemX2 = 0;
	let SY_ItemSpeed = 3.05;
	let SY_ItemType = GetArgument();
	let SY_ItemCollect = 0;

//---------------------------------------------------------------------------------

	@Initialize
	{
		SetLife(1000000);
		SetAngle(270);
		SetSpeed(3.05);
		LoadGraphic(SY_ItemImg);
	}
	
//---------------------------------------------------------------------------------

	@MainLoop
	{
	// Either power max or bombing, consume item
	if ((OnBomb()) || (GetPlayerY <= GetCommonDataDefault("CD_ItemCollectLine",150)))
		{
		SY_ItemCollect = 1;
		}
	else
		{
		SY_ItemCollect = 0;
		}

	if (SY_ItemCollect == 1)
		{
		SetAngle(GetAngleToPlayer());
		SetSpeed(8);
		}
	else 
		{
		SetAngle(270);
		if (SY_ItemSpeed > 3.05)	{	SY_ItemSpeed = 3.05;	}
		SetSpeed(SY_ItemSpeed);
		SY_ItemSpeed -= 0.05;
		if (SY_ItemSpeed <= -2.5)
			{
			SY_ItemSpeed = -2.5;
			}
		// Crab! I got hit and it fall TAT
		if (OnPlayerMissed())
			{
			SetAngle(270);
			SetSpeed(-2.5);
			}
		}





	// Fever will get delete when cast bomb
	if ((SY_ItemType == 6) && (OnBomb())) {	VanishEnemy();	}

	// If you close to, drain in
	if ((GetX()>GetPlayerX()-45) && (GetX()<GetPlayerX()+45) && (GetY()>GetPlayerY()-45) && (GetY()<GetPlayerY()+45) && (OnPlayerMissed == false))
		{
		SetAngle(GetAngleToPlayer());
		SetSpeed(6);
		}

	// Pick it up and delete it
	if ((GetX() > GetPlayerX()-16) && (GetX()<GetPlayerX()+16) && (GetY()>GetPlayerY()-16) && (GetY()<GetPlayerY()+16))
		{
				if (SY_ItemType == 0)
				{
				SetCommonData("CD_Feverscore", GetCommonDataDefault("CD_Feverscore",0) + 250);
				AddScore(2500 * GetCommonDataDefault("CD_FeverMultiplyUse",1));
				PlaySE(GetCurrentScriptDirectory~"..\sfx\se_item00.wav");
				}
				else if (SY_ItemType == 1)
				{
				SetCommonData("CD_Feverscore", GetCommonDataDefault("CD_Feverscore",0) + 750);
				AddPoint(1);
				AddScore(1000 * GetCommonDataDefault("CD_FeverMultiplyUse",1));
				PlaySE(GetCurrentScriptDirectory~"..\sfx\se_item00.wav");
				}
				else if (SY_ItemType == 2)
				{
				SetCommonData("CD_Feverscore", GetCommonDataDefault("CD_Feverscore",0) + 5000);
				ExtendPlayer(1);
				AddScore(25000 * GetCommonDataDefault("CD_FeverMultiplyUse",1));
				PlaySE(GetCurrentScriptDirectory~"..\sfx\se_extend.wav");
				}
				else if (SY_ItemType == 3)
				{
				SetCommonData("CD_Feverscore", GetCommonDataDefault("CD_Feverscore",0) + 500);
				SetCommonData("CD_Power", GetCommonDataDefault("CD_Power",0) + 5);
				AddScore(2500 * GetCommonDataDefault("CD_FeverMultiplyUse",1));
				PlaySE(GetCurrentScriptDirectory~"..\sfx\se_item00.wav");
				}
				else if (SY_ItemType == 4)
				{
				SetCommonData("CD_Feverscore", GetCommonDataDefault("CD_Feverscore",0) + 1000);
				SetCommonData("CD_Power", GetCommonDataDefault("CD_Power",0) + 50);
				AddScore(5000 * GetCommonDataDefault("CD_FeverMultiplyUse",1));
				PlaySE(GetCurrentScriptDirectory~"..\sfx\se_item00.wav");
				}
				else if (SY_ItemType == 5)
				{
				SetCommonData("CD_Feverscore", GetCommonDataDefault("CD_Feverscore",0) + 5000);
				SetCommonData("CD_Power", GetCommonDataDefault("CD_Power",0) + 100);
				AddScore(25000 * GetCommonDataDefault("CD_FeverMultiplyUse",1));
				PlaySE(GetCurrentScriptDirectory~"..\sfx\se_powerup.wav");
				}
				else if (SY_ItemType == 6)
				{
				SetCommonData("CD_Feverscore", GetCommonDataDefault("CD_Feverscore",0) + 10000);
				AddScore(50000 * GetCommonDataDefault("CD_FeverMultiplyUse",1));
				PlaySE(GetCurrentScriptDirectory~"..\sfx\se_ok00.wav");
				}
		VanishEnemy();
		}

	// Float away~ WAITTTTTTTTTT
	if ((GetY() >= GetClipMaxY+30) || (GetX() >= GetClipMaxX+50) || (GetX() <= GetClipMinX-50))
		{
		VanishEnemy();
		}


	yield;
	}
	
//---------------------------------------------------------------------------------

	@Finalize
	{
	}
	
//---------------------------------------------------------------------------------

	@DrawLoop
	{
		SetTexture(SY_ItemImg);
		SetColor(255,255,255);
		SetRenderState(ALPHA);
		SetAlpha(255);

		alternative(SY_ItemType)
		case(0)	{	SY_ItemX1 = 1;	SY_ItemX2 = 17;	}
		case(1)	{	SY_ItemX1 = 18;	SY_ItemX2 = 34;	}
		case(2)	{	SY_ItemX1 = 35;	SY_ItemX2 = 51;	}
		case(3)	{	SY_ItemX1 = 52;	SY_ItemX2 = 68;	}
		case(4)	{	SY_ItemX1 = 69;	SY_ItemX2 = 85;	}
		case(5)	{	SY_ItemX1 = 86;	SY_ItemX2 = 102;	}
		case(6)	{	SY_ItemX1 = 103;	SY_ItemX2 = 119;	}

   		SetGraphicRect(SY_ItemX1, 0, SY_ItemX2, 17);
		DrawGraphic(GetX(),GetY());
	}

//---------------------------------------------------------------------------------

}
