//#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Sp1"]
#Text[""]

#include"./Default_ShotConst.txt"
#include"./Default_Effect.txt"
#include"./effect.txt"
SetCommonData("dat",0);
#include"./Effects/Effects.txt"

#include"./Cutin.txt"

let cirr = GetCurrentScriptDirectory ~ "circle2.png" ;
	

let cirrr = GetCurrentScriptDirectory ~ "circle3.png" ;
let cir = GetCurrentScriptDirectory ~ "circle.png" ;
let bg = GetCurrentScriptDirectory ~ "spbg.jpg" ;
let cut = GetCurrentScriptDirectory ~ "Cut.png" ;
let bg2 = GetCurrentScriptDirectory ~ "spbg2.jpg" ;
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";
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;
	
Lac;
Lac2;
	ObjMove_SetDestAtWeight(objEnemy, 192, 120, 10,3);
	
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);
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(bg133)){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)){
	ObjPrim_SetTexture(objEnemy,img);
	ObjSprite2D_SetDestRect(objEnemy,-61.5,-83+5*sin(h),61.5,83+5*sin(h));
	ObjRender_SetScaleXYZ(objEnemy,0.7,0.7,0);
	dir=ObjMove_GetAngle(objEnemy);
	speed=ObjMove_GetSpeed(objEnemy);
	h+=4;

	if(speed==0){
	af1=0;
		if(af3==1){time++;
//af1=0;
		if(time<15){ObjSprite2D_SetSourceRect(objEnemy,373, 256, 511, 454);}
		if(time>=15+1 && af1<=20+1){ObjSprite2D_SetSourceRect(objEnemy,533,255, 671, 453);
		
		
		
		
if(time>80){
		time=0;
		af3=0;}
		
		}
		
		}
	else{
	
if(af1<15){ObjSprite2D_SetSourceRect(objEnemy,0, 0, 136, 197);}
		if(af1>=30+1 && af1<=45+1){ObjSprite2D_SetSourceRect(objEnemy,137,0, 274, 197);}
		if(af1>=46+1 && af1<=60+1){ObjSprite2D_SetSourceRect(objEnemy,137+137,0, 411, 197);}
		if(af1>=61+1 && af1<=76+1){ObjSprite2D_SetSourceRect(objEnemy,137,0, 274, 197);}
		
if(af1>77){ObjSprite2D_SetSourceRect(objEnemy,0, 0, 136, 197);}
		}


		}

	if(speed>0 && cos(dir)>0 ){
		ObjRender_SetAngleY(objEnemy,0);
		if(af2>12){ObjSprite2D_SetSourceRect(objEnemy,6, 234, 144, 431);}
		if(af2>24){ObjSprite2D_SetSourceRect(objEnemy,6, 234, 144, 431);}
		if(af2>36){af1=0;}
		af2++;}

	if(speed>0 && cos(dir)<0 ){
		//ObjRender_SetAngleY(objEnemy,180);
		if(af2>12){ObjSprite2D_SetSourceRect(objEnemy,144, 234, 282, 431);}
		if(af2>24){ObjSprite2D_SetSourceRect(objEnemy,144, 234, 282, 431);}
		if(af2>36){af1=0;}
		af2++;}

	af1++;
	if(af1>120){af1=0;}yield;}}


task end{
	while(ObjEnemy_GetInfo(objEnemy,INFO_LIFE)>0){yield;}
	
	/////////////////////////////////////////////////////////////
	//SetCommonData("dat",1);
	
	
	
	DeleteShotAll(TYPE_ALL,TYPE_ITEM);
	Obj_Delete(objEnemy);
	yield;
	CloseScript(GetOwnScriptID);}

@Event{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){SetScriptResult(2100);}
	case(EV_REQUEST_TIMER){SetScriptResult(45);}
	case(EV_REQUEST_SPELL_SCORE){SetScriptResult(15000);}}

	
	
	let ggg=0;
	let ggg2=0;
	let ttt=0;
	let ttt2=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,1024,1024);
ObjRender_SetAlpha(bg1q,255);
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,20000,20000,1024,20024);
ObjRender_SetAlpha(qw,155);
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,255);

ObjRender_SetAngleZ(bg1q,3*cos(hhh*5)+5);
hhh+=0.1;
}
}


task baxx(vv){let gg=0;
while(!Obj_IsDeleted(vv)){
yield;
	ObjSprite2D_SetSourceRect(vv,20000,20000,256,256);
	ObjSprite2D_SetDestCenter(vv);
	ObjRender_SetPosition(vv,0,gg,0);
			gg+=-0.5;
hhh+=0.1;
}
}




