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

#include"./Default_ShotConst.txt"
#include"./function_cutin.txt"
#include"./effect.txt"
#include"./Default_Effect.txt"
SetCommonData("data",0);
let ti=0;
let dam=0;
let cut = GetCurrentScriptDirectory ~ "KeCut.png" ;
let earth = GetCurrentScriptDirectory ~ "earth2.png" ;
let earth2 = GetCurrentScriptDirectory ~ "earth.png" ;
let cir = GetCurrentScriptDirectory ~ "circle.png" ;
let cr = GetCurrentScriptDirectory ~ "spell.png" ;
let sbg = GetCurrentScriptDirectory ~ "spbg.png" ;
let sbg2 = GetCurrentScriptDirectory ~ "spbg2.jpg" ;
let fo = GetCurrentScriptDirectory ~ "impact.ttf" ;
///

//SetPlayerInvincibilityFrame(41565);
///
let bg = GetCurrentScriptDirectory ~ "sp2.png" ;
let bg2 = GetCurrentScriptDirectory ~ "bg2.png" ;
let pow = GetCurrentScriptDirectory ~ "./Sounds/se_power1.wav" ;
let dec = GetCurrentScriptDirectory ~ "./Sounds/se_cat00.wav" ;
let cha = GetCurrentScriptDirectory ~ "./Sounds/se_ch00.wav" ;
let fault = GetCurrentScriptDirectory ~ "./Sounds/se_fault.wav" ;
let tana = GetCurrentScriptDirectory ~ "./Sounds/se_tan01.wav" ;
let bgam = GetCurrentScriptDirectory ~ "./Sounds/st.mp3" ;
let ki = GetCurrentScriptDirectory ~ "./Sounds/se_kira00.wav" ;
let don = GetCurrentScriptDirectory ~ "./Sounds/se_pldead.wav" ;
let don2 = GetCurrentScriptDirectory ~ "./Sounds/se_don00.wav" ;
let las = GetCurrentScriptDirectory ~ "./Sounds/se_lazer01.wav" ;
let boo = GetCurrentScriptDirectory ~ "./Sounds/se_boon01.wav" ;
function wait(w){loop(w){yield;}}
//----------------------------------------------------
//グローバル変数宣言
//この位置で宣言した変数はスクリプト全体で有効です。
//ただしこの箇所での変数への代入は、定数以外の代入は行えません。
//(実行順序が保障されないため乱数などの使用はできません)
let af1=0;
let af2=0;
let af3=0;

//----------------------------------------------------
let objEnemy; //敵オブジェクト
let objPlayer; //自機オブジェクト
let frame = 0; //敵動作に使用するカウンタ(@MainLoopで1づつ増加させます)
let img=GetCurrentScriptDirectory ~ "KE.png";
//----------------------------------------------------
//敵の動作
//----------------------------------------------------



