 //#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Non3"]
#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_c1ardget.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;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(objEnemy)){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,-32,-32+5*sin(h),32,32+5*sin(h));
	ObjRender_SetScaleXYZ(objEnemy,1.1,1.1,0);
	dir=ObjMove_GetAngle(objEnemy);
	speed=ObjMove_GetSpeed(objEnemy);
	h+=4;

	if(speed==0){af1=1;
		if(af3==1){time++;ObjRender_SetAngleY(objEnemy,0);
		
af1=0;
		if(time<7){ObjSprite2D_SetSourceRect(objEnemy,64, 0, 128, 64);}
		if(time>=7+1 && af1<=7+5+1){ObjSprite2D_SetSourceRect(objEnemy,128,0, 192, 64);}
		if(time>=14+1 && af1<=15+1){ObjSprite2D_SetSourceRect(objEnemy,192,0, 256, 64);
		
		
		
if(time>20){wait(30);
ObjSprite2D_SetSourceRect(objEnemy,128,0, 192, 64);
wait(7);
ObjSprite2D_SetSourceRect(objEnemy,64, 0, 128, 64);
wait(7);
		time=0;
		af3=0;}
		
		
		
		
		}
		
		}
	else{ObjRender_SetAngleY(objEnemy,0);
		
	
if(af1<15){af2=0;ObjSprite2D_SetSourceRect(objEnemy,0, 0, 64, 64);}
		
		}


		}

	if(speed>0 && cos(dir)>0 ){
		ObjRender_SetAngleY(objEnemy,0);
		if(af2>7){ObjSprite2D_SetSourceRect(objEnemy,0, 64, 64, 128);}
		if(af2>14){ObjSprite2D_SetSourceRect(objEnemy,64, 64, 128,128);}
		if(af2>21){ObjSprite2D_SetSourceRect(objEnemy,128, 64, 192,128);}
		if(af2>28){ObjSprite2D_SetSourceRect(objEnemy,192, 64, 256,128);}
		if(af2>45){af1=1;}
		af2++;}

	if(speed>0 && cos(dir)<0 ){
		ObjRender_SetAngleY(objEnemy,180);
		if(af2>7){ObjSprite2D_SetSourceRect(objEnemy,0, 64, 64, 128);}
		if(af2>14){ObjSprite2D_SetSourceRect(objEnemy,64, 64, 128,128);}
		if(af2>21){ObjSprite2D_SetSourceRect(objEnemy,128, 64, 192,128);}
		if(af2>28){ObjSprite2D_SetSourceRect(objEnemy,192, 64, 256,128);}
		if(af2>45){af1=1;}
		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);
	SetAutoDeleteObject(true);
	CloseScript(GetOwnScriptID);}

@Event{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){SetScriptResult(1300);}
	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 sp{
	let so = GetCurrentScriptDirectory ~ "./Sounds/se_break.wav";
	let obj = ObjSound_Create;
	ObjSound_Load(obj,so);
	ObjSound_Play(obj);
	ObjSound_SetVolumeRate(obj,60);}
task move{
	
	
	
MakeExplosion("MAPLE",objEnemy,rand(55,255),rand(55,255),rand(55,255));
MakeExplosion("MAPLE",objEnemy,rand(55,255),rand(55,255),rand(55,255));
sp;
	
	
	wait(120);
	
	loop{
	charge;
	
	MakeConcentration("MAPLE",objEnemy,0,255,55,60);
wait(90);

af3=1;
wait(15);dam=1;
fire;
	wait(45);
	spawn=1;
	
	wait(30);
	charge;
	
	MakeConcentration("MAPLE",objEnemy,0,255,55,60);
wait(90);

af3=1;
wait(15);
bax=1;
tank2;
wait(90);
bax=0;
r=0;
let xx=0;
let yy=0;
let choose=0;
choose=round(rand(0,1));

if(ObjMove_GetX(objEnemy)<192 && choose==1){choose=0;}
if(ObjMove_GetX(objEnemy)>192 && choose==0){choose=1;}
if(choose==1){xx=rand(-30,-10);yy=rand(-20,-10)}
if(choose==0){xx=rand(30,10);yy=rand(20,10)}




ring;
wait(10);
ObjMove_SetDestAtWeight(objEnemy, 192+xx, 140+xx, 10,1);
wait(90);

	
	
	}
	
	
	}
	