ObjRender_SetScaleXYZ(bg1q,0.7,0.7,0);

Obj_SetRenderPriorityI(bg1q,20);


ObjRender_SetScaleXYZ(qw,0.7,0.7,0);
ObjRender_SetBlendType(qw,BLEND_MULTIPLY);
Obj_SetRenderPriorityI(qw,20);






}

task move{
	
	
	wait(120);
	
	
	
af3=1;
wait(15);
PlaySE(boo);sss;
ObjCutin_SetSpellcardS4(" Phenomenon '' Oxygen debt '' ", cut, NAZRIN, 240, 104, 104);
ObjCutin_LaunchS3(NAZRIN, cut, "normal");


wait(60);


	PlaySE(cha);
	MakeConcentration("SAKURA",objEnemy,155,155,255,50);
	
wait(90);

MakeExplosion("SAKURA",objEnemy,155,155,255);
PlaySE(cha2);

af3=1;
wait(5);
	dam=1;
SetCommonData("lel",1);
	}

	
	
	task bullet(ang){
	
	}
	///
	
	
@MainLoop{yield;
	SetAutoDeleteObject(true);
	if(dam==0){ObjEnemy_SetDamageRate(objEnemy,0,0);}
	if(dam==1){ObjEnemy_SetDamageRate(objEnemy,25,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, 20);
ObjEnemy_SetIntersectionCircleToShot(objEnemy, ex, ey+60, 10);
ObjEnemy_SetIntersectionCircleToPlayer(objEnemy, ex, ey, 32);
ObjEnemy_SetIntersectionCircleToPlayer(objEnemy, ex, ey+20, 20);
ObjEnemy_SetIntersectionCircleToPlayer(objEnemy, ex, ey+30, 10);
ObjEnemy_SetIntersectionCircleToPlayer(objEnemy, ex, ey+40, 10);
ObjEnemy_SetIntersectionCircleToPlayer(objEnemy, ex, ey+50, 5);
ObjEnemy_SetIntersectionCircleToPlayer(objEnemy, ex, ey-20,32);
frame++;}
SetCommonData("lel",0);
let lasa=0;
task sdd{




}


let r=60;
	let tut=0;
	let angle=0;
task Lac{
	
	

	let lacc = ObjEnemy_Create(OBJ_ENEMY);
	ObjEnemy_Regist(lacc);
	
	wait(300);
	Shot(lacc);
	back;
	ObjMove_SetPosition(lacc,ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy));
	
	

		task Shot(obj){wait(150);
			while(!Obj_IsDeleted(obj)){
			
			
			
			
	
	
	
	
	
	
	
	let objshot1=CreateShotA1(ObjRender_GetX(lacc)+r*cos(tut),ObjRender_GetY(lacc)+r*sin(tut), 0.4, lasa+atan2(ObjRender_GetY(lacc)-ObjRender_GetY(lacc)+r*sin(tut),ObjRender_GetX(lacc)-ObjRender_GetX(lacc)+r*cos(tut)), 87, 10);
	let objshot2=CreateShotA1(ObjRender_GetX(lacc)-r*cos(tut),ObjRender_GetY(lacc)-r*sin(tut), 0.4, lasa+180+atan2(ObjRender_GetY(lacc)-ObjRender_GetY(lacc)+r*sin(tut),ObjRender_GetX(lacc)-ObjRender_GetX(lacc)+r*cos(tut)), 87, 10);
	
	let objshot11=CreateShotA1(ObjRender_GetX(lacc)-r*sin(tut),ObjRender_GetY(lacc)+r*cos(tut), 0.4, lasa+90+atan2(ObjRender_GetY(lacc)-ObjRender_GetY(lacc)+r*sin(tut),ObjRender_GetX(lacc)-ObjRender_GetX(lacc)+r*cos(tut)), 87, 10);
	let objshot22=CreateShotA1(ObjRender_GetX(lacc)+r*sin(tut),ObjRender_GetY(lacc)-r*cos(tut), 0.4, lasa+270+atan2(ObjRender_GetY(lacc)-ObjRender_GetY(lacc)+r*sin(tut),ObjRender_GetX(lacc)-ObjRender_GetX(lacc)+r*cos(tut)), 87, 10);
	cc(objshot1);
	cc(objshot2);
	cc(objshot11);
	cc(objshot22);
	
	
	task cc(tt){wait(60);
	loop(60){
	ObjMove_SetSpeed(tt,ObjMove_GetSpeed(tt)+0.1);wait(3);
	}
	}
	
	
	
	
	
	
	
	if(ObjMove_GetX(GetPlayerObjectID)>ObjMove_GetX(lacc)-40 && ObjMove_GetX(GetPlayerObjectID)<ObjMove_GetX(lacc)+40 && ObjMove_GetY(GetPlayerObjectID)>ObjMove_GetY(lacc)-40 && ObjMove_GetY(GetPlayerObjectID)<ObjMove_GetY(lacc)+40){
	tut+=12.39;sdd;
	wait(3);
				PlaySE(ki);}else{
				
				tut+=1.5657;
	
				PlaySE(ki);
				wait(8);
				}
				
				
				
				
				
				
				
				
				
				}}
				
				ObjMove_SetDestAtWeight(lacc,GetStgFrameWidth/2-100,GetStgFrameHeight/2-150,5,2);
				wait(60);
				
				
				PlaySE(cha);
	MakeConcentration("SAKURA",lacc,155,0,255,50);
	
wait(90);

MakeExplosion("SAKURA",lacc,155,0,255);
PlaySE(cha2);
				
				
				
				
				loop{
		ObjMove_SetDestAtWeight(lacc,ObjMove_GetX(GetPlayerObjectID),ObjMove_GetY(GetPlayerObjectID),5,1);
		yield;}
		
		
		
		
		
		
		
task back{
	let bg133=ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(bg133, BLEND_ADD_RGB);
	ObjPrim_SetTexture(bg133,cirr);
	ObjSprite2D_SetSourceRect(bg133,0,0,132,132);
	ObjSprite2D_SetDestCenter(bg133);
	////
	

	let hh=0;
	dd;

	task dd{
		while(!Obj_IsDeleted(bg133)){yield;
		
		if(GetCommonData("lel",0)){
		ObjRender_SetPosition(bg133,ObjMove_GetX(lacc)+11111,ObjMove_GetY(lacc),0);
		}
		if(GetCommonData("lel",1)){
		ObjRender_SetPosition(bg133,ObjMove_GetX(lacc),ObjMove_GetY(lacc),0);
		}
		
		ObjRender_SetAngleZ(bg133,asd2/2);
			ObjRender_SetScaleXYZ(bg133,1+0.1*cos(hh),1+0.1*cos(hh),0);
		
		hh+=2;
			Obj_SetRenderPriorityI(bg133,22);
			ObjRender_SetAlpha(bg133,0);
			////
			
			asd2+=1.5;}}}
		
		
		
		
}

