#搶曽抏枊晽[Single]
#ScriptVersion[3]
#Title["怑arth 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 way = 1;
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(60);
	ObjEnemyBossScene_StartSpell(objScene);
	Cutin("Earth Sign\"Rock Spike\"",15);
	wait(60);
	TSpike;
	wait(300);
	TShot;
	}
//----------------------------------------------------

task TShot{
	while(!Obj_IsDeleted(objBoss)){
	PlaySound("Shot1",0);
	ascent(i in 0..18){
	ascent(a in 0..2){
	CreateShotA1(GetEnemyX,GetEnemyY,1+a/2,i*20+a*10,KUNAI_ORANGE,10);
	}
	}
	wait(120);
	TMovement(35,10,2);
	}
	}

task TSpike{
	let x = 0;
	let angle = 0;
	let obj;
	while(!Obj_IsDeleted(objBoss)){
	TCharge01(GetEnemyX,GetEnemyY,3,3,60,255,255,0);
	PlaySound("Charge4",0);
	wait(60);
	ascent(n in 0..10){
	x = 464/10*n;
	angle = rand(75,105);
	TExplosionA(x, -20, 4, 0.03);
	obj = CreateStraightLaserA1(x,-20,angle,0,20,0,ST_LASER_ORANGE,100);
	ManageFakeSpike(obj,x,angle,0);
	PlaySound("Eff3",0);
	wait(5);
	}
	wait(300);
	/////////////////////
	TCharge01(GetEnemyX,GetEnemyY,3,3,60,255,255,0);
	PlaySound("Charge4",0);
	wait(60);
	descent(n in 0..10){
	x = 464/10*n;
	angle = rand(255,285);
	TExplosionA(x, stgy*2, 4, 0.03);
	obj = CreateStraightLaserA1(x,stgy*2+20,angle,0,20,0,ST_LASER_ORANGE,100);
	ManageFakeSpike(obj,x,angle,1);
	PlaySound("Eff3",0);
	wait(5);
	}
	wait(300);
	}
	}

task ManageFakeSpike(obj,x,dir,way){
	let length = 0;
	let spike;
	ascent(i in 0..200){
	ObjLaser_SetLength(obj,length);
	length += 40;
	if(i==90){
	PlaySound("Eff2",0);
	if(way == 1){
	spike = CreateStraightLaserA1(x,stgy*2+20,dir,0,20,120,C_LASER_ORANGE,0);
	ManageSpike(spike);
	TExplosionA(x, stgy*2+20, 10, 0.1);
	ascent(i in 0..15){
	CreateShotA1(x,stgy*2,1,i*24+dir,PELLET_ORANGE,10);
	}
	}
	else{
	spike = CreateStraightLaserA1(x,-20,dir,0,20,120,C_LASER_ORANGE,0);
	ManageSpike(spike);
	TExplosionA(x, -20, 10, 0.1);
	ascent(i in 0..30){
	CreateShotA1(x,0,1,i*12+dir,PELLET_ORANGE,10);
	}
	}
	}
	yield;
	}
	Obj_Delete(obj);
	}

task ManageSpike(obj){
	let length = 0;
	while(!Obj_IsDeleted(obj)){
	ObjLaser_SetLength(obj,length);
	if(length<=600){length += 40;}
	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());
	}
