#東方弾幕風[Single]
#ScriptVersion[3]
#Title["色ire Sign"]
#Text["Untitle"]
#Image["./ExRumia(星符「ミッドナイトレヴァリエ」).jpg"]
#Background["script/default_system/Default_Background_IceMountain.txt"]
#BGM[DEFAULT]
#Player[DEFAULT]

#include"./Functions/Index.txt"
#include"script/Rumia Boss/ZUNShot_Const.txt"
#include"script/Default_system/Default_Effect.Txt"

let objBoss;
let mbg;
let bSpell=true;
let value = 420;
let objScene=GetEnemyBossSceneObjectID();
let GCSD=GetCurrentScriptDirectory~"";
let stgx=GetStgFrameWidth()/2;
let stgy=GetStgFrameHeight()/2;
@Initialize
{
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	ObjEnemy_SetDamageRate(objBoss,20,10);
	mainTask;
	TRender;
	LoadSoundEffects;
	TEnd;
	ObjMove_SetDestAtWeight(objBoss,stgx,150,10,5);
	DeleteShotAll(TYPE_ALL, TYPE_ITEM);//出現と同時に敵弾を全て削除	
}

@MainLoop
{
	ObjEnemy_SetIntersectionCircleToPlayer(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),25);
	ObjEnemy_SetIntersectionCircleToShot(objBoss,ObjMove_GetX(objBoss),ObjMove_GetY(objBoss),26);
	if(GetShotCount(TARGET_ENEMY) == 0 && value == 0){
	TWork;
	value = 180;
	}
	if(value>0){
	value--;
	}
	yield;
}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
	{
		SetScriptResult(750);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(60);
	}
	case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(30000);
	}
}

//----------------------------------------------------
task mainTask{
	wait(60);
	ObjEnemyBossScene_StartSpell(objScene);
	Cutin("Fire Sign\"Ring of Fire\"",15);
	wait(120);
	TWork;
	wait(300);
	TShot;
	}
//----------------------------------------------------
task TWork{
	if(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){
	// Caution !! //
	ascent(i in 0..6){
	PlaySound("Enep1",0);
	TExplosionA(GetEnemyX+120*cos(i*60), GetEnemyY+120*sin(i*60), 3, 0.05);
	wait(5);
	}
	ascent(i in 0..12){
	PlaySound("Enep1",0);
	TExplosionA(GetEnemyX+250*cos(-i*30+15), GetEnemyY+250*sin(-i*30+15), 5, 0.05);
	wait(4);
	}	
	wait(30);
	// Boomz !! //
	TCharge01(GetEnemyX,GetEnemyY,3,3,30,255,0,0);
	PlaySound("Charge2",0);
	PlaySound("stars",60);
	wait(30);
	TCharge01(GetEnemyX,GetEnemyY,3,3,30,255,0,0);
	wait(30);
	TExplosionA(GetEnemyX, GetEnemyY, 3, 0.15);
	ascent(i in 0..6){TExplosionA(GetEnemyX+120*cos(i*60), GetEnemyY+120*sin(i*60), 10, 0.1);}
	ascent(i in 0..12){TExplosionA(GetEnemyX+250*cos(-i*30+15), GetEnemyY+250*sin(-i*30+15), 10, 0.1);}
	ascent(i in 0..6){
	let bigbullet = CreateShotA1(GetEnemyX+120*cos(i*60),GetEnemyY+120*sin(i*60),0,0,ORB_RED,30);
	manage(bigbullet,i*60);
	}
	ascent(i in 0..12){
	let bigbullet2 = CreateShotA1(GetEnemyX+240*cos(i*30+15),GetEnemyY+240*sin(i*30+15),0,180,ORB_RED,30);
	manage(bigbullet2,i*30+20);
	}
	}
	}

task TShot{
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){
	PlaySound("BulletWave",0);
	ascent(a in 0..3){
	CreateShotA1(GetEnemyX,GetEnemyY,0.75+a/2,angleToPlayer,BUBBLE_RED,0);
	}
	wait(180);
	PlaySound("BulletWave",0);
	ascent(a in 0..2){
	CreateShotA1(GetEnemyX,GetEnemyY,0.75,angleToPlayer-20+a*40,BUBBLE_RED,0);
	}
	CreateShotA1(GetEnemyX,GetEnemyY,1.25,angleToPlayer,BUBBLE_RED,0);
	wait(180);
	}
	}

