//#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Sp1"]
#Text[""]

#include"./Default_ShotConst.txt"
#include"./Default_Effect.txt"
#include"./effect.txt"

#include"./Effects/Effects.txt"

#include"./Cutin.txt"


let cir = GetCurrentScriptDirectory ~ "circle.png" ;
let bg = GetCurrentScriptDirectory ~ "spbg.jpg" ;
let cut = GetCurrentScriptDirectory ~ "Cut.png" ;
let bg2 = GetCurrentScriptDirectory ~ "spbg2.jpg" ;
let cha = GetCurrentScriptDirectory ~ "./Sounds/se_ch02.wav" ;
let cha2 = GetCurrentScriptDirectory ~ "./Sounds/se_enep02.wav" ;
let tana = GetCurrentScriptDirectory ~ "./Sounds/se_tan01.wav" ;
let bgam = GetCurrentScriptDirectory ~ "./Sounds/se_cardget.wav" ;
let ki = GetCurrentScriptDirectory ~ "./Sounds/se_kira00.wav" ;
let boo = GetCurrentScriptDirectory ~ "./Sounds/se_cat00.wav" ;
let img=GetCurrentScriptDirectory ~ "KE.png";
function wait(w){loop(w){yield;}}
let frame = 0;
let af1=0;
let af2=0;
let af3=0;
let dam=0;

let objEnemy;

@Initialize{

objEnemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objEnemy);
	animate;yield;
	
	ObjMove_SetDestAtWeight(objEnemy, 192, 120, 10,3);
	
TExplosionA(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),5,1);
TExplosionA(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),2,0.1);
	
	move;
	LoadSound(cha);
	LoadSound(cha2);
	LoadSound(tana);
	LoadSound(boo);
	LoadSound(bgam);
	LoadSound(ki);
PlaySE(bgam);
	
	end;
back;

	//ObjMove_SetDestAtWeight(objEnemy, -120, -120, 10,12);
	let cx = GetStgFrameWidth() / 2;
	}

let t=0;
let ff=0;
let ff2=0;
let gg=0;
let gg2=0;
let tt=0;

////////////////////////////////////////////////////////////////////////////////////////
let h=0;
let asd=0;
let asd2=0;

task back{
	let bg133=ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(bg133, BLEND_ADD_RGB);
	ObjPrim_SetTexture(bg133,cir);
	ObjSprite2D_SetSourceRect(bg133,0,0,132,132);
	ObjSprite2D_SetDestCenter(bg133);
	////
	

	let hh=0;
	dd;

	task dd{
		while(!Obj_IsDeleted(bg133)){yield;
		ObjRender_SetPosition(bg133,ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),0);
		ObjRender_SetAngleZ(bg133,asd2/2);
			ObjRender_SetScaleXYZ(bg133,1.8+0.3*cos(hh),1.8+0.3*cos(hh),0);
			
		hh+=2;
			Obj_SetRenderPriorityI(bg133,22);
			ObjRender_SetAlpha(bg133,113);
			////
			
			asd2+=6;}}}
let dir;
	let speed;
	let time=0;
	
	
	
	
	
	
	
	
task animate{
	
	
	
	
	

while(!Obj_IsDeleted(objEnemy)){
	ObjPrim_SetTexture(objEnemy,img);
	ObjSprite2D_SetDestRect(objEnemy,-61.5,-83+5*sin(h),61.5,83+5*sin(h));
	ObjRender_SetScaleXYZ(objEnemy,0.7,0.7,0);
	dir=ObjMove_GetAngle(objEnemy);
	speed=ObjMove_GetSpeed(objEnemy);
	h+=4;

	if(speed==0){
	af1=0;
		if(af3==1){time++;
//af1=0;
		if(time<15){ObjSprite2D_SetSourceRect(objEnemy,373, 256, 511, 454);}
		if(time>=15+1 && af1<=20+1){ObjSprite2D_SetSourceRect(objEnemy,533,255, 671, 453);
		
		
		
		
if(time>80){
		time=0;
		af3=0;}
		
		}
		
		}
	else{
	
if(af1<15){ObjSprite2D_SetSourceRect(objEnemy,0, 0, 136, 197);}
		if(af1>=30+1 && af1<=45+1){ObjSprite2D_SetSourceRect(objEnemy,137,0, 274, 197);}
		if(af1>=46+1 && af1<=60+1){ObjSprite2D_SetSourceRect(objEnemy,137+137,0, 411, 197);}
		if(af1>=61+1 && af1<=76+1){ObjSprite2D_SetSourceRect(objEnemy,137,0, 274, 197);}
		
if(af1>77){ObjSprite2D_SetSourceRect(objEnemy,0, 0, 136, 197);}
		}


		}

	if(speed>0 && cos(dir)>0 ){
		ObjRender_SetAngleY(objEnemy,0);
		if(af2>12){ObjSprite2D_SetSourceRect(objEnemy,6, 234, 144, 431);}
		if(af2>24){ObjSprite2D_SetSourceRect(objEnemy,6, 234, 144, 431);}
		if(af2>36){af1=0;}
		af2++;}

	if(speed>0 && cos(dir)<0 ){
		//ObjRender_SetAngleY(objEnemy,180);
		if(af2>12){ObjSprite2D_SetSourceRect(objEnemy,144, 234, 282, 431);}
		if(af2>24){ObjSprite2D_SetSourceRect(objEnemy,144, 234, 282, 431);}
		if(af2>36){af1=0;}
		af2++;}

	af1++;
	if(af1>120){af1=0;}yield;}}


