
#ScriptVersion[3]
#Title["nonSpell2V"]
#Text["nonSpell2V"]
#Background["./Background.txt"]
#BGM[DEFAULT]
#Player[DEFAULT]

#include"./Functions/Index.txt"
#include"script/Letty/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;
let objScene=GetEnemyBossSceneObjectID();
@Initialize
{LoadTexture(GCSD~"shot/ZUNShot.png");
	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);
	yield;

}

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

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

task TFire{
	let obj;
	let r = 360;
	while(!Obj_IsDeleted(objBoss)){
	r = 360;
	ascent(n in 0..21){
	PlaySound("Shot1",95,0);
	ascent(i in 0..4){
	ascent(a in 0..2){
	ShotA2(GetEnemyX,GetEnemyY,4+a,i*7.7+n*42,-0.1,1,PELLET_GREEN,12);
	ShotA2(GetEnemyX,GetEnemyY,4+a,i*8.7+n*42+180,-0.1,1,PELLET_GREEN,12);
	}
	}
	ascent(a in 0..10){
	ShotOA1(objBoss,0.5+a/3,96-n*11+angleToPlayer,BL_SMALL_BLUE,12);
	ShotOA1(objBoss,0.5+a/3,276-n*11+angleToPlayer,BL_SMALL_BLUE,12);
	}
	wait(5);
	}
	//////////////
	descent(n in 0..21){
	PlaySound("Shot1",95,0);
	ascent(i in 0..4){
	ascent(a in 0..2){
	ShotA2(GetEnemyX,GetEnemyY,4+a,i*8.7+n*42,-0.1,1.5,PELLET_GREEN,12);
	ShotA2(GetEnemyX,GetEnemyY,4+a,i*7.7+n*42+180,-0.1,1.5,PELLET_GREEN,12);
	}
	}
	ascent(a in 0..10){
	ShotOA1(objBoss,0.5+a/3,96-n*11+angleToPlayer,BL_SMALL_BLUE,12);
	ShotOA1(objBoss,0.5+a/3,276-n*11+angleToPlayer,BL_SMALL_BLUE,12);
	}
	wait(5);
	}
	wait(60);
	TMovement(30,5,5);
	wait(60);
	maple(1);
	wait(120);
	attack(100);
	ascent(i in 0..40){
	PlaySound("BulletWave",95,0);
	r -= 8;
	obj = snow(GetEnemyX+r*cos(i*16),GetEnemyY+r*sin(i*16),rand(0.1,0.2),i*30+rand(-30,30),4,60,0);
	Manage(obj,i);
	wait(3);
	}
	r = 360;
	wait(90);
	attack(100);
	descent(i in 0..40){
	PlaySound("BulletWave",95,0);
	r -= 8;
	obj = snow(GetEnemyX+r*cos(i*16),GetEnemyY+r*sin(i*16),rand(0.1,0.2),i*30+rand(-30,30),4,60,0);
	Manage(obj,i);
	wait(3);
	}
	wait(90);
	PlaySound("Shot1",95,0);
	ascent(i in 0..36){
	ascent(a in 0..4){
	ShotA1(GetEnemyX+30*cos(i*10+a*5),GetEnemyY+30*sin(i*10+a*5),0.5+a/2,i*10+a*5,PELLET_AQUA,12);
	}
	}
	wait(60);
	TMovement(35,5,5);
	wait(60);
	}
	}

task Manage(obj,num){
	wait(90);
	let x = ObjMove_GetX(obj)+rand(-15,15);
	let y = ObjMove_GetY(obj)+rand(-15,15);
	Obj_Delete(obj);
	ascent(i in 0..4){
	if(i%2==0){PlaySound("Shot1",95,0);}
	loop(2){
	let shot = ShotA2(x+rand(-15,15),y+rand(-15,15),rand(3.5,4.5),NULL,-0.1,rand(0.5,1),SMALL_BLUE,20);
	let angle = getAtanAngle(shot,objBoss);
	ObjMove_SetAngle(shot,i*90+angle+num);
	}
	wait(3);
	}
	}

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

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){
		ObjRender_SetAngleY(objBoss,180);
		if(f<8){ObjSprite2D_SetSourceRect(objBoss, 0, 0, 48, 64);}
		if(f>=8 && f<16){ObjSprite2D_SetSourceRect(objBoss, 48, 0, 96, 64);}
		if(f>=16 && f<24){ObjSprite2D_SetSourceRect(objBoss, 96, 0, 144, 64);}
		if(f>=24 && f<32){ObjSprite2D_SetSourceRect(objBoss, 144, 0, 192, 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;
	}