///
let plu=0;
task Lac2{
	
	

	let lacc = ObjEnemy_Create(OBJ_ENEMY);
	ObjEnemy_Regist(lacc);
	
	wait(300);
	Shot(lacc);
	back;
	ObjMove_SetPosition(lacc,ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy));
	let asd=0;
	let aaa=0;
	
	task las(obj){
	wait(150);
	
	loop{
	
	loop(15){
	let gg = CreateLooseLaserA1(ObjMove_GetX(lacc),ObjMove_GetY(lacc),12,angle+plu,1000,10,221,0);
	
let gg2=CreateShotA1(ObjRender_GetX(lacc),ObjRender_GetY(lacc), 0.5, angle+plu, 230, 10);
ObjShot_SetAutoDelete(gg2,false);
	ss12(gg2);
	sa(gg2);
	
	task sa(y){
	loop{
	if(ObjMove_GetX(y)<0  || ObjMove_GetX(y)>GetStgFrameWidth  ){
	aaa=3;
	ObjMove_SetAngle(y,180-ObjMove_GetAngle(y));
	loop(120){
	ObjMove_SetSpeed(y,1);yield;}
	break;
	}
	yield;
	}
	}
	task ss12(g){
	
	loop{
	yield;
	
let gg2222=CreateShotA1(ObjRender_GetX(g),ObjRender_GetY(g), aaa, ObjMove_GetAngle(g)+180, 246, 0);
ObjShot_FadeDelete(gg2222);
	}
	}
	
	
ObjShot_SetIntersectionEnable(gg,false);
	ss(gg2);
	
	
	task ss(re){
	
	wait(60);PlaySE(tana);
	loop(60){
	
	ObjMove_SetSpeed(re,ObjMove_GetSpeed(re)+0.1);yield;
	
	}
	


	
	}
	
	
	 angle+=360/15;
	}plu+=17.9876543456789;
	
	wait(180);
	}
	
	
	
	}
	
	las(lacc);

		task Shot(obj){wait(150);
			while(!Obj_IsDeleted(obj)){
			
			
			
			
	
	
	
	
	
	
	/*
	let objshot1=CreateShotA1(ObjRender_GetX(lacc)+r*cos(tut),ObjRender_GetY(lacc)+r*sin(tut), 1, 180+atan2(ObjRender_GetY(lacc)-ObjRender_GetY(lacc)+r*sin(tut),ObjRender_GetX(lacc)-ObjRender_GetX(lacc)+r*cos(tut)), 86, 10);
	let objshot2=CreateShotA1(ObjRender_GetX(lacc)-r*cos(tut),ObjRender_GetY(lacc)-r*sin(tut), 1, atan2(ObjRender_GetY(lacc)-ObjRender_GetY(lacc)+r*sin(tut),ObjRender_GetX(lacc)-ObjRender_GetX(lacc)+r*cos(tut)), 86, 10);
	
	let objshot11=CreateShotA1(ObjRender_GetX(lacc)-r*sin(tut),ObjRender_GetY(lacc)+r*cos(tut), 1, 180+atan2(ObjRender_GetY(lacc)-ObjRender_GetY(lacc)+r*sin(tut),ObjRender_GetX(lacc)-ObjRender_GetX(lacc)+r*cos(tut)), 86, 10);
	let objshot22=CreateShotA1(ObjRender_GetX(lacc)+r*sin(tut),ObjRender_GetY(lacc)-r*cos(tut), 1, atan2(ObjRender_GetY(lacc)-ObjRender_GetY(lacc)+r*sin(tut),ObjRender_GetX(lacc)-ObjRender_GetX(lacc)+r*cos(tut)), 86, 10);
	*/
	let a=0;
	let a2=255/120;
	loop(15){
	
	
	
	
	
	let bub2=CreateShotA1(ObjRender_GetX(lacc)+r*sin(tut),ObjRender_GetY(lacc)-r*cos(tut), 1, ang+90+atan2(ObjRender_GetY(lacc)-ObjRender_GetY(lacc)+r*sin(tut),ObjRender_GetX(lacc)-ObjRender_GetX(lacc)+r*cos(tut)), 126, 10);
	
	
	
	tut+=360/15;
	}ang+=-16.9876546789;
				
				
				
				
				
				
				
				
				PlaySE(ki);
				wait(30);}
				
				
				
				
				
				}
				
				ObjMove_SetDestAtWeight(lacc,GetStgFrameWidth/2+100,GetStgFrameHeight/2-150,5,2);
				wait(60);
				
				
				PlaySE(cha);
	MakeConcentration("SAKURA",lacc,0,0,255,50);
	