let rangle=0;
let rang=0;
	task ring{wait(10);
	let asd=0;
	
	loop(5){tank;
	loop(55){
	
	let qwe=CreateShotA1(ObjRender_GetX(objEnemy),ObjRender_GetY(objEnemy), 4-asd, rangle+rang, 44, 5);
	let qwe2=CreateShotA1(ObjRender_GetX(objEnemy),ObjRender_GetY(objEnemy), 4-asd, rangle+rang, 44, 5);
	rangle+=360/55;
	slow;
	task slow{
	
	loop(28){
	ObjMove_SetSpeed(qwe,ObjMove_GetSpeed(qwe)-0.1);
	ObjMove_SetSpeed(qwe2,ObjMove_GetSpeed(qwe2)-0.1);
	wait(2);}
	loop(30){
	
	ObjMove_SetAngle(qwe,ObjMove_GetAngle(qwe)-2.10);
	ObjMove_SetAngle(qwe2,ObjMove_GetAngle(qwe2)+2.10);

	wait(2);}
	loop(30){
	
	ObjMove_SetAngle(qwe,ObjMove_GetAngle(qwe)+1.10);
	ObjMove_SetAngle(qwe2,ObjMove_GetAngle(qwe2)-1.10);

	wait(2);}
	
	}
	
	}rang+=14.876545678;
	wait(8);asd+=+0.1;
	}
	
	wait(10);asd+=+0.1;
	}
	
	
	
	
	
	
task kur{
	let so = GetCurrentScriptDirectory ~ "./Sounds/se_kira00.wav";
	let obj = ObjSound_Create;
	ObjSound_Load(obj,so);
	ObjSound_Play(obj);
	ObjSound_SetVolumeRate(obj,80);}
let bax=0;
	let spawn=0;let angle2=0;
	let angle=0;
	let angel=0;
	let r=0;
	let lol=0;
	task fire{kur;
	
	
	let suk=rand(4,120);
	
	let qwe=CreateShotA1(ObjRender_GetX(objEnemy)+(r)*cos(tut),ObjRender_GetY(objEnemy)+(r)*sin(tut), 0, ang-angle, 168, 5);
	mocer(qwe);
	
	let qwe2=CreateShotA1(ObjRender_GetX(objEnemy)-(r)*cos(tut),ObjRender_GetY(objEnemy)-(r)*sin(tut), 0, ang-angle, 168, 5);
	mocer(qwe2);
	
	let qwer=CreateShotA1(ObjRender_GetX(objEnemy)-(r)*cos(tut),ObjRender_GetY(objEnemy)-(r)*sin(tut), 0, ang-angle, 168, 5);
	mocer(qwer);
	
	
	let qwer2=CreateShotA1(ObjRender_GetX(objEnemy)-(r)*cos(tut),ObjRender_GetY(objEnemy)-(r)*sin(tut), 0, ang-angle, 168, 5);
	mocer(qwer2);
	
	
	let qwer22=CreateShotA1(ObjRender_GetX(objEnemy)-(r)*cos(tut),ObjRender_GetY(objEnemy)-(r)*sin(tut), 0, ang-angle, 168, 5);
	mocer(qwer22);
	
	task kkk{
	let as=2/60;
	let as2=0;
	loop(88){yield;angel+=2;}
	loop(60){yield;angel+=2-as2;as2+=as;}angel=0;
	}
	kkk;
	
	
	task mocer(x){
	ObjShot_SetSpellResist(x,true);
	
	grow;
	task grow{
	let z=0;
	loop(100){ObjRender_SetScaleXYZ(x,0+z,0+z,0+z);
	z+=0.01;
	yield;
	}
	let povorot=0;
	loop{if(bax==1){
	
	let spp=1.5;
	let lol=0;
	
	
	if(ObjMove_GetX(x)<ObjMove_GetX(objEnemy)-10 && ObjMove_GetY(x)>ObjMove_GetY(objEnemy)){
	
	povorot+=suk;
	}
	if(ObjMove_GetX(x)>ObjMove_GetX(objEnemy)+10 && ObjMove_GetY(x)>ObjMove_GetY(objEnemy)){
	
	povorot+=-suk;
	}
	
	if(ObjMove_GetX(x)>ObjMove_GetX(objEnemy) && ObjMove_GetY(x)<ObjMove_GetY(objEnemy)){
	
	povorot+=suk;
	}
	if(ObjMove_GetX(x)<ObjMove_GetX(objEnemy) && ObjMove_GetY(x)<ObjMove_GetY(objEnemy)){
	
	povorot+=-suk;
	}
	
	let a=2;
TExplosionA(ObjMove_GetX(x),ObjMove_GetY(x),5,0.1);
spp=3;
let lol2=0;
loop(10){

	loop(10){
	
	let qwe=CreateShotA1(ObjRender_GetX(x),ObjRender_GetY(x), spp, ang-angle, 12, 10);
	ObjMove_SetAngle(qwe,ang+atan2(ObjRender_GetY(objEnemy)-ObjRender_GetY(qwe),ObjRender_GetX(objEnemy)-ObjRender_GetX(qwe))+180+lol+lol2+lol22);
	
	
	
	
	lol+=-0.96545678;
	spp+=-0.02;
	}
	
	lol2+=30;
	}
	
	ObjMove_SetAngle(x,atan2(ObjRender_GetY(objEnemy)-ObjRender_GetY(x),ObjRender_GetX(objEnemy)-ObjRender_GetX(x)));
	
	loop(69){
	
	
	ObjMove_SetSpeed(x,ObjMove_GetSpeed(x)+0.05);
	ObjMove_SetAngle(x,ObjMove_GetAngle(x)-0.5);
	wait(1);
	}
	loop(30){
	
	ObjMove_SetAngle(x,ObjMove_GetAngle(x)+1);
	ObjMove_SetSpeed(x,ObjMove_GetSpeed(x)-0.1);
	wait(1);
	}
	
	
	a=0;
	spp=1;lol=0;
lol2=0;tank2;

lol22=rand(10,360);




let spp2=1;
ang=0;
	loop(5){
	
	loop(15){
	let qwe=CreateShotA1(ObjRender_GetX(x),ObjRender_GetY(x), spp2, ang-angle, 2, 10);
	ObjMove_SetAngle(qwe,ang+atan2(ObjRender_GetY(objEnemy)-ObjRender_GetY(qwe),ObjRender_GetX(objEnemy)-ObjRender_GetX(qwe)));
	ang+=360/15;}
	
	
	
	
	spp2+=0.1;
	}
	
	




ObjMove_SetAngle(x,atan2(GetPlayerY-ObjRender_GetY(x),GetPlayerX-ObjRender_GetX(x)));
	let sus=rand(0.03,0.1);
TExplosionA(ObjMove_GetX(x),ObjMove_GetY(x),5,0.1);
loop(159){
	
	
	ObjMove_SetSpeed(x,ObjMove_GetSpeed(x)+sus);
	
	wait(2);
	}


	
	wait(180);
	Obj_Delete(x);
	break;
	
	
	
	}yield;}
	
	
	}
	
	
	let lol22=0;
	
	
	let f=1;
	loop(136){r+=0.10;
	yield;
	
	ObjMove_SetPosition(qwe,-f+ObjRender_GetX(objEnemy)+r*cos(angle*72+angel),ObjRender_GetY(objEnemy)+r*sin(angle*72+angel));
	
	
	
	ObjMove_SetPosition(qwe2,-f+ObjRender_GetX(objEnemy)+r*cos(angle*72+angel+72),ObjRender_GetY(objEnemy)+r*sin(angle*72+angel+72));
	
	
	
	
	ObjMove_SetPosition(qwer,-f+ObjRender_GetX(objEnemy)+r*cos(angle*72+angel+72+72),ObjRender_GetY(objEnemy)+r*sin(angle*72+angel+72+72));
	
	ObjMove_SetPosition(qwer2,-f+ObjRender_GetX(objEnemy)+r*cos(angle*72+angel+72+72+72),ObjRender_GetY(objEnemy)+r*sin(angle*72+angel+72+72+72));
	ObjMove_SetPosition(qwer22,-f+ObjRender_GetX(objEnemy)+r*cos(angle*72+angel+72+72+72+72),ObjRender_GetY(objEnemy)+r*sin(angle*72+angel+72+72+72+72));
	
	
			Obj_SetRenderPriorityI(x,55);
	}
	
	}
	
	
	
	
	
	
	}
	
	
	
	let tut=0;
	let tut1=0;
	let tut11=0;
	let a=0;
	let spp=0;
	
	task tra(df){let tut2=0;
	loop{yield;
	if(tut2>1){tut2=1;}
	tut+=tut2;tut2+=0.003;}
	
	}
	
	
	
