 //#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Sp4"]
#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 inv = GetCurrentScriptDirectory ~ "sh.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{
LoadEnemyShotData(GetCurrentScriptDirectory ~ "./Parsee system/System/AllStarShot.txt"); 
objEnemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objEnemy);
	animate;
	
	ObjMove_SetDestAtWeight(objEnemy, 192, 140, 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(53);}
	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 he2{let so = GetCurrentScriptDirectory ~ "./Sounds/se_msl2.wav";
	
	let obj = ObjSound_Create;
	ObjSound_Load(obj,so);
	ObjSound_Play(obj);
	ObjSound_SetVolumeRate(obj,40);}
	
task he{let so = GetCurrentScriptDirectory ~ "./Sounds/Charge.wav";
	
	let obj = ObjSound_Create;
	ObjSound_Load(obj,so);
	ObjSound_Play(obj);
	ObjSound_SetVolumeRate(obj,80);}
	
	
	
	
	
	task heart(x,s,y,ss,angle){
	
	
	let qwe=CreateShotA1(x-s,y-ss, 1, angle, 740, 10);
	let qwee=CreateShotA1(x+s,y+ss, 1, angle, 740, 10);
	ObjShot_SetSpellResist(qwe,true);
	ObjShot_SetSpellResist(qwee,true);
	
	
	
	pov;
	
	
	
	task pov{
	
	let ggg=rand(-2,2);
	loop(30){
	ObjShot_SetAutoDelete(qwe,false);
	ObjShot_SetAutoDelete(qwee,false);
	ObjMove_SetAngle(qwe,ObjMove_GetAngle(qwe)-ggg);
	ObjMove_SetAngle(qwee,ObjMove_GetAngle(qwee)+ggg);
	
	wait(2);}
	
	ObjShot_SetAutoDelete(qwe,true);
	ObjShot_SetAutoDelete(qwee,true);
	loop(60){
	
	
	ggg=rand(-2,-1);
	loop(30){
	
	ObjMove_SetAngle(qwe,ObjMove_GetAngle(qwe)-ggg);
	
	ObjMove_SetAngle(qwee,ObjMove_GetAngle(qwee)+ggg);
	
	wait(2);}
	ggg=rand(1,2);
	loop(30){
	
	ObjMove_SetAngle(qwe,ObjMove_GetAngle(qwe)-ggg);
	
	ObjMove_SetAngle(qwee,ObjMove_GetAngle(qwee)+ggg);
	
	wait(2);}
	
	
	}}
	
	
	
	while(!Obj_IsDeleted(qwe)){
	kur;
	let qwe1=CreateShotA1(ObjMove_GetX(qwe),ObjMove_GetY(qwe), 0, angle, 527, 10);
	let qwe12=CreateShotA1(ObjMove_GetX(qwee),ObjMove_GetY(qwee), 0, angle, 527, 10);
	l;
	task l{wait(110);ObjShot_FadeDelete(qwe1);ObjShot_FadeDelete(qwe12);}
	
	wait(7);
	}
	
	
	}
	
	
	
	
	