task manage(obj,r){
	let smallbullet;
	let c = 0;
	let ra = ObjMove_GetAngle(obj);
	ObjShot_SetAutoDelete(obj,false);
	ObjShot_SetSpellResist(obj,true);
	ascent(i in 0..8){
	smallbullet = CreateShotOA1(obj,0,0,FIRE_RED,0);
	manage2(smallbullet,i*45);
	}
	while(!Obj_IsDeleted(obj)){
	c++;
	ObjMove_SetPosition(obj,GetEnemyX+(120+ra/1.2)*cos(r),GetEnemyY+(120+ra/1.2)*sin(r));
	if(ra==0){r+= 0.2;}
	else if(ra==180){r-= 0.12;}
	yield;
	}
		task manage2(obj2,r2){
		let dis = 0;
		ObjShot_SetAutoDelete(obj2,false);
		ObjShot_SetSpellResist(obj2,true);
		while(!Obj_IsDeleted(obj2)){
		ObjMove_SetPosition(obj2,ObjMove_GetX(obj)+(70*sin(dis))*cos(r2),ObjMove_GetY(obj)+(70*sin(dis))*sin(r2));
		r2+= 0.5;
		dis+=0.4;
		yield;
		}
	}
	}
//----------------------------------------------------
//描画タスク
//----------------------------------------------------

task TRender
{
	magiccircle(objBoss);
	let imgExRumia = GetCurrentScriptDirectory~"boss11.png";
	let f = 0;
	let t = 0;
	ObjPrim_SetTexture(objBoss, imgExRumia);
	while(!Obj_IsDeleted(objBoss))
	{
		let angle = ObjMove_GetAngle(objBoss);
		let speed = ObjMove_GetSpeed(objBoss);
		if(speed == 0){
		if(f<8){ObjSprite2D_SetSourceRect(objBoss, 0, 0, 64, 64);}
		if(f>=8 && f<16){ObjSprite2D_SetSourceRect(objBoss, 64, 0, 128, 64);}
		if(f>=16 && f<24){ObjSprite2D_SetSourceRect(objBoss, 128, 0, 192, 64);}
		if(f>=24 && f<32){ObjSprite2D_SetSourceRect(objBoss, 192, 0, 256, 64);}
		if(f>=32){f=0;}
		f++;
		t = 0;
		}
		else if(cos(angle) > 0 || cos(angle) < 0 && t == 0){
		if(cos(angle)<0){ObjRender_SetAngleY(objBoss,180);}
		else{ObjRender_SetAngleY(objBoss,0);}
		manageSprite;
		t = 1;
		}
		ObjSprite2D_SetDestCenter(objBoss);
		yield;
	}
}

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

function TMovement(x,y){
		let resultx=rand(0,1);
		resultx=round(resultx);
		let resulty=rand(0,1);
		resulty=round(resulty);
		let posx=rand(10,-10);
		if(posx<=10&&posx>=-10){
			if(resultx==1){
				posx=x;
			}else{
				posx=-x;
			}
		}
		if((GetEnemyX+posx)<=32||(GetEnemyX+posx)>=(GetStgFrameWidth()-32)){
			posx=-posx;
		}
		
		let posy=rand(20,-20);
		if(posy<=7.5&&posy>=-7.5){
			if(resulty==1){
				posy=y;
			}else{
				posy=-y;
			}
		}
		if((GetEnemyY+posy)<=32||(GetEnemyY+posy)>=GetStgFrameHeight()/3){
			posy=-posy;
		}
		ObjMove_SetDestAtWeight(objBoss,GetEnemyX+posx,GetEnemyY+posy,10,5);
}
	
//----------------------------------------------------
task TEnd{
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){yield;}
		TExplosionA(GetEnemyX,GetEnemyY,10,0.6);
		DeleteShotAll(TYPE_ALL,TYPE_ITEM);
		Obj_Delete(objBoss);
		loop(30){
		DeleteShotAll(TYPE_ALL,TYPE_ITEM);
		yield;
		}
		CloseScript(GetOwnScriptID());

	}
