#東方弾幕風[Single]
#ScriptVersion[3]
#Title["色antasy Sign"]
#Text["Untitle"]
#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=true;
let value = 420;
let frame = 0;
let aim = "false";
let objScene=GetEnemyBossSceneObjectID();
let GCSD=GetCurrentScriptDirectory~"";
let stgx=GetStgFrameWidth()/2;
let stgy=GetStgFrameHeight()/2;
@Initialize
{
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	ObjEnemy_SetDamageRate(objBoss,20,10);
	mainTask;
	TRender;
	LoadSoundEffects;
	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(850);
	}
	case(EV_REQUEST_TIMER)
	{
		SetScriptResult(60);
	}
	case(EV_REQUEST_SPELL_SCORE)
	{
		SetScriptResult(30000);
	}
}

//----------------------------------------------------
task mainTask{
	wait(120);
	ObjEnemyBossScene_StartSpell(objScene);
	Cutin("Fantasy Sign\"Magic Orb\"",15);
	wait(60);
	TBall;
	}
//----------------------------------------------------

task TBall{
	let obj;
	obj = CreateShotA1(GetEnemyX+150*cos(0),GetEnemyY+100*sin(0),0,0,ORB_RED,30);
	ManageRed(obj);
	obj = CreateShotA1(GetEnemyX+150*cos(72),GetEnemyY+100*sin(72),0,0,ORB_BLUE,30);
	ManageBlue(obj);
	obj = CreateShotA1(GetEnemyX+150*cos(144),GetEnemyY+100*sin(144),0,0,ORB_GREEN,30);
	ManageGreen(obj);
	obj = CreateShotA1(GetEnemyX+150*cos(216),GetEnemyY+100*sin(216),0,0,ORB_YELLOW,30);
	ManageYellow(obj);
	obj = CreateShotA1(GetEnemyX+150*cos(288),GetEnemyY+100*sin(288),0,0,ORB_GRAY,30);
	ManageGray(obj);
	PlaySound("Charge3",0);
	TCharge01(GetEnemyX,GetEnemyY,2,2,48,255,0,0);
	wait(24);
	TCharge01(GetEnemyX,GetEnemyY,2,2,48,0,255,0);
	wait(24);
	TCharge01(GetEnemyX,GetEnemyY,2,2,48,0,0,255);
	wait(24);
	TCharge01(GetEnemyX,GetEnemyY,2,2,48,255,255,0);
	wait(24);
	TCharge01(GetEnemyX,GetEnemyY,2,2,48,255,255,255);
	wait(24);
	PlaySound("stars",0);
	}

task ManageGray(obj){
	let c = 0;
	let g;
	let s = 1;
	wait(120);
	TExplosionA(ObjMove_GetX(obj), ObjMove_GetY(obj), 4, 0.15);
	while(!Obj_IsDeleted(obj)){
	ObjMove_SetPosition(obj,GetEnemyX+150*cos(c+288),GetEnemyY+100*sin(c+288));
	c++;
	if(c%90==89){
	ascent(i in 0..12){
	g = CreateShotOA1(obj,1.25,i*30,LARGE_GRAY,5);
	ObjMove_SetAngularVelocity(g,1*s);
	ObjMove_AddPatternA2(g,120,1.25,NO_CHANGE,0,0,0);
	}
	s*= -1;
	}
	yield;
	}
	}

task ManageYellow(obj){
	let c = 0;
	let x;
	let y;
	wait(120);
	TExplosionA(ObjMove_GetX(obj), ObjMove_GetY(obj), 4, 0.15);
	while(!Obj_IsDeleted(obj)){
	ObjMove_SetPosition(obj,GetEnemyX+150*cos(c+216),GetEnemyY+100*sin(c+216));
	c++;
	if(c%175==114){
	x = ObjMove_GetX(obj);
	y = ObjMove_GetY(obj);
	PlaySound("Laser1",0);
	ascent(i in 0..3){
	CreateLooseLaserA1(x,y,4,GetAngleToPlayer(obj)-40+i*40,120,15,C_LASER_YELLOW,10);
	}
	}
	yield;
	}
	}

task ManageGreen(obj){
	let c = 0;
	let g;
	let r = 0;
	wait(120);
	TExplosionA(ObjMove_GetX(obj), ObjMove_GetY(obj), 4, 0.15);
	while(!Obj_IsDeleted(obj)){
	ObjMove_SetPosition(obj,GetEnemyX+150*cos(c+144),GetEnemyY+100*sin(c+144));
	c++;
	if(c%11==10){
	PlaySound("Shot1",0);
	r = rand(0,359);
	ascent(i in 0..4){
	g = CreateShotOA1(obj,rand(1.25,2.25),r+i*90,PELLET_GREEN,10);
	}
	ObjMove_SetAngularVelocity(g,rand(-0.1,0.1));
	}
	yield;
	}
	}

task ManageBlue(obj){
	let c = 0;
	let o;
	wait(120);
	TExplosionA(ObjMove_GetX(obj), ObjMove_GetY(obj), 4, 0.15);
	while(!Obj_IsDeleted(obj)){
	ObjMove_SetPosition(obj,GetEnemyX+150*cos(c+72),GetEnemyY+100*sin(c+72));
	c++;
	if(c%60==59){
	PlaySound("Shot1",0);
	ascent(i in 0..8){
	ascent(a in 0..2){
	o = CreateShotOA1(obj,0.75+a/2,i*45+a*22.5,SMALL_BLUE,10);
	}
	}
	}
	yield;
	}
	}

task ManageRed(obj){
	let c = 0;
	wait(120);
	TExplosionA(ObjMove_GetX(obj), ObjMove_GetY(obj), 4, 0.15);
	while(!Obj_IsDeleted(obj)){
	ObjMove_SetPosition(obj,GetEnemyX+150*cos(c),GetEnemyY+100*sin(c));
	c++;
	if(c%120==119){
	 PlaySound("BulletWave",0);
	 ascent(i in 0..3){
	 CreateShotOA1(obj,0.75,GetAngleToPlayer(obj)-30+i*30,OVAL_RED,10);
	 }
	 ascent(i in 0..2){
	 CreateShotOA1(obj,1.25,GetAngleToPlayer(obj)-15+i*30,OVAL_RED,10);
	 }
	 CreateShotOA1(obj,1.75,GetAngleToPlayer(obj),OVAL_RED,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,speed){
		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)<=96||(GetEnemyX+posx)>=(GetStgFrameWidth()-96)){
			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,speed);
}
	
//----------------------------------------------------
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());
	}