task end{
	while(ObjEnemy_GetInfo(objEnemy,INFO_LIFE)>0){yield;}
	
	
	DeleteShotAll(TYPE_ALL,TYPE_ITEM);
	Obj_Delete(objEnemy);
	yield;
	CloseScript(GetOwnScriptID);}

@Event{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){SetScriptResult(1800);}
	case(EV_REQUEST_TIMER){SetScriptResult(50);}
	case(EV_REQUEST_SPELL_SCORE){SetScriptResult(15000);}}

	
	
	let ggg=0;
	let ggg2=0;
	let ttt=0;
	let ttt2=0;
	task flow2{
	
	
	
let bu11=CreateShotA1(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy), 2.6, 90+29, 30, 10);
let bu111=CreateShotA1(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy), 2.6, 90-29, 30, 10);
ObjShot_SetSpellResist(bu11,true);
ObjShot_SetSpellResist(bu111,true);


	wait(110);
loop(26){

ObjMove_SetSpeed(bu11,ObjMove_GetSpeed(bu11)-0.1);
ObjMove_SetSpeed(bu111,ObjMove_GetSpeed(bu111)-0.1);
wait(3);


}
let spp=1;
let lal=0;
let spp2=0;

task sk{loop{yield;lal+=2;}}
sk;
lll(bu11);
lll(bu111);
task lll(oo){
loop{
let we=CreateShotA1(ObjMove_GetX(oo),ObjMove_GetY(oo), spp, 0+5*cos(lal), 239, 10);
let wee=CreateShotA1(ObjMove_GetX(oo),ObjMove_GetY(oo), spp, 0+5*cos(lal)-45, 239, 10);
let weee=CreateShotA1(ObjMove_GetX(oo),ObjMove_GetY(oo), spp, 0+5*cos(lal)-90, 239, 10);
let weeee=CreateShotA1(ObjMove_GetX(oo),ObjMove_GetY(oo), spp, 0+5*cos(lal)-135, 239, 10);
let weeeee=CreateShotA1(ObjMove_GetX(oo),ObjMove_GetY(oo), spp, 0+5*cos(lal)-180, 239, 10);
let weeeeee=CreateShotA1(ObjMove_GetX(oo),ObjMove_GetY(oo), spp, 0+5*cos(lal)-225, 239, 10);
let weeeeeee=CreateShotA1(ObjMove_GetX(oo),ObjMove_GetY(oo), spp, 0+5*cos(lal)-270, 239, 10);
let weeeeeeee=CreateShotA1(ObjMove_GetX(oo),ObjMove_GetY(oo), spp, 0+5*cos(lal)-315, 239, 10);


wait(5);spp+=spp2;spp2+=0.02;if(spp>4){spp=4;}
	}
	
	
	}}
	
	
task flow{





loop(10){


let bu11=CreateShotA1(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy), 1.3, ggg+ggg2, 22, 10);
let bu111=CreateShotA1(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy), 1.27, ggg+ggg2+5, 22, 10);
let bu1111=CreateShotA1(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy), 1.27, ggg+ggg2-5, 22, 10);

let ds=CreateShotA1(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy), 1.24, ggg+ggg2+10, 22, 10);
let sd=CreateShotA1(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy), 1.24, ggg+ggg2-10, 22, 10);


let ds1=CreateShotA1(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy), 1.21, ggg+ggg2+15, 22, 10);
let sd1=CreateShotA1(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy), 1.21, ggg+ggg2-15, 22, 10);



back(sd1,0.075,20);
back(ds1,0.075,20);
back(bu11,0.1,23);
back(bu111,0.095,21);
back(bu1111,0.095,21);
back(ds,0.085,23);
back(sd,0.085,23);



ggg+=360/10;


}


task back(oo,wa,gra){





task check{wait(30);
loop{
yield;
if(ObjMove_GetX(oo)<ObjMove_GetX(objEnemy)+2 && ObjMove_GetX(oo)>ObjMove_GetX(objEnemy)-2 && ObjMove_GetY(oo)<ObjMove_GetY(objEnemy)+2 && ObjMove_GetY(oo)>ObjMove_GetY(objEnemy)-2  ){
Obj_Delete(oo);

}

}

}



check;
ObjShot_SetAutoDelete(oo,false);
wait(240);ObjShot_SetGraphic(oo,gra);PlaySE(ki);
loop(10){ObjMove_SetSpeed(oo,ObjMove_GetSpeed(oo)-wa);wait(3);}


loop(30){ObjMove_SetSpeed(oo,ObjMove_GetSpeed(oo)-wa);wait(3);}

}


