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

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

let cut = GetCurrentScriptDirectory ~ "KeCut.png" ;
let cir = GetCurrentScriptDirectory ~ "circle.png" ;
let bg = GetCurrentScriptDirectory ~ "sp2.png" ;
let bg2 = GetCurrentScriptDirectory ~ "bg2.png" ;
let cha = GetCurrentScriptDirectory ~ "./Sounds/se_ch00.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_boon01.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);
	move;
	LoadSound(cha);
	LoadSound(tana);
	LoadSound(boo);
	LoadSound(bgam);
	LoadSound(ki);
PlaySE(bgam);
	
TExplosionA(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),5,1);
TExplosionA(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),2,0.1);

	end;
back;

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

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);
	ObjPrim_SetTexture(bg133,cir);
	ObjSprite2D_SetSourceRect(bg133,0,0,128,127);
	ObjSprite2D_SetDestCenter(bg133);
	////
	let bg1333=ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(bg1333,cir);
	ObjSprite2D_SetSourceRect(bg1333,0,0,128,127);
	ObjSprite2D_SetDestCenter(bg1333);

	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+sin(hh),1+sin(hh),0);
		if(hh<180){hh+=0.5;}else{hh=0;}
			Obj_SetRenderPriorityI(bg133,22);
			ObjRender_SetAlpha(bg133,133);
			////
			ObjRender_SetPosition(bg1333,ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),0);
			ObjRender_SetAngleZ(bg1333,-asd2/2);
			ObjRender_SetScaleXYZ(bg1333,1+sin(hh),1+sin(hh),0);
			Obj_SetRenderPriorityI(bg1333,22);
			ObjRender_SetAlpha(bg1333,133);
			asd2+=6;}}}
let dir;
	let speed;
	let time=0;
task animate{

	
	
	
	
	

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

	if(speed==0){
		if(af3==1){time++;

		if(time<130){ObjSprite2D_SetSourceRect(objEnemy,378, 257, 512, 447);}
		if(time>=12+130 && af1<=24+130){ObjSprite2D_SetSourceRect(objEnemy,518,257, 651, 447);}
		if(time>=25+130){ObjSprite2D_SetSourceRect(objEnemy,378, 257, 512, 447);wait(13);time=0;}
		}
	else{
		if(af1<15){ObjSprite2D_SetSourceRect(objEnemy,11, 1, 147, 192);}
		if(af1>=30+120 && af1<=45+120){ObjSprite2D_SetSourceRect(objEnemy,170,6, 305, 194);}
		if(af1>=46+120){ObjSprite2D_SetSourceRect(objEnemy,317, 6, 453, 192);}
		if(af1>=62+120){ObjSprite2D_SetSourceRect(objEnemy,170,6, 305, 194);}}}

	if(speed>0 && cos(dir)>0 ){
		ObjRender_SetAngleY(objEnemy,0);
		if(af2>12){ObjSprite2D_SetSourceRect(objEnemy,11, 198, 146, 388);}
		if(af2>24){ObjSprite2D_SetSourceRect(objEnemy,159, 215, 293, 403);}
		if(af2>36){af1=0;}
		af2++;}

	if(speed>0 && cos(dir)<0 ){
		ObjRender_SetAngleY(objEnemy,180);
		if(af2>12){ObjSprite2D_SetSourceRect(objEnemy,11, 198, 146, 388);}
		if(af2>24){ObjSprite2D_SetSourceRect(objEnemy,159, 215, 293, 403);}
		if(af2>36){af1=0;}
		af2++;}

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


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

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


let ang=0;
let ang2=0;
let and=0;
let and2=0;
let ch=0;

//////
task fir22{


task inn(obj){

wait(60);
PlaySE(ki);
ObjMove_SetSpeed(obj,0);
wait(30);



loop(120){


ObjMove_SetAngle(obj,ObjMove_GetAngle(obj)+1);

ObjMove_SetSpeed(obj,ObjMove_GetSpeed(obj)+(0.03));


wait(4);}


}

let hhh=0;
task inn2(obj2){


wait(60);
PlaySE(ki);
ObjMove_SetSpeed(obj2,0);
wait(30);



loop(120){

if(hhh==0){

ObjMove_SetAngle(obj2,ObjMove_GetAngle(obj2)+1.5);

ObjMove_SetSpeed(obj2,ObjMove_GetSpeed(obj2)+(0.06));
}else{break;}

wait(4);}


}

//////////////
//objenemy//let objPL;
//int//objPL=GetPlayerObjectID();
//ObjMove_SetX(objPL,data);
//
//////////////

let gg=20;
task chas(q){

loop(320){yield;
if(hhh==33){
PlaySE(ki);hhh=1;
ObjMove_SetSpeed(q,0);
ObjShot_SetGraphic(q,round(rand(17,24)));
loop(60){yield;ObjMove_SetSpeed(q,0);}

ss;

task ss{
loop(20){wait(3);
ObjMove_SetAngle(q,atan2(GetPlayerY - ObjMove_GetY(q), GetPlayerX - ObjMove_GetX(q)));break;}
}


loop(120){



ObjMove_SetSpeed(q,ObjMove_GetSpeed(q)+(0.015));


wait(4);


}


break;
}

}}


loop(15){





let obj271=CreateShotA1(ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), 0.5, and+and2, 24, 10);

Obj_SetRenderPriorityI(obj271,59);
let obj2711=CreateShotA1(ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), 0.5, and+and2+180, 31, 10);



chas(obj271);


inn(obj271);
inn(obj2711);







//let obj277=CreateShotA1(ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), 4, and+and2+180, DS_LIGHT_BLUE, 10);


and+=360/15;
}

}
//////
task fir{


task inn(obj){

wait(60);
PlaySE(ki);
ObjMove_SetSpeed(obj,0);
wait(30);



loop(120){


ObjMove_SetAngle(obj,ObjMove_GetAngle(obj)-1);

ObjMove_SetSpeed(obj,ObjMove_GetSpeed(obj)+(0.03));


wait(4);}


}

let hhh=0;
task inn2(obj2){


wait(60);
PlaySE(ki);
ObjMove_SetSpeed(obj2,0);
wait(30);



loop(120){

if(hhh==0){

ObjMove_SetAngle(obj2,ObjMove_GetAngle(obj2)+1.5);

ObjMove_SetSpeed(obj2,ObjMove_GetSpeed(obj2)+(0.06));
}else{break;}

wait(4);}


}

//////////////
//objenemy//let objPL;
//int//objPL=GetPlayerObjectID();
//ObjMove_SetX(objPL,data);
//
//////////////

let gg=20;
task chas(q){

loop(320){yield;
if(hhh==34){
PlaySE(ki);hhh=1;
ObjMove_SetSpeed(q,0);
ObjShot_SetGraphic(q,round(rand(17,24)));
loop(60){yield;ObjMove_SetSpeed(q,0);}

ss;

task ss{
loop(20){wait(3);
ObjMove_SetAngle(q,atan2(GetPlayerY - ObjMove_GetY(q), GetPlayerX - ObjMove_GetX(q)));}
}


loop(120){



ObjMove_SetSpeed(q,ObjMove_GetSpeed(q)+(0.005));


wait(4);


}


break;
}

}}


loop(15){





let obj271=CreateShotA1(ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), 0.5, and+and2, 24, 10);

Obj_SetRenderPriorityI(obj271,59);
let obj2711=CreateShotA1(ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), 0.5, and+and2+180, 31, 10);