@Initialize
{objEnemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
animate;
	ObjEnemy_Regist(objEnemy);
InstallFont(fo);
move;
//SetStgFrame(0, 0, SCREEN_WIDTH, 500, 0,80);
	//自機オブジェクト取得
	objPlayer = GetPlayerObjectID();
LoadSound(cha);
LoadSound(don2);
LoadSound(las);
LoadSound(tana);
LoadSound(boo);
LoadSound(fault);
LoadSound(pow);
LoadSound(dec);
LoadSound(bgam);
LoadSound(ki);
	//敵オブジェクトを生成し登録
		
	//ObjMove_SetDestAtWeight(objEnemy, -120, -120, 10,12);

	//敵画像の設定
	
	//座標(cx, 120)へ60フレームかけて移動する
	let cx = GetStgFrameWidth() / 2;//STGシーンの中心x座標を取得
	StarEffect(objEnemy,11232);
	end;
	back;
	yield;
ObjMove_SetDestAtWeight(objEnemy, 192, 190, 10,3);
}
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 animate{

let dir;
let speed;

let time=0;
let timetrue=0;

while(!Obj_IsDeleted(objEnemy)){yield;
ObjPrim_SetTexture(objEnemy,img);
//ObjSprite2D_SetDestCenter(objEnemy);

ObjSprite2D_SetDestRect(objEnemy,-61.5,-83+5*sin(h),61.5,83+5*sin(h));

h+=6;
ObjRender_SetScaleXYZ(objEnemy,0.8,0.8,0);

dir=ObjMove_GetAngle(objEnemy);
speed=ObjMove_GetSpeed(objEnemy);

if(speed==0){
af1++;



if(af3==1){

time++;

if(time<130){
ObjSprite2D_SetSourceRect(objEnemy,378, 257, 512, 447);
}

if(time>=12+130 && af1<=24+130){
ObjSprite2D_SetSourceRect(objEnemy,518,257, 651, 447);
}
if(time>=25+130){
ObjSprite2D_SetSourceRect(objEnemy,378, 257, 512, 447);
}

time=0;



}else{

if(af1<15){
ObjSprite2D_SetSourceRect(objEnemy,11, 1, 147, 192);
}

if(af1>=30+120 && af1<=45+120){
ObjSprite2D_SetSourceRect(objEnemy,170,6, 305, 194);
}
if(af1>=46+120){
ObjSprite2D_SetSourceRect(objEnemy,317, 6, 453, 192);
}
if(af1>=62+120){
ObjSprite2D_SetSourceRect(objEnemy,170,6, 305, 194);
}


}

}


if(speed>0 && cos(dir)>0 ){
af2++;
if(af2>12){ObjRender_SetAngleY(objEnemy,0);
ObjSprite2D_SetSourceRect(objEnemy,11, 198, 146, 388);}

if(af2>24){ObjRender_SetAngleY(objEnemy,0);
ObjSprite2D_SetSourceRect(objEnemy,159, 215, 293, 403);}


if(af2>36){af1=0;}
}


if(speed>0 && cos(dir)<0 ){

af2++;
if(af2>12){ObjRender_SetAngleY(objEnemy,180);
ObjSprite2D_SetSourceRect(objEnemy,11, 198, 146, 388);}

if(af2>24){ObjRender_SetAngleY(objEnemy,180);
ObjSprite2D_SetSourceRect(objEnemy,159, 215, 293, 403);}

if(af2>36){af1=0;}
}





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









}


}let hhh=0;let alal=0;
task back{
PlaySE(fault);
TExplosionA(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),5,1);
TExplosionA(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),2,0.1);

let bg1q=ObjPrim_Create(OBJ_SPRITE_2D);
bax(bg1q);
ObjPrim_SetTexture(bg1q,sbg);
ObjSprite2D_SetSourceRect(bg1q,0,0,1600,900);
ObjRender_SetAlpha(bg1q,alal);
ObjSprite2D_SetDestCenter(bg1q);
ObjRender_SetPosition(bg1q,GetStgFrameWidth/2,230,0);



/////



////

task bax(vv){

while(!Obj_IsDeleted(vv)){
yield;
ObjRender_SetAlpha(bg1q,alal);

ObjRender_SetAngleZ(vv,hhh);
hhh+=0.1;
}
}

ObjRender_SetScaleXYZ(bg1q,0.8,0.8,0);

Obj_SetRenderPriorityI(bg1q,20);






let bg133=ObjPrim_Create(OBJ_SPRITE_2D);



ObjPrim_SetTexture(bg133,cir);
ObjSprite2D_SetSourceRect(bg133,0,0,128,127);

ObjSprite2D_SetDestCenter(bg133);

////

let bg1333=ObjPrim_Create(OBJ_SPRITE_2D);



ObjPrim_SetTexture(bg1333,cir);
ObjSprite2D_SetSourceRect(bg1333,0,0,128,127);

ObjSprite2D_SetDestCenter(bg1333);

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+sin(hh),1+sin(hh),0);
if(hh<180){hh+=0.5;}else{hh=0;}

Obj_SetRenderPriorityI(bg133,22);
ObjRender_SetAlpha(bg133,133);

//



ObjRender_SetPosition(bg1333,ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),0);
ObjRender_SetAngleZ(bg1333,-asd2/2);


