#東方弾幕風[Single]
#ScriptVersion[3]
#Title["侵on-Spell4"]
#Text["Non-Spell4"]
#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;
let s = 1;
@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(60);
	fire;
	}
//----------------------------------------------------


task fire{
	let obj;
	while(ObjEnemy_GetInfo(objBoss,INFO_LIFE)>0){
	TCharge01(GetEnemyX,GetEnemyY,2,2,30,0,255,0);
	wait(30);
	TCharge01(GetEnemyX,GetEnemyY,2,2,30,255,255,0);
	wait(30);
	PlaySound("Shot2",0);
	ascent(i in 0..5){
	obj = CreateShotA1(GetEnemyX,GetEnemyY,3,210+i*30,OVAL_YELLOW,20);
	Manage(obj);
	}
	TMovement(35,10);
	wait(270);
	ascent(i in 0..7){
	PlaySound("Shot2",0);
	obj = CreateShotA1(GetEnemyX,GetEnemyY,3.5,180+i*30,OVAL_YELLOW,20);
	Manage(obj);
	wait(15);
	}
	wait(210);
	TCharge01(GetEnemyX,GetEnemyY,2,2,30,0,255,0);
	wait(30);
	TCharge01(GetEnemyX,GetEnemyY,2,2,30,255,255,0);
	wait(30);
	PlaySound("Shot2",0);
	ascent(i in 0..5){
	obj = CreateShotA1(GetEnemyX,GetEnemyY,3,210+i*30,OVAL_YELLOW,20);
	Manage(obj);
	}
	TMovement(35,10);
	wait(270);
	descent(i in 0..7){
	PlaySound("Shot2",0);
	obj = CreateShotA1(GetEnemyX,GetEnemyY,3.5,180+i*30,OVAL_YELLOW,20);
	Manage(obj);
	wait(15);
	}
	wait(210);
	}
	}

task Manage(obj){
	let x = ObjMove_GetX(obj);
	let y = ObjMove_GetY(obj);
	let angle = GetAngleToPlayer(obj);
	let l;
	let c = 0;
	while(!Obj_IsDeleted(obj)){
	if(ObjMove_GetX(obj)<0 || ObjMove_GetX(obj)>stgx*2 || ObjMove_GetY(obj)<0){
	PlaySound("Eff1",0);
	PlaySound("Laser1",60);
	angle = GetAngleToPlayer(obj);
	x = ObjMove_GetX(obj);
	y = ObjMove_GetY(obj);
	ascent(i in 0..3){
	l = CreateStraightLaserA1(x,y,angle-30+i*30,0,20,100,SMALL_YELLOW,60);
	ManageLaser(l,x,y);
	}
	Obj_Delete(obj);
	}
	yield;
	}
	}

	task ManageLaser(obj,x,y){
	let length = 0;
	let c = 0;
	while(!Obj_IsDeleted(obj)){
	ObjLaser_SetLength(obj,length);
	length += 50;
	c++;
	if(c==60){
	ascent(i in 0..30){
	CreateShotA1(x,y,1.5,i*12,PELLET_GREEN,10);
	CreateShotA1(x,y,1.2,i*12,PELLET_GREEN,10);
	}
	}
	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)<=100||(GetEnemyX+posx)>=(GetStgFrameWidth()-100)){
			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());

	}
