#東方弾幕風[Single]
#ScriptVersion[3]
#Title["Non-Spell1"]
#Text["Non-Spell1"]
#Background["./Background.txt"]
#BGM[DEFAULT]
#Player[DEFAULT]

#include"./Functions/Index.txt"
#include"script/Miko/Shot/ZUNShot_Const.txt"
#include"script/Default_system/Default_Effect.Txt"

let objBoss;
let enemy;
let bSpell=false;
let GCSD=GetCurrentScriptDirectory~"";
let stgx=GetStgFrameWidth()/2;
let stgy=GetStgFrameHeight()/2;
let idle = true;
@Initialize
{
	LoadTexture(GCSD~"shot/ZUNShot.png");
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	ObjMove_SetPosition(objBoss,-120,-120);
	ObjEnemy_SetDamageRate(objBoss,100,50);
	mainTask;
	TRender;
	TEnd;
	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(4000);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(40);
	}
}

//----------------------------------------------------
task mainTask{
	wait(60);
	ObjMove_SetDestAtWeight(objBoss,stgx,150,10,7);
	wait(90);
	TArrow;
	}
//----------------------------------------------------

task TArrow{
	let color;
	let s = 1;
	while(!Obj_IsDeleted(objBoss)){
	if(s==1){color = ARROW_BLUE;}
	else{color = ARROW_RED;}
	set(72*3+48*2+30);
	wait(60);
	ascent(n in 0..36){
	PlaySound("Shot1",95,0);
	ascent(i in 0..6){
	ShotA1(GetEnemyX,GetEnemyY-70,4-n/36,i*60+n*11*s,color,12);
	ShotA1(GetEnemyX,GetEnemyY-70,4-n/36,i*60-n*9*s,color,12);
	}
	wait(3);
	}
	wait(30);
	ascent(n in 0..64){
	PlaySound("Shot1",95,0);
	ascent(i in 0..5){
	ShotA1(GetEnemyX,GetEnemyY-70,3.25+n/18,i*72+n*8*s,color,12);
	ShotA1(GetEnemyX,GetEnemyY-70,3.75+n/18,i*72+n*8*s,color,12);
	}
	if(n==16){TArrow2;}
	//if(n==43){TCharge01(GetEnemyX,GetEnemyY,3,60,255,0,255);}
	wait(3);
	}
	TExplosionA(GetEnemyX,GetEnemyY,2,0.1);
	TExplosionA(GetEnemyX,GetEnemyY,2,0.2);
	PlaySound("stars",100,0);
	ascent(a in 0..7){
	CreateLooseLaserA1(GetEnemyX,GetEnemyY,8,a*360/7+15,500,30,G_LARGE_RED,0);
	ascent(i in 0..30){
	ShotOA1(objBoss,1+a/4,i*12+a*3.7*s,177+a,0);
	}
	}
	s = -s;
	wait(60);
	TMovement(35,10,5);
	wait(60);
	}
	}

task TArrow2{
	let px = 0;
	let py = 0;
	let angle = 0;
	ascent(n in 0..9){
	px = GetEnemyX+rand(-75,75);
	py = GetEnemyY+rand(-57,57)-70;
	angle = rand(-30,30);
	ascent(i in 0..6){
	ascent(a in 0..2){
	ShotA1(px,py,1.5+a,i*60+angle+n*1,ARROW_GREEN,16);
	ShotA1(px,py,1.5+a,i*60+angle-n*1,ARROW_GREEN,16);
	}
	}
	wait(8);
	}
	}

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


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

task TRender
{
	TWaveCircle();
	Aura;
	magiccircle(objBoss,1.75,true);
	let imgMiko = GetCurrentScriptDirectory~"img/boss.png";
	let f = 0;
	let t = 0;
	ObjPrim_SetTexture(objBoss, imgMiko);
	ObjRender_SetScaleXYZ(objBoss,1.05,1.05,1);
	while(!Obj_IsDeleted(objBoss))
	{
		let angle = ObjMove_GetAngle(objBoss);
		let speed = ObjMove_GetSpeed(objBoss);
		if(speed == 0 && idle == true){
		if(f<8){ObjSprite2D_SetSourceRect(objBoss, 0, 0, 64, 98);}
		if(f>=8 && f<16){ObjSprite2D_SetSourceRect(objBoss, 64, 0, 128, 98);}
		if(f>=16 && f<24){ObjSprite2D_SetSourceRect(objBoss, 128, 0, 192, 98);}
		if(f>=24 && f<32){ObjSprite2D_SetSourceRect(objBoss, 192, 0, 256, 98);}
		if(f>=32){f=0;}
		f++;
		t = 0;
		}
		else if(cos(angle) > 0 || cos(angle) < 0 && t == 0 && idle ==true){
		if(cos(angle)<0){point = 1;}
		else{point = -1;}
		manageSprite;
		t = 1;
		}
		ObjSprite2D_SetDestCenter(objBoss);
		yield;
	}
}

//----------------------------------------------------
task TEnd{
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){yield;}
		let arr = GetShotIdInCircleA2(stgx,stgy,600,TARGET_ENEMY);
		Obj_Delete(objBoss);
		SetAutoDeleteObject(true);
		yield;
		SetAutoDeleteObject(false);
		ascent(i in 0..length(arr)){
		effbreak(arr[i],"PURPLE");
		Obj_Delete(arr[i]);
		}
		wait(30);
		SetAutoDeleteObject(true);
		CloseScript(GetOwnScriptID());
		return;
	}