chas(obj271);


inn(obj271);
inn(obj2711);







//let obj277=CreateShotA1(ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), 4, and+and2+180, DS_LIGHT_BLUE, 10);


and+=360/15;
}

}


let yy=0;
task fir2{

loop(15){





let obj2711=CreateShotA1(ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), 1, yy+and2, 184, 10);

and2+=360/15;
}yy+=19.76889;

}

task move{
	
	wait(120);
	StarConcentration(objEnemy,90);
	PlaySE(cha);
	wait(120);
	
	loop{
	PlaySE(tana);
	fir;dam=1;
	wait(10);and2+=5.45645;
	PlaySE(tana);
	fir22;
	wait(10);and2+=5.45645;
	PlaySE(tana);
	fir;
	
	wait(10);and2+=5.45645;
	PlaySE(tana);
	fir22;
	
	wait(10);and2+=16.45645;

PlaySE(tana);
	fir;
	wait(10);and2+=5.45645;
	PlaySE(tana);
	fir22;
	wait(20);and2+=5.45645;
	PlaySE(tana);
	fir;
	
	wait(30);and2+=5.45645;
	PlaySE(tana);
	fir22;
	fir2;
	wait(40);and2+=5.45645;

	}
	}

@MainLoop{yield;
	SetAutoDeleteObject(true);
	if(dam==0){ObjEnemy_SetDamageRate(objEnemy,0,0);}
	if(dam==1){ObjEnemy_SetDamageRate(objEnemy,40,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, 32);
ObjEnemy_SetIntersectionCircleToPlayer(objEnemy, ex, ey, 32);
ObjEnemy_SetIntersectionCircleToPlayer(objEnemy, ex, ey+20, 32);
ObjEnemy_SetIntersectionCircleToPlayer(objEnemy, ex, ey-20,32);
frame++;}