ggg2+=12.5678478;



}
	
	
	
	

	
	
	
	
	

let ang=0;
let ang2=0;
task sss{












let bg1q=ObjPrim_Create(OBJ_SPRITE_2D);
bax(bg1q);
ObjPrim_SetTexture(bg1q,bg);
ObjSprite2D_SetSourceRect(bg1q,0,0,1024,1024);
ObjRender_SetAlpha(bg1q,255);
ObjSprite2D_SetDestCenter(bg1q);
ObjRender_SetPosition(bg1q,GetStgFrameWidth/2,GetStgFrameHeight/2,0);



/////


let qw=ObjPrim_Create(OBJ_SPRITE_2D);

ObjPrim_SetTexture(qw,bg2);
ObjSprite2D_SetSourceRect(qw,20000,20000,1024,20024);
ObjRender_SetAlpha(qw,155);
ObjSprite2D_SetDestCenter(qw);
ObjRender_SetPosition(qw,GetStgFrameWidth/2,GetStgFrameHeight/2,0);
baxx(qw);




////
let hhh=0;
task bax(vv){
while(!Obj_IsDeleted(vv)){
yield;
ObjRender_SetAlpha(bg1q,255);

ObjRender_SetAngleZ(bg1q,3*cos(hhh*5)+5);
hhh+=0.1;
}
}


task baxx(vv){let gg=0;
while(!Obj_IsDeleted(vv)){
yield;
	ObjSprite2D_SetSourceRect(vv,20000,20000,256,256);
	ObjSprite2D_SetDestCenter(vv);
	ObjRender_SetPosition(vv,0,gg,0);
			gg+=-0.5;
hhh+=0.1;
}
}




ObjRender_SetScaleXYZ(bg1q,0.7,0.7,0);

Obj_SetRenderPriorityI(bg1q,20);


ObjRender_SetScaleXYZ(qw,0.7,0.7,0);
ObjRender_SetBlendType(qw,BLEND_MULTIPLY);
Obj_SetRenderPriorityI(qw,20);






}

task move{
	
	
	wait(120);
	
	
	
af3=1;
wait(15);
PlaySE(boo);sss;
ObjCutin_SetSpellcardS4(" Necessity '' Cautious oxygen containment '' ", cut, NAZRIN, 240, 104, 104);
ObjCutin_LaunchS3(NAZRIN, cut, "normal");


wait(60);


	PlaySE(cha);
	MakeConcentration("SAKURA",objEnemy,155,155,255,50);
	
wait(90);

MakeExplosion("SAKURA",objEnemy,155,155,255);
PlaySE(cha2);

af3=1;
wait(5);
flow;
flow2;
wait(360);
//
PlaySE(cha);
	MakeConcentration("SAKURA",objEnemy,155,155,255,50);
	
wait(90);


dam=1;MakeExplosion("SAKURA",objEnemy,155,155,255);
PlaySE(cha2);

af3=1;


loop{flow;wait(60);}

	
	}

	
	
	task bullet(ang){
	
	}
	///
	
	
@MainLoop{yield;
	SetAutoDeleteObject(true);
	if(dam==0){ObjEnemy_SetDamageRate(objEnemy,0,0);}
	if(dam==1){ObjEnemy_SetDamageRate(objEnemy,25,10);}
	let ex = ObjMove_GetX(objEnemy);
	let ey = ObjMove_GetY(objEnemy);

	let px = GetPlayerX();
	let py = GetPlayerY();
	let ATP = atan2(py - ey, px - ex);


ObjEnemy_SetIntersectionCircleToShot(objEnemy, ex, ey, 32);
ObjEnemy_SetIntersectionCircleToShot(objEnemy, ex, ey+30, 20);
ObjEnemy_SetIntersectionCircleToShot(objEnemy, ex, ey+60, 10);
ObjEnemy_SetIntersectionCircleToPlayer(objEnemy, ex, ey, 32);
ObjEnemy_SetIntersectionCircleToPlayer(objEnemy, ex, ey+20, 20);
ObjEnemy_SetIntersectionCircleToPlayer(objEnemy, ex, ey+30, 10);
ObjEnemy_SetIntersectionCircleToPlayer(objEnemy, ex, ey+40, 10);
ObjEnemy_SetIntersectionCircleToPlayer(objEnemy, ex, ey+50, 5);
ObjEnemy_SetIntersectionCircleToPlayer(objEnemy, ex, ey-20,32);
frame++;}