
#ScriptVersion[3]
#Title["Non-Spell2L"]
#Text["Non-Spell2L"]
#Background["./Background.txt"]
#BGM[DEFAULT]
#Player[DEFAULT]

#include"./Functions/Index.txt"
#include"script/Medicine/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
{
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	ObjEnemy_SetDamageRate(objBoss,100,50);
	ObjMove_SetDestAtWeight(objBoss,stgx,150,10,7);
	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);
	SetPlayerSpeed(4,2);
	yield;

}

@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
	{
		SetScriptResult(3500);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(50);
	}
}

//----------------------------------------------------
task mainTask{
	wait(90);
	TFire;
	}
//----------------------------------------------------

task TFire{
	let r = 0;
	let dir = 0;
	let s = 1;
	let obj;
	loop(10){
	ascent(n in 0..2){
	ascent(i in 0..4){
	obj = CreateShotOA1(objBoss,10,0,LARGE_PURPLE,12);
	ObjMove_AddPatternA2(obj,0,4,180+i*30,0,-1.5,0);
	Manage(obj,n);
	}
	ascent(i in 0..4){
	obj = CreateShotOA1(objBoss,10,0,LARGE_PURPLE,12);
	ObjMove_AddPatternA2(obj,0,4,270+i*30,0,1.5,0);
	Manage(obj,n);
	}
	wait(45);
	TMovement(20,5,3);
	wait(45);
	}
	ascent(i in 0..6){
	obj = CreateShotOA1(objBoss,5,i*60,LARGE_PURPLE,12);
	Manage2(obj);
	}
	wait(60);
	maple(1);
	wait(120);
	ascent(n in 0..10){
	 PlaySound("Shot4",98,0);
	 ascent(i in 0..12){
	  ascent(a in 0..4){
	  CreateShotA1(GetEnemyX+60*cos(i*30+n*6*s),GetEnemyY+60*sin(i*30+n*6*s),0.75+a/2,i*30+n*9*s,BL_SMALL_YELLOW,20);
	  }
	 }
	 wait(4);
	}
	wait(30);
	ascent(n in 0..10){
	 PlaySound("Shot4",98,0);
	 ascent(i in 0..10){
	  ascent(a in 0..3){
	  CreateShotA1(GetEnemyX+60*cos(i*40-n*19*s+20),GetEnemyY+60*sin(i*40-n*19*s+20),1+a/2,i*40-n*21*s,BL_SMALL_GREEN,20);
	  }
	 }
	 wait(3);
	}
	wait(30);
	TMovement(20,5,3);
	wait(30);
	s = -s;
	}
	}

task TFire2{
	ascent(i in 0..6){
	ascent(a in 0..7){
	CreateShotOA1(objBoss,0.5+a/3,GetAngleToPlayer(objBoss)+i*60,LARGE_RED,20);
	}
	}
	}

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

task Manage(obj,c){
	let dir = rand(0,29);
	let color = [PELLET_GREEN,PELLET_YELLOW];
	wait(30);
	ObjRender_SetAlpha(obj,0);
	ObjShot_SetIntersectionEnable(obj,false);
	ascent(n in 0..3){
	PlaySound("Shot4",95,0);	
	ascent(i in 0..12){
	CreateShotOA1(obj,1.5,i*30+n*20+dir,color[c],10);
	}
	wait(15);
	}
	}

task Manage2(obj){
	let dir = rand(0,19);
	wait(30);
	ObjRender_SetAlpha(obj,0);
	ObjShot_SetIntersectionEnable(obj,false);
	ascent(n in 0..2){
	PlaySound("Shot4",95,0);	
	ascent(i in 0..18){
	CreateShotOA1(obj,1.5,i*20+n*7.5+dir,PELLET_PURPLE,10);
	}
	wait(30);
	}
	}

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

task TRender
{
	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, 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,0);}
		else{ObjRender_SetAngleY(objBoss,180);}
		manageSprite;
		t = 1;
		}
		ObjSprite2D_SetDestCenter(objBoss);
		yield;
	}
}

//----------------------------------------------------
task TEnd{
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){yield;}
		//TExplosionA(GetEnemyX,GetEnemyY,10,0.6);
		DeleteShotAll(TYPE_ALL,TYPE_ITEM);
		Obj_Delete(objBoss);
		SetAutoDeleteObject(true);
		loop(10){
			DeleteShotAll(TYPE_ALL,TYPE_IMMEDIATE);
			yield;
			}
		CloseScript(GetOwnScriptID());
		return;
	}
