//#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;

task bullet2{
	
	
	
	}
    let sc=0;
    let sc2=0;
	
	
	let xx=150;
	let yy=100;let nap=0;
task bullet{

    task sccc{loop{yield;sc+=6;}}
    sccc;
	
    task sccc2{loop{yield;sc2+=6;}}
    sccc2;

	af3=1;
	t=0;
	
	
	task sko(ik){
	let as=rand(0.05,0.058);
	let as2=rand(-1,1);
	
	
wait(60);
task anl{wait(180);

loop(30){


ObjMove_SetAngle(ik,ObjMove_GetAngle(ik)+as2);

wait(5);

}


}
anl;
loop(60){
ObjMove_SetSpeed(ik,ObjMove_GetSpeed(ik)+as/4);

wait(4);

}}




task sko2(ik){
	let as=rand(0.05,0.058);
	let as2=rand(-1,1);
	
	
wait(60);
task anl{wait(180);

loop(30){


ObjMove_SetAngle(ik,ObjMove_GetAngle(ik)-as2);

wait(5);

}


}
anl;dam=1;
loop(60){
ObjMove_SetSpeed(ik,ObjMove_GetSpeed(ik)+as/4);

wait(4);

}}
	
	
	loop{
	yield;
	
	
	
	nap=1;af3=1;
	loop(120){PlaySE(ki);
    
    let obj21=CreateShotA1(ObjMove_GetX(objEnemy)+xx*cos(sc),
	ObjMove_GetY(objEnemy)+yy*sin(sc), 0, +ff+90, round(rand(233,240)), 10);
	
	 let obj211=CreateShotA1(ObjMove_GetX(objEnemy)-xx*cos(sc),
	ObjMove_GetY(objEnemy)-yy*sin(sc), 0, +ff-90,  round(rand(233,240)), 10);
	
	
	
	 let obj2111=CreateShotA1(ObjMove_GetX(objEnemy)-xx*sin(sc),
	ObjMove_GetY(objEnemy)+yy*cos(sc), 0, +ff+180,  round(rand(233,240)), 10);
	
	
	 let obj21111=CreateShotA1(ObjMove_GetX(objEnemy)+xx*sin(sc),
	ObjMove_GetY(objEnemy)-yy*cos(sc), 0, +ff,  round(rand(233,240)), 10);
	
	sko(obj21);
	sko(obj211);
	sko(obj2111);
	sko(obj21111);
	
	
	
	
    xx+=-150/120;
    yy+=-100/120;
    ff+=5.9999999999999;
    wait(1);

    }
	af3=0;
	xx=150;
	yy=100;
	
	wait(180);
	af3=1;
	
	nap=2;
	loop(120){PlaySE(ki);
    
    let obj321=CreateShotA1(ObjMove_GetX(objEnemy)-xx*cos(sc),
	ObjMove_GetY(objEnemy)+yy*sin(sc), 0, -ff2+90, round(rand(233,240)), 10);
	
	 let obj3211=CreateShotA1(ObjMove_GetX(objEnemy)+xx*cos(sc),
	ObjMove_GetY(objEnemy)-yy*sin(sc), 0, -ff2+90+180,  round(rand(233,240)), 10);
	
	
	
	 let obj32111=CreateShotA1(ObjMove_GetX(objEnemy)+xx*sin(sc),
	ObjMove_GetY(objEnemy)+yy*cos(sc), 0, -ff2+90+90+180,  round(rand(233,240)), 10);
	
	
	let obj321111=CreateShotA1(ObjMove_GetX(objEnemy)-xx*sin(sc),
	ObjMove_GetY(objEnemy)-yy*cos(sc), 0, -ff2+180,  round(rand(233,240)), 10);
	
	sko2(obj321);
	sko2(obj3211);
	sko2(obj32111);
	sko2(obj321111);
	
	
	
	
    xx+=-150/120;
    yy+=-100/120;
   ff2+=5.9999999999999;
     wait(1);

    }xx=150;
	yy=100;
	af3=0;
	wait(180);
	
	
	xx=150;
	yy=100;
	
	//wait(180);
	af3=1;
	
	nap=2;
	loop(120){PlaySE(ki);
    
    let obj321=CreateShotA1(ObjMove_GetX(objEnemy)-xx*cos(sc),
	ObjMove_GetY(objEnemy)+yy*sin(sc), 0, ff2+270, round(rand(233,240)), 10);
	
	 let obj3211=CreateShotA1(ObjMove_GetX(objEnemy)+xx*cos(sc),
	ObjMove_GetY(objEnemy)-yy*sin(sc), 0, ff2-270,  round(rand(233,240)), 10);
	
	
	
	 let obj32111=CreateShotA1(ObjMove_GetX(objEnemy)+xx*sin(sc),
	ObjMove_GetY(objEnemy)+yy*cos(sc), 0, ff2+180,  round(rand(233,240)), 10);
	
	
	let obj321111=CreateShotA1(ObjMove_GetX(objEnemy)-xx*sin(sc),
	ObjMove_GetY(objEnemy)-yy*cos(sc), 0, ff2,  round(rand(233,240)), 10);
	
	sko2(obj321);
	sko2(obj3211);
	sko2(obj32111);
	sko2(obj321111);
	
	
	
	
    xx+=-150/120;
    yy+=-100/120;
   ff2+=5.9999999999999;
     wait(1);

    }xx=150;
	yy=100;
	af3=0;
	wait(180);
	af3=1;
	
	}
	
	}
	
	

////////////////////////////////////////////////////////////////////////////////////////
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;


task move{
	
	wait(120);
	StarConcentration(objEnemy,90);
	PlaySE(cha);
	wait(120);
	bullet;
	}

@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, 32);
ObjEnemy_SetIntersectionCircleToPlayer(objEnemy, ex, ey, 32);
ObjEnemy_SetIntersectionCircleToPlayer(objEnemy, ex, ey+20, 32);
ObjEnemy_SetIntersectionCircleToPlayer(objEnemy, ex, ey-20,32);
frame++;}