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

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

#include"./Effects/Effects.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_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_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, 140, 10,3);
	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)){yield;
	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){
		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>40){
		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;}}}


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(2100);}
	case(EV_REQUEST_TIMER){SetScriptResult(30);}
	case(EV_REQUEST_SPELL_SCORE){SetScriptResult(15000);}}
let anglel=0;

let ang=0;
let ang2=0;

let speed1=rand(0.5,2);

task move{
	
	PlaySE(bgam);
	wait(120);
	
	
	tra(3);
	PlaySE(cha);
	MakeConcentration("SAKURA",objEnemy,155,155,255,50);
	
wait(90);


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


af3=1;
wait(15);
let wa=10;
gg=0.5;
r=10;
loop(5){
	
	bullet2(anglel,21);
anglel+=9.7458787/2;
wait(6);gg+=0.05;wa+=-0.9;
}
loop(5){
	
	bullet2(anglel,21);
anglel+=9.7458787/2;
wait(6);gg+=0.05;wa+=-0.9;
}gg=0.5;



	wait(120);




loop{




	
	
	
	circl;
	ObjMove_SetDestAtWeight(objEnemy, GetStgFrameWidth/2+rand(0,40),  GetStgFrameHeight/2-rand(40,80), 20,2);
	wait(120);
	
af3=1;
wait(15);

loop(5){
	
	bullet2(anglel,21);
anglel+=9.7458787/2;
wait(6);gg+=0.05;wa+=-0.9;
}
loop(5){
	
	bullet2(anglel,21);
anglel+=9.7458787/2;
wait(6);gg+=0.05;wa+=-0.9;
}gg=0.5;

	wait(60);
	circl;
	ObjMove_SetDestAtWeight(objEnemy, GetStgFrameWidth/2-rand(0,40),  GetStgFrameHeight/2-rand(40,80), 20,2);
	wait(120);
	
af3=1;
wait(15);

loop(5){
	
	bullet2(anglel,21);
anglel+=9.7458787/2;
wait(6);gg+=0.05;wa+=-0.9;
}
loop(5){
	
	bullet2(anglel,21);
anglel+=9.7458787/2;
wait(6);gg+=0.05;wa+=-0.9;
}gg=0.5;

wait(60);

	
	}
}
	let aa=0;
	let aaa=0;
	task circl{
	
	loop(15){
	
	
	let bub=CreateShotA1(ObjRender_GetX(objEnemy)-33,ObjRender_GetY(objEnemy)-22, 1.5, aa+aaa, 169, 10);
	aa+=360/15;
	
	}
	aaa+=16.987654567;
	}
	
	
	
	let angle=0;
	let tut=0;
	let tut1=0;
	let tut11=0;
	let r=25;
	let a=0;
	let spp=0;
	
	task tra(df){
	
	
	}
let dsa=0;
	
	
	task bullet2(ang,gra){
	PlaySE(ki);let fff=rand(-1,1);
	
	let angle2=rand(0,360);
	loop(6){
	
	
	
	
	
	loop(4){
	
	
	
	
	let bub=CreateShotA1(ObjRender_GetX(objEnemy)-33+(r+10)*cos(tut),ObjRender_GetY(objEnemy)-22+(r+10)*sin(tut), gg, ang+angle, gra+1, 10);
	let bub2=CreateShotA1(ObjRender_GetX(objEnemy)-33,ObjRender_GetY(objEnemy)-22, gg, ang+angle, 128, 10);
	
	let bub3=CreateShotA1(ObjRender_GetX(objEnemy)-33+r*cos(tut),ObjRender_GetY(objEnemy)-22+r*sin(tut), gg, ang+angle, gra, 10);
	let bub23=CreateShotA1(ObjRender_GetX(objEnemy)-33,ObjRender_GetY(objEnemy)-22, gg, ang+angle, 128, 10);
	
	
	
	angle+=360/4;
	ObjShot_SetAutoDelete(bub,false);
	ObjShot_SetAutoDelete(bub2,false);
	ObjShot_SetAutoDelete(bub3,false);
	ObjShot_SetAutoDelete(bub23,false);
	gf(bub);
	gf(bub2);
	gf(bub23);
	gf(bub3);
	gf2(bub23);
	gf2(bub3);
	gf3(bub,bub2);
	
	task kk(t,o,y,u){wait(180);
ObjShot_SetAutoDelete(t,true);
	ObjShot_SetAutoDelete(o,true);
	ObjShot_SetAutoDelete(y,true);
	ObjShot_SetAutoDelete(u,true);
	
	
	}
	
	
	kk(bub3,bub23,bub,bub2);
	
	}
	
	
	task gf3(i,o){
	wait(180);
	
	ObjMove_SetAngle(i,atan2(ObjMove_GetY(o)-ObjMove_GetY(i),ObjMove_GetX(o)-ObjMove_GetX(i)));
	ObjMove_SetAngle(o,ObjMove_GetAngle(o)+0);
	PlaySE(ki);
	loop(30){
	
	ObjMove_SetSpeed(i,ObjMove_GetSpeed(i)+0.04);
	ObjMove_SetSpeed(o,ObjMove_GetSpeed(i)+0.02);
	ObjShot_SetGraphic(i,gra+1);
	
	
	
	
	wait(3);}}
	
	task gf2(i){
	wait(180);
	
	loop(30){
	
	ObjMove_SetSpeed(i,ObjMove_GetSpeed(i)-0.08);

	
	wait(3);}
	
	}
	
	
	task gf(i){
	let tt = ObjMove_GetSpeed(i)/30;

	wait(90);
	
	loop(30){
	
	ObjMove_SetSpeed(i,ObjMove_GetSpeed(i)-tt);
	
	wait(3);}
	
	
	/*loop(30){
	
	ObjMove_SetSpeed(i,ObjMove_GetSpeed(i)-0.1);
	
	wait(3);}*/
	}
	
	
	
	tut+=360/6;
	}tut+=18.56789;

	wait(10);
	
	
	
	
	}
	///
	
	
@MainLoop{yield;
	SetAutoDeleteObject(true);
	if(dam==0){ObjEnemy_SetDamageRate(objEnemy,0,0);}
	if(dam==1){ObjEnemy_SetDamageRate(objEnemy,45,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++;}