task boom{
	let so = GetCurrentScriptDirectory ~ "./Sounds/se_enep02.wav";
	let obj = ObjSound_Create;
	ObjSound_Load(obj,so);
	ObjSound_Play(obj);
	ObjSound_SetVolumeRate(obj,50);}
	
	
	
	
task tank{
	let so = GetCurrentScriptDirectory ~ "./Sounds/se_tan01.wav";
	let obj = ObjSound_Create;
	ObjSound_Load(obj,so);
	ObjSound_Play(obj);
	ObjSound_SetVolumeRate(obj,50);}
	
	
task tank2{
	let so = GetCurrentScriptDirectory ~ "./Sounds/se_tan00.wav";
	let obj = ObjSound_Create;
	ObjSound_Load(obj,so);
	ObjSound_Play(obj);
	ObjSound_SetVolumeRate(obj,20);}
	
	
task charge{
	let so = GetCurrentScriptDirectory ~ "./Sounds/se_ch02.wav";
	let obj = ObjSound_Create;
	ObjSound_Load(obj,so);
	ObjSound_Play(obj);
	ObjSound_SetVolumeRate(obj,80);}
	
	
	
@MainLoop{yield;
	SetAutoDeleteObject(true);
	if(dam==0){ObjEnemy_SetDamageRate(objEnemy,0,0);}
	if(dam==1){ObjEnemy_SetDamageRate(objEnemy,34,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, 26);

ObjEnemy_SetIntersectionCircleToPlayer(objEnemy, ex, ey,29);

frame++;}