task move{
	begi;
	
	wait(120);
	
	
	
af3=1;
wait(15);
boss;sss;
ObjCutin_SetSpellcardS4(" Envy '' Demon's presence ''  ", 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);circ;
boom;
MakeExplosion("MAPLE",objEnemy,0,255,55);




let sos=1;
let spe=2;
let sas=12;
loop(10){
loop(15){
	
	
	
	let qwer555 = CreateShotA1(ObjRender_GetX(objEnemy),ObjRender_GetY(objEnemy),spe,90,825,10);
	ObjRender_SetScaleXYZ(qwer555,sos,sos,sos);
	sss;
	task sss{loop{yield;
	ObjShot_SetIntersectionCircleA1(qwer555,sas);
	}}
	
	ObjMove_SetAngle(qwer555,angle+atan2(ObjRender_GetY(objEnemy)-GetPlayerY,ObjRender_GetX(objEnemy)-GetPlayerX)+ang);
	ang+=360/15;
	}angle+=18.8765;sas+=-0.09;
sos-=0.05;spe+=-0.15;
}


kkkk;
task kkkk{
wait(120);

let sus=rand(10,80);
let sus2=rand(10,100);
heart(0,0,GetStgFrameHeight/2,sus2,0);

heart(GetStgFrameWidth,0,GetStgFrameHeight/2,sus2,180);
wait(150);
loop{

let sus=rand(10,80);
let sus2=rand(10,100);



let ran=round(rand(1,2));
if(ran==1){
heart(190,sus,0,0,90);

heart(190,sus,GetStgFrameHeight,0,270);
}

if(ran==2){



heart(0,0,GetStgFrameHeight/2,sus2,0);

heart(GetStgFrameWidth,0,GetStgFrameHeight/2,sus2,180);
}




wait(150);
	}
	}
	
	let was=180;
	let zxc=3;
	ObjMove_SetDestAtWeight(objEnemy, 192, -150, 10,3);

	wait(120);

	loop{
	let spos=round(rand(1,2));
	
	let sys=rand(100,280);
	if(spos==1){
	ObjMove_SetX(objEnemy,-150);
	
	
	ObjMove_SetY(objEnemy,sys);
	ObjMove_SetDestAtWeight(objEnemy, -150, sys, 10,10);

	wait(was);
	
	ObjMove_SetDestAtWeight(objEnemy, 20, sys, 10,zxc);

	
	while(ObjMove_GetSpeed(objEnemy)>0){yield;}
	
	tud;
	ObjMove_SetDestAtWeight(objEnemy, -150, sys, 10,zxc);
while(ObjMove_GetSpeed(objEnemy)>0){yield;}
was+=-15;zxc+=0.5;
if(was<30){was=30;}
	}
	/////////////////////
	if(spos==2){
	ObjMove_SetX(objEnemy,GetStgFrameWidth+150);
	
	ObjMove_SetY(objEnemy,sys);
	ObjMove_SetDestAtWeight(objEnemy, GetStgFrameWidth+150, sys, 10,10);

	wait(was);
	
	ObjMove_SetDestAtWeight(objEnemy, GetStgFrameWidth-20, sys, 10,zxc);

	
	while(ObjMove_GetSpeed(objEnemy)>0){yield;}
	
	tud;
	ObjMove_SetDestAtWeight(objEnemy, GetStgFrameWidth+150, sys, 10,zxc);
while(ObjMove_GetSpeed(objEnemy)>0){yield;}

was+=-15;zxc+=0.5;
if(was<30){was=30;}
	}
	
	
	
	}
	////////////////////
	
	
	
	
	}
	
	
	
	
	task tud{
	let ggg=0;
	
let as=4;
	
	let rangle=0;
	let rang=rand(0,345);
	loop(20){
	
	let qwe=CreateShotA1(ObjRender_GetX(objEnemy),ObjRender_GetY(objEnemy), 1, rangle+rang, 62, 5);
	let qwe2=CreateShotA1(ObjRender_GetX(objEnemy),ObjRender_GetY(objEnemy), 1, rangle+rang, 61, 5);
	rangle+=360/20;
	slow;
	task slow{
	loop(6){
	loop(30){
	
	ObjMove_SetAngle(qwe,ObjMove_GetAngle(qwe)-as);
	ObjMove_SetAngle(qwe2,ObjMove_GetAngle(qwe2)+as);

	wait(2);}as+=-0.02*2;}
	
	}
	}
	
	
	
	loop(15){
	l;
	ll;
	lll;
	
	
	let qwer555 = CreateShotA1(ObjRender_GetX(objEnemy),ObjRender_GetY(objEnemy),1.2,90,825,10);
	ObjMove_SetAngle(qwer555,atan2(ObjRender_GetY(objEnemy)-GetPlayerY,ObjRender_GetX(objEnemy)-GetPlayerX)+ggg+180);
	
	
	task l{
	let qwer555 = CreateShotA1(ObjRender_GetX(objEnemy),ObjRender_GetY(objEnemy),1,90,280,10);
	ObjMove_SetAngle(qwer555,atan2(ObjRender_GetY(objEnemy)-GetPlayerY,ObjRender_GetX(objEnemy)-GetPlayerX)+ggg+180);
	
	
	}
	
	task ll{
	let qwer555 = CreateShotA1(ObjRender_GetX(objEnemy),ObjRender_GetY(objEnemy),0.8,90,27,10);
	ObjMove_SetAngle(qwer555,atan2(ObjRender_GetY(objEnemy)-GetPlayerY,ObjRender_GetX(objEnemy)-GetPlayerX)+ggg+180);
	
	
	}
	task lll{
	let qwer555 = CreateShotA1(ObjRender_GetX(objEnemy),ObjRender_GetY(objEnemy),0.6,90,718,10);
	ObjMove_SetAngle(qwer555,atan2(ObjRender_GetY(objEnemy)-GetPlayerY,ObjRender_GetX(objEnemy)-GetPlayerX)+ggg+180);
	
	
	}
	
	ggg+=360/15;
	}
	
	
	
	
	he;he2;
	let sc=0;
	let sc2=0;
	let sc3=0;
	let sc4=0;
	check;
	
	
	task check{
	let qwer555 = CreateShotA1(ObjRender_GetX(objEnemy),ObjRender_GetY(objEnemy),0,90,4,10);
	ObjRender_SetAlpha(qwer555,0);
	ObjShot_SetIntersectionEnable(qwer555,false);
	task kkk{wait(240);Obj_Delete(qwer555);}
	kkk;
	
	loop(240){
	
	
	if(GetObjectDistance(qwer555,GetPlayerObjectID)<333*sc && GetObjectDistance(qwer555,GetPlayerObjectID)>333*sc3)
	{
	
	//kur;
	
	
	SetPlayerSpeed(0.25,0.25);
	
	}else{
SetPlayerSpeed(3.7,2);}
	
	yield;
	}
	
	
	
	
	}
	
	
	
	
	
	
	
	sis;
	
	let bg133=ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(bg133, BLEND_INV_DESTRGB);
	ObjPrim_SetTexture(bg133,inv);
	ObjSprite2D_SetSourceRect(bg133,0,0,666,666);
	ObjSprite2D_SetDestCenter(bg133);
	
ObjRender_SetPosition(bg133,ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),0);
	loop(220){
ObjRender_SetAlpha(bg133,255);

ObjRender_SetScaleXYZ(bg133,sc,sc,sc);
	yield;
	sc+=sc2;sc2+=0.0002;
	}
	
	
	task sis{
	
	let bg133=ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(bg133, BLEND_INV_DESTRGB);
	ObjPrim_SetTexture(bg133,inv);
	ObjSprite2D_SetSourceRect(bg133,0,0,666,666);
	ObjSprite2D_SetDestCenter(bg133);
	
ObjRender_SetPosition(bg133,ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),0);
	loop(220){
ObjRender_SetAlpha(bg133,255);

ObjRender_SetScaleXYZ(bg133,sc3,sc3,sc3);
	yield;
	sc3+=sc4;sc4+=0.0001;
	}
	
	}
	
	
	}
	
	
	
	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,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++;}