
#ScriptVersion[3]
#Title["Non-Spell1"]
#Text["Non-Spell1"]
#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(4000);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(50);
	}
}

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

task TFire{
	let r = 0;
	let dir = 0;
	let obj;
	let s = 1;
	maple(2);
	wait(60);
	loop(5){
	ascent(i in 0..12){
	let obj = CreateShotA2(GetEnemyX,GetEnemyY,5,i*30,-0.1,1,LARGE_PURPLE,12);
	Manage(obj,1);
	}
	wait(120);
	ascent(i in 0..12){
	let obj = CreateShotA2(GetEnemyX,GetEnemyY,5,i*30+15,-0.1,1,LARGE_PURPLE,12);
	Manage(obj,-1);
	}
	wait(150);
	ascent(i in 0..12){
	let obj = CreateShotA2(GetEnemyX,GetEnemyY,5,i*30+15,-0.1,1,LARGE_PURPLE,12);
	Manage2(obj);
	}
	wait(60);
	maple(1);
	wait(120);
	ascent(n in 0..13){
	 PlaySound("Shot4",98,0);
	 ascent(i in 0..6){
	  ascent(a in 0..5){
	  CreateShotA1(GetEnemyX+60*cos(i*60+n*9*s),GetEnemyY+60*sin(i*60+n*9*s),0.5+a/3,i*60+n*13*s,BL_SMALL_YELLOW,20);
	  }
	 }
	 wait(5);
	}
	wait(60);
	TMovement(35,5,5);
	wait(60);
	s = -s;
	}
	}

task Manage(obj,dir){
	let angle = 0;
	wait(30);
	ObjRender_SetAlpha(obj,0);
	ObjShot_SetIntersectionEnable(obj,false);
	ascent(n in 0..3){
	PlaySound("Shot4",100,0);
	ascent(i in 0..7){
	angle = 360/7;
	if(dir==1){CreateShotOA1(obj,1.5,i*angle+n*angle/3*dir,PELLET_YELLOW,8);}
	if(dir==-1){CreateShotOA1(obj,1.5,i*angle+n*angle/3*dir,PELLET_GREEN,8);}
	}
	wait(20);
	}
	}

task Manage2(obj){
	wait(30);
	ObjRender_SetAlpha(obj,0);
	ObjShot_SetIntersectionEnable(obj,false);
	ascent(n in 0..2){
	PlaySound("Shot4",100,0);	
	ascent(i in 0..12){
	CreateShotOA1(obj,1.5,i*30+n*20,PELLET_PURPLE,10);
	}
	wait(30);
	}
	}

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

task Control(obj,type){
	let shot;
	if(type==1){	
		wait(30);
		loop(100){
		ascent(i in 0..12){
		ascent(a in 0..2){
		shot = CreateShotOA1(obj,1+a/2,i*30,PELLET_GREEN,12);
		ObjMove_SetAngle(shot,GetAngleToPlayer(shot)+i*30);
		}
		}
		PlaySound("Shot5",100,0);
		wait(30);
		}
	}
	if(type==2){
		wait(30);
		ascent(i in 0..12){
		ascent(a in 0..4){
		shot = CreateShotOA1(obj,1.5+a/3,i*30,LARGE_YELLOW,12);
		ObjMove_SetAngle(shot,GetAngleToPlayer(shot)+i*30);
		}
		}
		PlaySound("Shot5",100,0);
	}
	}

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

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;
	}