ObjRender_SetScaleXYZ(bg1333,1+sin(hh),1+sin(hh),0);


Obj_SetRenderPriorityI(bg1333,22);
ObjRender_SetAlpha(bg1333,133);


asd2+=6;}}


}




@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
	{
		//敵ライフを要求された
		SetScriptResult(5800);
	}
	case(EV_REQUEST_TIMER)
	{
		//敵ライフを要求された
		SetScriptResult(50);
	}
}

let ang=0;
let ang2=0;
let al=0;
let al2=0;
let al23=0;
let sc=0;
let ann=0;

let dd=0;
let dd2=0;
let and=0;
let and2=0;









task tex{

let ttt=ObjText_Create;



let bg1=ObjPrim_Create(OBJ_SPRITE_2D);

ObjPrim_SetTexture(bg1,cr);
ObjSprite2D_SetSourceRect(bg1,0,0,234,36);

ObjSprite2D_SetDestCenter(bg1);
ObjRender_SetPosition(bg1,-230+al2,SCREEN_HEIGHT-150,0);



ObjRender_SetScaleXYZ(bg1,1,1,0);

Obj_SetRenderPriorityI(bg1,29);
ObjRender_SetAlpha(bg1,255);


ObjRender_SetAlpha(ttt,al);
ObjText_SetFontSize(ttt,20);
ObjText_SetFontBorderType(ttt,BORDER_SHADOW);
ObjText_SetFontBorderWidth(ttt,2);
ObjText_SetFontBorderColor(ttt,0,0,0);
//ObjRender_SetPosition(ttt,-1111,SCREEN_HEIGHT-350,0);
ObjText_SetFontType(ttt,"Impact");
ObjText_SetText(ttt,"Heaven sign '' Devil capturing net ''");

task innn{
loop(60){al2+=3.95;ObjRender_SetPosition(bg1,55+al2,SCREEN_HEIGHT-150+10,0);
ObjRender_SetPosition(ttt,-130+al2-30,SCREEN_HEIGHT-150,0);
yield;}
wait(30);
loop(45){ObjRender_SetPosition(bg1,55+al2,SCREEN_HEIGHT-150-al23+10,0);
ObjRender_SetPosition(ttt,-130+al2-30,SCREEN_HEIGHT-150-al23,0);al23+=7;
yield;}

}


innn;
while(!Obj_IsDeleted(ttt)){
yield;
loop(120){

ObjRender_SetAlpha(ttt,al);al+=2;yield;}

break;
}



}




////////




task SShake(dist,time)
{
	let cenx = GetStgFrameWidth/2;
	let ceny = GetStgFrameHeight/2;
	
	loop(time)
	{
		Set2DCameraFocusX(cenx+rand(-dist,dist));
		Set2DCameraFocusY(ceny+rand(-dist,dist));
		yield;
	}
	
	Reset2DCamera();
}





