 //#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Sp2"]
#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 ey = GetCurrentScriptDirectory ~ "eye.png" ;
let bg = GetCurrentScriptDirectory ~ "spr.png" ;
let cut = GetCurrentScriptDirectory ~ "Cut.png" ;
let bg2 = GetCurrentScriptDirectory ~ "spg.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_cat00.wav" ;
let img=GetCurrentScriptDirectory ~ "KE.png";
let img2=GetCurrentScriptDirectory ~ "flower.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);yield;
	animate;
	
	ObjMove_SetDestAtWeight(objEnemy, 192, 120, 10,1);
	
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);
	
	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)){
		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;yield;}}}
let dir;
	let speed;
	let time=0;
	
	
	
	
	
	
	let g=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){
		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);


if(fir==1){loop{yield;ObjSprite2D_SetDestRect(objEnemy,-32,-32+5*sin(h),32,32+5*sin(h));
	h+=4;ObjSprite2D_SetSourceRect(objEnemy,192,0, 256, 64);}}


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>35){af1=0;}
		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>35){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);
	SetAutoDeleteObject(true);
	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 stop=0;

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,256,256);
ObjRender_SetAlpha(bg1q,255);
ObjRender_SetScaleXYZ(bg1q,1.5,1.5,1.5);
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,0,0,256,256);
ObjRender_SetAlpha(qw,155);

ObjRender_SetScaleXYZ(qw,2.5,2.5,2.5);
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,130);

ObjRender_SetScaleXYZ(bg1q,2.4,2.4,2.4);
ObjRender_SetPosition(bg1q,GetStgFrameWidth/2,GetStgFrameHeight/2,0);
ObjRender_SetAngleZ(bg1q,hhh);
hhh+=0.2;
}
}


task baxx(vv){let gg=0;
while(!Obj_IsDeleted(vv)){
yield;
	
ObjRender_SetScaleXYZ(qw,2.4,2.4,2.4);
ObjRender_SetAlpha(vv,255);

ObjRender_SetPosition(vv,GetStgFrameWidth/2,GetStgFrameHeight/2,0);
ObjRender_SetAngleZ(vv,-hhh);
			gg+=-0.2;
}
}




Obj_SetRenderPriorityI(bg1q,21);


//ObjRender_SetBlendType(qw,BLEND_MULTIPLY);
Obj_SetRenderPriorityI(qw,20);






}
let aas=0;
task circ{dam=1;
}

task kur{
	let so = GetCurrentScriptDirectory ~ "./Sounds/se_kira00.wav";
	let obj = ObjSound_Create;
	ObjSound_Load(obj,so);
	ObjSound_Play(obj);
	ObjSound_SetVolumeRate(obj,50);}
	
	
task incoming{
	let so = GetCurrentScriptDirectory ~ "./Sounds/se_border.wav";
	let obj = ObjSound_Create;
	ObjSound_Load(obj,so);
	ObjSound_Play(obj);
	ObjSound_SetVolumeRate(obj,80);}
	
	
task charge{
	let so = GetCurrentScriptDirectory ~ "./Sounds/se_ch02.wav";
	let obj = ObjSound_Create;
	ObjSound_Load(obj,so);
	ObjSound_Play(obj);
	ObjSound_SetVolumeRate(obj,80);}
	
	
task begi{
	let obj = ObjSound_Create;
	ObjSound_Load(obj,bgam);
	ObjSound_Play(obj);
	ObjSound_SetVolumeRate(obj,80);}
	
	
	
task appe{let so = GetCurrentScriptDirectory ~ "./Sounds/se_tan01.wav";
	let obj = ObjSound_Create;
	ObjSound_Load(obj,so);
	ObjSound_Play(obj);
	ObjSound_SetVolumeRate(obj,50);}
	
	
	
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_tan00.wav";
	let obj = ObjSound_Create;
	ObjSound_Load(obj,so);
	ObjSound_Play(obj);
	ObjSound_SetVolumeRate(obj,20);}
	

	
	
	
task boss{
	let obj = ObjSound_Create;
	ObjSound_Load(obj,boo);
	ObjSound_Play(obj);
	ObjSound_SetVolumeRate(obj,70);}
	
	
