#東方弾幕風[Single]
#ScriptVersion[3]
#Title["星符「ミッドナイトレヴァリエ」"]
#Text["Exルーミア最初のスペルカード：[r]星符「ミッドナイトレヴァリエ」"]
#Image["./ExRumia(星符「ミッドナイトレヴァリエ」).jpg"]
#Background["script/default_system/Default_Background_IceMountain.txt"]
#BGM[DEFAULT]
#Player[DEFAULT]

#include"script/default_system/Default_ShotConst.txt"
#include"script/default_system/Default_Effect.txt"

let objEnemy;
let bConcentrationMotion = false;
@Initialize
{
	objEnemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objEnemy);
	ObjEnemy_SetDamageRate(objEnemy, 10, 10);//披ダメージを10%に設定
	TWork;
	TRender;
	TEnd;

	DeleteShotAll(TYPE_ALL, TYPE_ITEM);//出現と同時に敵弾を全て削除	
}

@MainLoop
{
	let ex = ObjMove_GetX(objEnemy);
	let ey = ObjMove_GetY(objEnemy);
	ObjEnemy_SetIntersectionCircleToShot(objEnemy, ex, ey, 40);//当たり判定(自弾)登録
	ObjEnemy_SetIntersectionCircleToPlayer(objEnemy, ex, ey, 20);//当たり判定(体当たり)登録


	yield;
}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
	{
		SetScriptResult(300);//ライフを1500に設定
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(60);//時間制限を60秒に設定
	}
	case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(30000);//スペルカードボーナスを30000に設定
	}
}

//----------------------------------------------------
//敵動作
//----------------------------------------------------
task TWork
{
//	Concentration01(150);
//	CutIn(YOUMU,"星符「ミッドナイトレヴァリエ」",0,0,0,0,0);//スペルカード名表示

	//座標(cx, 60)へ60フレームかけて移動する
	let cx = GetStgFrameWidth() / 2;//STGシーンの中心x座標を取得
	ObjMove_SetDestAtFrame(objEnemy, cx, 60, 60);
	loop(60){yield;}

	let objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);

	while(!Obj_IsDeleted(objEnemy))
	{
		loop(90){yield;}
		TShotBlue(29, 130);
		TShotBlue(180, 65);

		loop(160){yield;}
		TShotRed(0, 90);
		TShotRed(180, 90);

		loop(50){yield;}
		bConcentrationMotion = true;

		loop(100){yield;}
		bConcentrationMotion = false;
	}
}

//----------------------------------------------------
//描画タスク
//----------------------------------------------------
task TRender
{
	let imgExRumia = GetCurrentScriptDirectory~"ExRumia.png";
	ObjPrim_SetTexture(objEnemy, imgExRumia);

	while(!Obj_IsDeleted(objEnemy))
	{
		let angle = ObjMove_GetAngle(objEnemy);
		let speed = ObjMove_GetSpeed(objEnemy);
		if(speed == 0)
		{
			if(bConcentrationMotion)
			{
				ObjSprite2D_SetSourceRect(objEnemy, 64, 1, 127, 64);
			}
			else
			{
				ObjSprite2D_SetSourceRect(objEnemy, 1, 1, 64, 64);
			}
		}
		else if(cos(angle) > 0){ObjSprite2D_SetSourceRect(objEnemy, 192, 1, 255, 64);}
		else if(cos(angle) < 0){ObjSprite2D_SetSourceRect(objEnemy, 128 ,1, 191, 64);}
		ObjSprite2D_SetDestCenter(objEnemy);

		yield;
	}

}

//----------------------------------------------------
//弾関連
//----------------------------------------------------
task TShotBlue(angle1, angle2)
{
	let ex = ObjMove_GetX(objEnemy);
	let ey = ObjMove_GetY(objEnemy);
	let obj = CreateShotA2(ex, ey, 5, angle1, -0.08, 0, DS_BALL_L_BLUE, 0);//弾を発射
	ObjMove_AddPatternA1(obj, 60, 5, angle2);

	loop(60){yield;}

	ascent(i in 0 .. 300)
	{
		if(Obj_IsDeleted(obj)){break;}
		let shotSpeed = rand(0.5,1.5);
		let sx = ObjMove_GetX(obj);
		let sy = ObjMove_GetY(obj);
		CreateShotA1(sx, sy, rand(0.5,1.5), rand(0,360), DS_BALL_S_BLUE, 60);
		yield;
	}
}

task TShotRed(angle1, angle2)
{
	let ex = ObjMove_GetX(objEnemy);
	let ey = ObjMove_GetY(objEnemy);
	let obj = CreateShotA2(ex, ey, 5, angle1, -0.08, 0, DS_BALL_L_RED, 0);//弾を発射
	ObjMove_AddPatternA1(obj, 60, 5, angle2);

	loop(60){yield;}

	ascent(i in 0 .. 300)
	{
		if(Obj_IsDeleted(obj)){break;}
		let shotSpeed=rand(0.5,1.5);
		let sx = ObjMove_GetX(obj);
		let sy = ObjMove_GetY(obj);
		CreateShotA1(sx, sy, rand(0.5,1.5), rand(0,360), DS_BALL_S_RED, 60);
		yield;
	}
}

//----------------------------------------------------
//終了待機タスク
//----------------------------------------------------
task TEnd
{
	while(ObjEnemy_GetInfo(objEnemy, INFO_LIFE) > 0)
	{
		yield;
	}

	let ex = ObjMove_GetX(objEnemy);
	let ey = ObjMove_GetY(objEnemy);
	TExplosionA(ex, ey, 10, 0.6);
	DeleteShotAll(TYPE_ALL, TYPE_ITEM);//敵弾を全て削除	
	Obj_Delete(objEnemy);

	loop(30){yield;}

	CloseScript(GetOwnScriptID());
}
