
#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"

#include"./../../img/boss/lib_anime_Medicine.txt"
#include"./../../lib/BossCommon/BossCommon.txt"

@Initialize
{
	BossInit(384,128);
}

@MainLoop
{
	let ex = ObjMove_GetX(objEnemy);
	let ey = ObjMove_GetY(objEnemy);
	ObjEnemy_SetIntersectionCircleToShot(objEnemy, ex, ey, 32);//当たり判定(自弾)登録
	ObjEnemy_SetIntersectionCircleToPlayer(objEnemy, ex, ey, 12);//当たり判定(体当たり)登録
	SetCommonData("BossPosition",[ex,ey]);
	yield;
}

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

//----------------------------------------------------
//敵動作
//----------------------------------------------------
task BossWork
{
	let PlayerSpeedH=0;
	let PlayerSpeedL=0;
	if(GetCommonData("PlayerCharacter",0)==0)
	{
		PlayerSpeedH=4.0;
		PlayerSpeedL=1.5;
	}
	else
	{
		PlayerSpeedH=5.0;
		PlayerSpeedL=2.0;
	}
	//座標(cx, 60)へ60フレームかけて移動する
	let cx = GetStgFrameWidth() / 2;//STGシーンの中心x座標を取得
	ObjMove_SetDestAtWeight(objEnemy, cx, 112, 10,5);
	SetAction(ACT_MOVE, 75);
	CallSpellCard("「ポイズンフェザー」");

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

	wait(75);
	SetAction(ACT_SHOT_A, 7500);
	feather;
	wait(10);
	feather;
	wait(90);

	Shoot;
	wait(210);		
	Poison;
	DamageRate=[100,100];

	task Poison
	{
		let time;
		loop
		{
			time=330-300*(GetLife/5000);
			Shot(rand(0,416),448,rand(0.5,1),270);
			PoisonEffect(rand(0,416),480-rand(time/2,time));
			if(GetPlayerY>=480-time)
			{
				SetPlayerSpeed(PlayerSpeedH/2,PlayerSpeedL/2);
			}
			else
			{
				SetPlayerSpeed(PlayerSpeedH,PlayerSpeedL);
			}
			if(GetLife<=0){SetPlayerSpeed(PlayerSpeedH,PlayerSpeedL);break;}
			wait(1);
		}
		task Shot(x,y,speed,angle)
		{
				let obj = ObjShot_Create(OBJ_SHOT);
				ObjShot_Regist(obj);
				ObjMove_SetPosition(obj, x, y);
			//	ObjMove_SetSpeed(obj, speed);
			//	ObjMove_SetAngle(obj, angle);
				ObjShot_SetGraphic(obj, DS_BALL_S_PURPLE);

				ObjShot_SetIntersectionEnable(obj,false);
				ObjRender_SetAlpha(obj,150);
				ObjRender_SetColor(obj,50,50,50);
				loop(time)
				{
					ObjShot_SetDelay(obj, 15);
					ObjRender_SetX(obj,ObjRender_GetX(obj)+speed*cos(angle));
					ObjRender_SetY(obj,ObjRender_GetY(obj)+speed*sin(angle));
					yield;
				}
				Obj_Delete(obj);
		}
		task PoisonEffect(x,y)
		{
				let obj = ObjShot_Create(OBJ_SHOT);
				ObjShot_Regist(obj);
				ObjMove_SetPosition(obj, x, y);
			//	ObjMove_SetSpeed(obj, speed);
			//	ObjMove_SetAngle(obj, angle);
				ObjShot_SetGraphic(obj, DS_BALL_S_PURPLE);
				ObjShot_SetDelay(obj, 30);
				ObjShot_SetIntersectionEnable(obj,false);
				ObjRender_SetAlpha(obj,0);
				loop(30)
				{
					yield;
				}
				Obj_Delete(obj);
		}
	}
	task Shoot
	{
		loop
		{
			CreateShotA1(rand(GetStgFrameWidth()/2-24,448),rand(-64,-32),rand(1,3),rand(90,110),DS_BALL_S_PURPLE,5);
			CreateShotA1(rand(GetStgFrameWidth()/2+24,-32),rand(-64,-32),rand(1,3),rand(90,70),DS_BALL_S_PURPLE,5);
			wait(4);
		}
	}
	task feather
	{
		loop
		{
			let R=20;
			let angle=210;
			loop(60)
			{
				CreateShotA1(GetX+R*cos(angle),GetY+R*sin(angle),10,angle,DS_BALL_BS_PURPLE,5);
				CreateShotA1(GetX+R*cos(540-angle),GetY+R*sin(540-angle),10,540-angle,DS_BALL_BS_PURPLE,5);
				angle+=2;
				wait(2);
			}
			loop(60)
			{
				CreateShotA1(GetX+R*cos(angle),GetY+R*sin(angle),10,angle,DS_BALL_BS_PURPLE,5);
				CreateShotA1(GetX+R*cos(540-angle),GetY+R*sin(540-angle),10,540-angle,DS_BALL_BS_PURPLE,5);
				angle-=2;
				wait(2);
			}
		}
	}

}