task move{
	begi;
	
	wait(120);
	
	
	
af3=1;
wait(15);
boss;sss;
ObjCutin_SetSpellcardS4("Grandpa Hanasaka ''The fate of an envious person'' ", cut, NAZRIN, 240, 104, 104);
ObjCutin_LaunchS3(NAZRIN, cut, "normal");


wait(60);


charge;
	
	MakeConcentration("MAPLE",objEnemy,0,255,55,60);
	
wait(90);

af3=1;
wait(15);
boom;
MakeExplosion("MAPLE",objEnemy,0,255,55);
	prison(rand(100,250),rand(300,350));
	loop(2){
	wall(0,rand(50,GetStgFrameHeight-50),0);
	wall(GetStgFrameWidth,rand(50,GetStgFrameHeight-50),180);
	wall(rand(50,GetStgFrameWidth-50),GetStgFrameHeight,270);
	wall(rand(50,GetStgFrameWidth-50),0,90);
	}
	
	wait(90+150);
	
charge;
	
	MakeConcentration("MAPLE",objEnemy,0,255,55,60);
	
wait(90);
	
	circ;
	
	
	wait(540-180-150);
	
	
charge;
	
	MakeConcentration("MAPLE",objEnemy,0,255,55,60);
	
wait(90);

af3=1;
wait(15);
	lab=1;
	let corner = 0;
	let sup=0;
	cil;
task cil{wait(120);



	ObjMove_SetDestAtWeight(objEnemy, 192+100, 120+rand(-20,20), 10,1);
wait(180);
loop{
ObjMove_SetDestAtWeight(objEnemy, 192-100, 120+rand(-20,20), 10,1);
wait(240);
ObjMove_SetDestAtWeight(objEnemy, 192+100, 120+rand(-20,20), 10,1);

wait(240);
}
}	
	
	loop{
	
	
	wait(90);
	
	task sss{wait(45);circles2;appe;}
	sss;
	tank;
	let ang = 0;
	
	
	loop(6){TBubble(num+ang,time);ang+=60;}
	let sos=rand(0,60);
corner+=rand(15,50);
	task TBubble(angle,time){
		let obj = CreateShotA1(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),2.5,corner+angle,168,30);
		
		
		ObjMove_SetAngle(obj,atan2(GetPlayerY-ObjRender_GetY(objEnemy),GetPlayerX-ObjRender_GetX(objEnemy))+angle);
	
		wait(30);
		
		while(!Obj_IsDeleted(obj)){TFlower(ObjMove_GetX(obj)+rand(-15,15),ObjMove_GetY(obj)+rand(-15,15),time);wait(15);}

		task TFlower(x,y,time_explode){
			ascent(i in 0..5){
			let flower = CreateShotA1(x+8*cos(i*72),y+8*sin(i*72),0,i*72,47,10);
			graph;
			task graph{
			
			ObjShot_SetGraphic(flower,47);
			wait(60);
			ObjShot_SetGraphic(flower,48);
			wait(60);
			ObjShot_SetGraphic(flower,41);
			wait(60);
			
			ObjShot_FadeDelete(flower);
			
			
			}
			
					}}}}
					
					

}
	
	let num=3;
	let lols=0;
	task circles2{
	
	loop(10){
	as;
	let qwer555 =CreateShotA1(ObjRender_GetX(objEnemy),ObjRender_GetY(objEnemy),1.5,lol+lols,28,10);
	
	task as{
	let qwer555 =CreateShotA1(ObjRender_GetX(objEnemy),ObjRender_GetY(objEnemy),1.3,lol+lols,12,10);
	}
	
	
	
	lol+=360/10;
	
	
	}lols+=13.876;
	
	}
	
	task circles{
	let anglel=0;
	let spp=2;
	
	loop(48){tank;
	let sus=0.5+spp;
	loop(10){
	
	let qwer555 =CreateShotA1(ObjRender_GetX(objEnemy),ObjRender_GetY(objEnemy),sus,lol+20,1,10);
	ObjMove_SetAngle(qwer555,atan2(ObjRender_GetY(objEnemy)-ObjRender_GetY(qwer555),ObjRender_GetX(objEnemy)-ObjRender_GetX(qwer555))+lol+anglel);
	lol+=360/10;
	del;
	task del{
	while(lab==0){yield;}
	ObjShot_FadeDelete(qwer555);
	}
	
	
	}
	wait(10);
	spp+=-0.02;anglel+=9.87656789;
	}
	
	
	}

	
	task prison(x,y){
	
	circles;
	loop(60){
	let qwe=CreateShotA1(x,y, 2.5, angle, 12, 0);
	ObjShot_SetSpellResist(qwe,true);
	ObjShot_SetIntersectionEnable(qwe,false);
	ObjShot_SetAutoDelete(qwe,false);
	ObjRender_SetAlpha(qwe,0);
	ll;
	task ll{
	wait(180);
	ObjShot_SetGraphic(qwe,168);
	ObjShot_SetIntersectionEnable(qwe,true);
	ObjRender_SetAlpha(qwe,255);
	
loop(50){
ObjMove_SetSpeed(qwe,ObjMove_GetSpeed(qwe)-0.1);wait(3);
}incoming;wait(110);
loop(25){
ObjMove_SetSpeed(qwe,ObjMove_GetSpeed(qwe)+0.1);wait(3);
}

while(lab==0){yield;}
ObjShot_SetAutoDelete(qwe,true);
	
loop(25){
ObjMove_SetSpeed(qwe,ObjMove_GetSpeed(qwe)+0.2);wait(2);
}

	}
	
	angle+=360/60;
	}
	
	}
	
	task wall(x,y,ang){
	
	let check=1;
	let pov=0;
    let povorot=0;
    let povorot2=0;
	let qwe=CreateShotA1(x,y, 1.5, ang, 20, 10);
	ObjShot_SetSpellResist(qwe,true);
	ObjShot_SetIntersectionEnable(qwe,false);
	ObjShot_SetAutoDelete(qwe,false);
	ObjRender_SetAlpha(qwe,0);
	sli;
	task sli{
	loop(3){
	povorot2=round(rand(1,3));
	
	if(povorot2==1){povorot=0;}
	if(povorot2==2){povorot=90;}
	if(povorot2==3){povorot=-90;}
	
	wait(120);
	ObjMove_SetAngle(qwe,ObjMove_GetAngle(qwe)+povorot);
	}
	}
	
	
	
	let ch=round(rand(1,2));
	if(ch==1){pov=90;}
	if(ch==2){pov=-90;}
	
	
	
	
	loop(25){
	
	
	loop(5){
	wait(5);
	
	if(check==1){
	
	if(ObjMove_GetX(qwe)>0 && ObjMove_GetX(qwe)<GetStgFrameWidth && ObjMove_GetY(qwe)>0 && ObjMove_GetY(qwe)<GetStgFrameHeight){
	
	kur;
	
	
	
	let qwe1=CreateShotA1(ObjRender_GetX(qwe),ObjRender_GetY(qwe), 0, ObjMove_GetAngle(qwe)+pov, 20, 10);
	ObjShot_SetSpellResist(qwe1,true);
	ObjShot_SetIntersectionEnable(qwe1,false);
	ObjRender_SetAlpha(qwe1,50);
	go;
	
	
	task go{
	while(lab==0){yield;}
	tank;
	
TExplosionA(ObjMove_GetX(qwe1),ObjMove_GetY(qwe1),10,0.05);
	ObjShot_SetIntersectionEnable(qwe1,true);
	ObjRender_SetAlpha(qwe1,200);
loop(30){
ObjMove_SetSpeed(qwe1,ObjMove_GetSpeed(qwe1)+0.001);wait(3);
}
	}
	
	
	}
	
	
	}
	
	}
	
	check=round(rand(1,2));
	let ch=round(rand(1,2));
	if(ch==1){pov=90;}
	if(ch==2){pov=-90;}
	}
	
	
	
	}
	
	
	let lab=0;
	let angle=0;
	let angel=0;
	let r=0;
	let lol=0;
	let lol2=0;
	
	let fir=0;
	
	
	
	
	
@MainLoop{yield;
//DeleteShotInCircle(TYPE_ALL,TYPE_IMMEDIATE,0,0,2);
	SetAutoDeleteObject(true);
	if(dam==0){ObjEnemy_SetDamageRate(objEnemy,0,0);}
	if(dam==1){ObjEnemy_SetDamageRate(objEnemy,31,5);}
	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++;}