/////
let ag=0;
let ag2=0;
let yu=0;
let step=0;
//
task move{
wait(120);
af3=1;
PlaySE(dec);
tex;
alal=130;
cutin(NAZRIN,cut,0,0,435,558);
wait(30);
af3=0;
PlaySE(cha);StarConcentration(objEnemy,90);
wait(120);
af3=1;
down=2.5;

loop{

step=0;dam=1;
down=2.5;



loop(40){
circle2(rand(0,GetStgFrameWidth),10);wait(5);PlaySE(ki);
}

loop(10){down+=-0.2;wait(1);}
down=0;

wait(75);
top(GetPlayerX,-5);
wait(355);
down=2.5;

loop(120){yield;

 let obj55=CreateShotA1(GetStgFrameWidth,rand(0,GetStgFrameHeight), 12, ooo+ooo2,  222, rand(0,30));
ObjShot_SetIntersectionEnable(obj55,false);
}

step=1;
loop(40){

circle2(GetStgFrameWidth,rand(0,GetStgFrameHeight));wait(5);PlaySE(ki);
}

loop(15){down+=-0.2;wait(1);}
down=0;

wait(75);
top(GetPlayerX,-5);
wait(355);
down=2.5;

//

step=2;
down=2.5;


loop(120){yield;

 let obj55=CreateShotA1(rand(0,GetStgFrameWidth),GetStgFrameHeight, 12, ooo+ooo2,  222, rand(0,30));
ObjShot_SetIntersectionEnable(obj55,false);
}

loop(40){
circle2(rand(0,GetStgFrameWidth),GetStgFrameHeight);wait(5);PlaySE(ki);
}

loop(10){down+=-0.2;wait(1);}
down=0;

wait(75);
top(GetPlayerX,-5);
wait(355);
down=2.5;


step=3;


loop(120){yield;

 let obj55=CreateShotA1(0,rand(0,GetStgFrameHeight), 12, ooo+ooo2,  222, rand(0,30));
ObjShot_SetIntersectionEnable(obj55,false);
}

loop(40){
circle2(0,rand(0,GetStgFrameHeight));wait(5);PlaySE(ki);
}

loop(15){down+=-0.2;wait(1);}
down=0;

wait(75);
top(GetPlayerX,-5);
wait(355);
down=2.5;




}

wait(90);
af3=0;





}
let aa=0;
let aa2=0;
let yy=0;
let yy2=0;
let lef=0;
let sss=0;
let ans=0;
task top(x,y){




let obj3271=CreateShotA1(x, y, 1, 90, round(rand(17,24)), 10);

ObjShot_SetAutoDelete(obj3271,false);
loop(16){


let qwe=CreateShotA1(ObjMove_GetX(obj3271), ObjMove_GetY(obj3271), 1, ans, round(rand(33,40)), 10);
ObjShot_SetAutoDelete(qwe,false);
sd(qwe);




ans+=360/16;


}

task sd(oo){
loop(800){
ObjMove_SetAngle(oo,ObjMove_GetAngle(oo)+0.3);
ObjMove_SetSpeed(oo,ObjMove_GetSpeed(oo)+0.2);
ObjMove_SetX(oo,ObjMove_GetX(obj3271));
ObjMove_SetY(oo,ObjMove_GetY(obj3271));sss+=1;
yield;


}
Obj_Delete(oo);
}



loop(16){


let qwe=CreateShotA1(ObjMove_GetX(obj3271), ObjMove_GetY(obj3271), 1, ans, round(rand(33,40)), 10);
ObjShot_SetAutoDelete(qwe,false);
sd2(qwe);




ans+=360/16;


}



loop(9){
PlaySE(tana);
loop(10){


let qwe4=CreateShotA1(ObjMove_GetX(obj3271), ObjMove_GetY(obj3271), 1.2, aa+aa2, 128, 0);
ObjShot_SetAutoDelete(qwe4,false);


let qwe41=CreateShotA1(ObjMove_GetX(obj3271), ObjMove_GetY(obj3271), 1, aa+aa2, 121, 0);
ObjShot_SetAutoDelete(qwe41,false);



aa+=360/10;


}aa2+=34.346456;

wait(60);
}aa2=0;


task sd2(oo){
loop(800){
ObjMove_SetAngle(oo,ObjMove_GetAngle(oo)-0.3);
ObjMove_SetSpeed(oo,ObjMove_GetSpeed(oo)+0.2);
ObjMove_SetX(oo,ObjMove_GetX(obj3271));
ObjMove_SetY(oo,ObjMove_GetY(obj3271));
yield;


}
Obj_Delete(oo);
}



loop(8){


let qwe=CreateShotA1(ObjMove_GetX(obj3271), ObjMove_GetY(obj3271), 0.5, ans, round(rand(33,40)), 10);
ObjShot_SetAutoDelete(qwe,false);
sd1(qwe);




ans+=360/8;


}

task sd1(oo){
loop(800){
ObjMove_SetAngle(oo,ObjMove_GetAngle(oo)-0.3);
ObjMove_SetSpeed(oo,ObjMove_GetSpeed(oo)+0.1);
ObjMove_SetX(oo,ObjMove_GetX(obj3271));
ObjMove_SetY(oo,ObjMove_GetY(obj3271));
yield;


}
Obj_Delete(oo);
}


loop(8){


let qwe=CreateShotA1(ObjMove_GetX(obj3271), ObjMove_GetY(obj3271), 1.5, ans, round(rand(33,40)), 10);
ObjShot_SetAutoDelete(qwe,false);
sd11(qwe);




ans+=360/8;


}

task sd11(oo){
loop(800){
ObjMove_SetAngle(oo,ObjMove_GetAngle(oo)+0.6);
ObjMove_SetSpeed(oo,ObjMove_GetSpeed(oo)+0.1);
ObjMove_SetX(oo,ObjMove_GetX(obj3271));
ObjMove_SetY(oo,ObjMove_GetY(obj3271));
yield;


}
Obj_Delete(oo);}


}
let down=0;
task circle2(x,y){
let ggg=rand(0.1,2);
//P//laySE(tana);


 let obj55=CreateShotA1(x,y, 0, rand(0,360),  105, 0);

stop(obj55);
ooo2+=18.34939485;


task stop(oo){
ll;




task ll{

loop{ObjShot_SetAutoDelete(oo,false);
yield;

if(step==0){
ObjMove_SetY(oo,ObjMove_GetY(oo)+down);
}


if(step==1){
ObjMove_SetX(oo,ObjMove_GetX(oo)-down);
}


if(step==2){
ObjMove_SetY(oo,ObjMove_GetY(oo)-down);
}


if(step==3){
ObjMove_SetX(oo,ObjMove_GetX(oo)+down);
}



if(down==0){


wait(10);
CreateLooseLaserA1(ObjMove_GetX(oo),ObjMove_GetY(oo),20,ObjMove_GetAngle(oo),1700,-8,156,0);
wait(60);
PlaySE(las);
task sss{loop(150/6){
CreateLooseLaserA1(ObjMove_GetX(oo),ObjMove_GetY(oo),20,ObjMove_GetAngle(oo),700,25,153,0);
wait(10);
}}
sss;
wait(300);

loop(50){
wait(4);
ooo+=3.543534534;

ObjMove_SetSpeed(oo,ObjMove_GetSpeed(oo)+0.05);wait(2);and+=5.945534;}

break;
}


}

}

loop(3){ObjShot_SetAutoDelete(oo,false);
let ran=rand(-13,13);

wait(60);
}





}




}


