 //#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Sp1"]
#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);
	animate;back;
	
	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;


	//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;
	
		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 tim{loop{wait(60);timers+=-1;}}
	
task animate{
	tim;
	
	
	
	

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(" Green-eyed guide ''A problem for a happy traveler''  ", 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);
	
	
	bullet;
	
	
	
	
	
wait(240);


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

af3=1;
wait(15);fir=1;
circ;
loop{
	go;
	wait(120);}
	}

	
	let angle=0;
	let angel=0;
	let r=0;
	let lol=0;
	let lol2=0;
	
	let fir=0;
	
	
	task go{
	
	tank;
	fir=1;
	loop(10){
	let qwer555 = CreateShotA1(ObjRender_GetX(objEnemy),ObjRender_GetY(objEnemy),2,90,168,10);
	ObjMove_SetAngle(qwer555,atan2(ObjRender_GetY(objEnemy)-GetPlayerY,ObjRender_GetX(objEnemy)-GetPlayerX)+lol+180+lol2);
	lol+=360/10;
	slow;
	
	
	
	
	task slow{wait(30);
	loop(20){ObjMove_SetSpeed(qwer555,ObjMove_GetSpeed(qwer555)-0.1);wait(3);}
	loop(40){ObjMove_SetSpeed(qwer555,ObjMove_GetSpeed(qwer555)+0.1);wait(3);}
	
	}
	
	
	}
	
	}
	
	
	task comet{let sas=0;
	let rog=90+rand(-10,10);
	let spp = CreateShotA1(rand(30,GetStgFrameWidth-30),-5,2,rog,236,0);
	ObjShot_SetSpellResist(spp,true);
	ObjShot_SetAutoDelete(spp,false);
	sos;
	task sos{let soss=rand(-3,3);
	loop(20){ObjMove_SetAngle(spp,ObjMove_GetAngle(spp)+soss);wait(3);}
	loop(40){ObjMove_SetAngle(spp,ObjMove_GetAngle(spp)-soss);wait(3);}
	loop(40){ObjMove_SetAngle(spp,ObjMove_GetAngle(spp)+soss);wait(3);}
	
	loop(40){ObjMove_SetAngle(spp,ObjMove_GetAngle(spp)-soss);wait(3);}
	loop(40){ObjMove_SetAngle(spp,ObjMove_GetAngle(spp)+soss);wait(3);}
	
	}
	loop(60){
	let spp2 = CreateShotA1(ObjMove_GetX(spp),ObjMove_GetY(spp),0,rog+90,116,10);
	
	
	kk;
	task kk{
	
	
	
	wait(180);ObjShot_FadeDelete(spp2);
	}
	
	
	wait(5);
	
	}
	
	
  if(ObjEnemy_GetInfo(objEnemy,INFO_LIFE) <= 900){wait(90);}else{
	wait(220);
	}
	sas=1;yield;
	
	
	}
	let kuk=0;
	let sas=0;
	
	let timers=50;
	
	task bullet{
	
	
	task comets{wait(180);
	loop{
	
	
	if(ObjEnemy_GetInfo(objEnemy,INFO_LIFE) <= 900 || timers<25){
	wait(90);}else{wait(220);}
	
	
	comet;}
	}
	comets;
	task kkk{loop{yield;angel+=3;}}
	kkk;
	let yy=0;
	loop(40){
	
	
	loop(30){
	let spp = CreateShotA1(ObjRender_GetX(objEnemy)+r*2*cos(angle*120+angel),yy+ObjRender_GetY(objEnemy)+r/2*sin(angle*120+angel),2,90,52,10);
	ObjShot_SetIntersectionEnable(spp,false);
	ObjRender_SetAlpha(spp,0);
	l;
	task l{
	wait(10);
	Obj_Delete(spp);}
	angel+=360/30;}
	
	r+=3;
	wait(3);yy+=-5;
	}
	
	
	
	wall(0,5.5,0);
	wall2(GetStgFrameWidth,5.5,0);
	
	
	loop{
	wait(6);
	kur;}
	task wall(x,inc,chto){
	let xx=0;
	let xx2=0;
	
	loop{
	
	
	
	
	
	loop(rand(5,15)){
	let spp2 = CreateShotA1(x+xx,0,2,90,84,0);
	ObjShot_SetSpellResist(spp2,true);
	kk;
	task kk{
	let asd=255/60;
	let asd2=0;
	
	loop(60){
	ObjRender_SetAlpha(spp2,0+asd2);asd2+=asd;yield;}
	}
	xx+=inc;
	
	
	if(xx>GetStgFrameWidth+x){xx=chto}
	wait(2);}
	
	
	
	let w=rand(40,90);
	let loo=0;
	let was=round(rand(1,2));
	if(was==1){loo=16;}
	if(was==2){loo=8;}
	loop(loo){
	let spp2 = CreateShotA1(x+xx,0,2,90,84,0);
	ObjShot_SetSpellResist(spp2,true);
	kk;
	task kk{
	let asd=255/60;
	let asd2=0;
	loop(60){
	ObjRender_SetAlpha(spp2,0+asd2);asd2+=asd;yield;}
	
	wait(w);ObjShot_SetGraphic(spp2,81);
	loop(50){ObjMove_SetSpeed(spp2,ObjMove_GetSpeed(spp2)-0.1);wait(4);}
	
	}
	
	
	
	xx+=inc;
	
	
	if(xx>GetStgFrameWidth+x){xx=chto;}
	wait(2);}
	
	
	
	
	}
	
	
	
	
	}
	/////////
	
	
	task wall2(x,inc,chto){
	let xx=0;
	let xx2=0;
	
	loop{
	
	
	
	
	
	loop(rand(5,15)){
	let spp2 = CreateShotA1(x-xx,0,2,90,84,0);
	ObjShot_SetSpellResist(spp2,true);
	kk;
	task kk{
	let asd=255/60;
	let asd2=0;
	
	loop(60){
	ObjRender_SetAlpha(spp2,0+asd2);asd2+=asd;yield;}
	}
	xx+=inc;
	
	
	if(xx>GetStgFrameWidth){xx=chto}
	wait(2);}
	
	
	
	let w=rand(40,90);
	let loo=0;
	let was=round(rand(1,2));
	if(was==1){loo=16;}
	if(was==2){loo=8;}
	loop(loo){
	let spp2 = CreateShotA1(x-xx,0,2,90,84,0);
	ObjShot_SetSpellResist(spp2,true);
	kk;
	task kk{
	let asd=255/60;
	let asd2=0;
	loop(60){
	ObjRender_SetAlpha(spp2,0+asd2);asd2+=asd;yield;}
	
	wait(w);ObjShot_SetGraphic(spp2,81);
	loop(50){ObjMove_SetSpeed(spp2,ObjMove_GetSpeed(spp2)-0.1);wait(4);}
	
	}
	
	xx+=inc;
	
	
	if(xx>GetStgFrameWidth){xx=chto;}
	wait(2);}
	
	
	
	
	}
	
	
	
	
	}
	//////
	}
	///
	
	
@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,35,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++;}