wait(90);

MakeExplosion("SAKURA",lacc,0,0,255);
PlaySE(cha2);
				
				
				
				
				loop{
		ObjMove_SetDestAtWeight(lacc,ObjMove_GetX(GetPlayerObjectID),ObjMove_GetY(GetPlayerObjectID),5,0.1);
		yield;}
		
		
		
		
		
		
		
task back{
	let bg133=ObjPrim_Create(OBJ_SPRITE_2D);
	ObjRender_SetBlendType(bg133, BLEND_ADD_RGB);
	ObjPrim_SetTexture(bg133,cirrr);
	ObjSprite2D_SetSourceRect(bg133,0,0,132,132);
	ObjSprite2D_SetDestCenter(bg133);
	////
	

	let hh=0;
	dd;

	task dd{
		while(!Obj_IsDeleted(bg133)){yield;
		
		if(GetCommonData("lel",0)){
		ObjRender_SetPosition(bg133,ObjMove_GetX(lacc)+11111,ObjMove_GetY(lacc),0);
		}
		if(GetCommonData("lel",1)){
		ObjRender_SetPosition(bg133,ObjMove_GetX(lacc),ObjMove_GetY(lacc),0);
		}
		
		ObjRender_SetAngleZ(bg133,asd2/2);
			ObjRender_SetScaleXYZ(bg133,1+0.1*cos(hh),1+0.1*cos(hh),0);
		
		hh+=2;
			Obj_SetRenderPriorityI(bg133,22);
			ObjRender_SetAlpha(bg133,0);
			////
			
			asd2+=1.5;}}}
		
		
		
		
}





