#東方弾幕風[Single]
#ScriptVersion[3]
#Title["侵on-Spell2"]
#Text["Non-Spell2"]
#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 bSpell=false;
let GCSD=GetCurrentScriptDirectory~"";
let stgx=GetStgFrameWidth()/2;
let stgy=GetStgFrameHeight()/2;
@Initialize
{
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	mainTask;
	LoadSoundEffects;
	TRender;
	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);
	yield;

}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
	{
		SetScriptResult(3500);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(60);//時間制限を60秒に設定
	}
}

//----------------------------------------------------
task mainTask{
	wait(120);
	TWork;
	}
//----------------------------------------------------

task TWork{
	let s = 1;
	if(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){
	ascent(n in 0..2){
	loop(2){
	let ex = ObjMove_GetX(objBoss);
	let ey = ObjMove_GetY(objBoss);
	let obj;
	PlaySound("Laser2",0);
	ascent(i in 0..4){
	TExplosionA(ex+60*cos(i*90+30), ey+60*sin(i*90+30), 10, 0.1);
	if(s==1){
	obj = CreateStraightLaserA1(ex+60*cos(i*90+30),ey+60*sin(i*90+30),i*90+30,600,20,91,ST_LASER_RED,0);
	ManageObj(obj,i*90+30,s,n);
	}
	else if(s==-1){
	obj = CreateStraightLaserA1(ex+60*cos(i*90-20),ey+60*sin(i*90+60),i*90+60,600,20,91,ST_LASER_BLUE,0);
	ManageObj(obj,i*90+60,s,n);
	}
	}
	s *= -1;
	wait(90);
	}
	wait(30);
	if(n==0){TMovement(35,10);
	wait(60);
	}
	else{
	ObjMove_SetDestAtWeight(objBoss,stgx,120,10,5);
	}
	}
	TShot;
	}
	}

task TShot{
	let obj;
	wait(60);
	TCharge01(GetEnemyX,GetEnemyY,2,2,30,255,255,255);
	wait(30);
	descent(n in 0..15){
	PlaySound("Shot1",0);
	ascent(i in 0..12){
	obj = CreateShotA2(GetEnemyX+100,GetEnemyY,5,i*30+n*1.5,0,0,SMALL_BLUE,0);
	ObjMove_AddPatternA2(obj,10+n,1,NO_CHANGE,0.03,0.4,4);
	obj = CreateShotA2(GetPlayerX+60*cos(i*30-n*7),GetPlayerY+60*sin(i*30-n*7),5,i*30-n*7,0,0,SMALL_BLUE,0);
	ObjMove_AddPatternA2(obj,10+n,1,NO_CHANGE,0.03,0.35,4);
	}
	wait(2);
	PlaySound("Shot1",0);
	ascent(i in 0..12){
	obj = CreateShotA2(GetEnemyX-100,GetEnemyY,5,i*30-n*1.5,0,0,SMALL_RED,0);
	ObjMove_AddPatternA2(obj,10+n,1,NO_CHANGE,0.03,-0.4,4);
	obj = CreateShotA2(GetPlayerX+60*cos(i*30+n*7),GetPlayerY+60*sin(i*30+n*7),5,i*30+n*7,0,0,SMALL_RED,0);
	ObjMove_AddPatternA2(obj,10+n,1,NO_CHANGE,0.03,-0.35,4);
	}
	wait(2);
	}
	wait(30);
	TWork;
	}

task ManageObj(obj,dir,check,type){
	let c = 0;
	let count = 0;
	let obj2;
	let s;
	while(!Obj_IsDeleted(obj)){
	obj2 = CreateShotOA1(obj,0,0,SMALL_RED,15);
	ObjShot_SetDeleteFrame(obj2,0);
	c+= 0.5*check;
	count++;
	ObjMove_SetPosition(obj,GetEnemyX+60*cos(dir+c),GetEnemyY+60*sin(dir+c));
	ObjStLaser_SetAngle(obj,dir+c);
	if(type==0){
	if(count==60 || count == 30 || count == 1){
	PlaySound("Shot1",0);
	ascent(i in 0..9){
	ascent(a in 0..3){
	if(check==1){CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),2+a/2,i*40+GetAngleToPlayer(obj),SMALL_RED,15);}
	else if(check==-1){CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),2+a/2,i*40+GetAngleToPlayer(obj),SMALL_BLUE,15);}
	}
	}
	}
	}
	if(type==1){
	if(count == 60 || count == 39 || count == 20 || count == 1){
	PlaySound("Shot1",0);
	if(count%2==0){s=5;}
	else{s=-5;}
	ascent(i in 0..3){
	if(check==1){
	CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),2,angleToPlayer-15+i*15,SMALL_RED,15);
	}
	else if(check==-1){
	CreateShotA1(ObjMove_GetX(obj),ObjMove_GetY(obj),2,angleToPlayer-15+i*15,SMALL_BLUE,15);
	}
	}
	}
	}
	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());

	}