let ooo=0;
let ooo2=0;

@MainLoop
{yield;SetAutoDeleteObject(true);
	//敵の座標を取得
	let ex = ObjMove_GetX(objEnemy);
	let ey = ObjMove_GetY(objEnemy);

		let px = GetPlayerX();
		let py = GetPlayerY();

	
		let ATP = atan2(py - ey, px - ex);


	if(dam==0){ObjEnemy_SetDamageRate(objEnemy,0,0);}
	if(dam==1){ObjEnemy_SetDamageRate(objEnemy,90,10);}
	

	//当たり判定登録
	ObjEnemy_SetIntersectionCircleToShot(objEnemy, ex, ey, 32);//当たり判定(自機弾用)登録
	ObjEnemy_SetIntersectionCircleToShot(objEnemy, ex, ey+30, 32);//当たり判定(自機弾用)登録
	ObjEnemy_SetIntersectionCircleToPlayer(objEnemy, ex, ey, 32);//当たり判定(体当たり用)登録
	ObjEnemy_SetIntersectionCircleToPlayer(objEnemy, ex, ey+20, 32);//当たり判定(体当たり用)登録
	ObjEnemy_SetIntersectionCircleToPlayer(objEnemy, ex, ey-20, 32);//当たり判定(体当たり用)登録

	//カウンタに1追加
	frame++;

SetForbidPlayerSpell(true);
	//ライフ0処理
	
}




task end{
while(ObjEnemy_GetInfo(objEnemy,INFO_LIFE)>0){yield;}
Obj_Delete(objEnemy);
CloseScript(GetOwnScriptID);}
