//#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 ~ "spel2l.png" ;
let sbg = GetCurrentScriptDirectory ~ "sppan.jpg" ;
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 time = GetCurrentScriptDirectory ~ "./Sounds/se_timeout.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" ;
let bgam1 = GetCurrentScriptDirectory ~ "./Sounds/Last.mp3" ;
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(bgam1);
LoadSound(don2);
LoadSound(time);
LoadSound(las);
LoadSound(tana);
LoadSound(boo);
LoadSound(fault);
LoadSound(pow);
LoadSound(dec);
LoadSound(bgam);
LoadSound(ki);
	//敵オブジェクトを生成し登録
		
//PlayBGM(bgam1,0,69);
	//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, 110, 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,2560,1600);
ObjRender_SetAlpha(bg1q,0);
ObjSprite2D_SetDestCenter(bg1q);
ObjRender_SetPosition(bg1q,GetStgFrameWidth/2+230,200,0);



/////



////

task bax(vv){
wait(300);
while(!Obj_IsDeleted(vv)){
yield;
ObjRender_SetAlpha(bg1q,alal);

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

ObjRender_SetScaleXYZ(bg1q,0.4,0.4,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(9800);
	}
	case(EV_REQUEST_TIMER)
	{
		//敵ライフを要求された
		SetScriptResult(70);
	}
}

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," '' Space Panorama ''");

task innn{
loop(60){al2+=3.95;ObjRender_SetPosition(bg1,55+al2+40,SCREEN_HEIGHT-150+10,0);
ObjRender_SetPosition(ttt,-90+al2-30+120,SCREEN_HEIGHT-150,0);
yield;}
wait(30);
loop(45){ObjRender_SetPosition(bg1,55+al2+40,SCREEN_HEIGHT-150-al23+10,0);
ObjRender_SetPosition(ttt,-90+al2-30+120,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 sda{
}
task move{
//
//

let ag=0;
let ag2=0;

wait(120);
af3=1;let f=0;
alal=255;
task s{
loop(60){f+=16/60;
SetPlayerClip(32-f*2,16-f/2,SCREEN_WIDTH, SCREEN_HEIGHT-32);
SetStgFrame(32-f*2,16-f/4,SCREEN_WIDTH,SCREEN_HEIGHT-16,1,80);
yield;}}



PlaySE(cha);
StarConcentration(objEnemy,90);
StarConcentration(objEnemy,110);
wait(180);




s;
//(32, 16, 416, 464, 20, 80).


SShake(5,90);
TExplosionA(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),5,1);
TExplosionA(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),2,0.1);
TExplosionA(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy),3.5,0.5);
cutin(NAZRIN,cut,0,0,435,558);
SetForbidPlayerSpell(true);
sda;

PlaySE(dec);
tex;


wait(30);
af3=0;
wait(120);

ObjMove_SetDestAtWeight(objEnemy, SCREEN_WIDTH/2, SCREEN_HEIGHT/2-100, 10,3);

PlaySE(cha);
StarConcentration(objEnemy,90);
StarConcentration(objEnemy,110);
wait(180);
af3=1;dam=1;
loop(5){
step1;
step12;
wait(60);
step123;
step1234;
wait(60);
}

let sap=0;
wait(120);
step2;


down=2.5;
wait(30);
af3=0;
wait(30);
wait(30);

PlaySE(cha);
StarConcentration(objEnemy,90);
wait(180);
fasad;

task fasad{
wait(720-180);
PlaySE(cha);
StarConcentration(objEnemy,90);
wait(180);sap=1;
step22;

wait(240);
PlaySE(cha);
StarConcentration(objEnemy,90);
wait(180);
step222;

}

loop{
yield;
if(sap==0){
step3(0,0,0,12,0,40,round(rand(121,128)));wait(120);
step3(0,12,0,0,90,80,round(rand(121,128)));wait(120);
step3(GetStgFrameWidth,0,0,12,180,40,round(rand(121,128)));wait(120);}

if(sap==1){
step3(0,0,0,12,0,40,round(rand(121,128)));wait(180);
step3(0,12,0,0,90,80,round(rand(121,128)));wait(180);
step3(GetStgFrameWidth,0,0,12,180,40,round(rand(121,128)));wait(180);}



}










}let down=0;

let war=0;

let aa3=0;

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

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

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


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

	//当たり判定登録
	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++;

	//ライフ0処理
	
}


task step1{

PlaySE(tana);
loop(45){
let obj21=CreateShotA1(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy), 1.5, dd+dd2, DS_STAR_S_BLUE, 10);
//let obj211=CreateShotA1(ObjMove_GetX(objEnemy)-50*cos(sc),ObjMove_GetY(objEnemy)-50*sin(sc), 1, dd+dd2, DS_STAR_S_PURPLE, 10);
slow(obj21);
dd+=360/45;
}

task slow(o){
loop(15){wait(4);
ObjMove_SetSpeed(o,ObjMove_GetSpeed(o)-0.1);

}
PlaySE(ki);
let anna=rand(0,5);
loop(90){wait(1);
ObjMove_SetSpeed(o,ObjMove_GetSpeed(o)+0.02);
ObjMove_SetAngle(o,ObjMove_GetAngle(o)+anna);

}
loop(90){wait(1);
ObjMove_SetAngle(o,ObjMove_GetAngle(o)+anna/3);

}

}



}



task step12{

PlaySE(tana);
loop(45){
let obj21=CreateShotA1(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy), 1.5, dd+dd2, DS_STAR_S_SKY, 10);
//let obj211=CreateShotA1(ObjMove_GetX(objEnemy)-50*cos(sc),ObjMove_GetY(objEnemy)-50*sin(sc), 1, dd+dd2, DS_STAR_S_PURPLE, 10);
slow(obj21);
dd+=360/45;
}

task slow(o){
loop(15){wait(4);
ObjMove_SetSpeed(o,ObjMove_GetSpeed(o)-0.1);

}
PlaySE(ki);
let anna=rand(0,5);
loop(90){wait(1);
ObjMove_SetSpeed(o,ObjMove_GetSpeed(o)+0.02);
ObjMove_SetAngle(o,ObjMove_GetAngle(o)+anna);

}
loop(90){wait(1);
ObjMove_SetAngle(o,ObjMove_GetAngle(o)+anna/3);

}

}

dd2+=18.56524;

}










//////////

task step123{

PlaySE(tana);
loop(45){
let obj21=CreateShotA1(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy), 1.5, dd+dd2, DS_STAR_S_RED, 10);
//let obj211=CreateShotA1(ObjMove_GetX(objEnemy)-50*cos(sc),ObjMove_GetY(objEnemy)-50*sin(sc), 1, dd+dd2, DS_STAR_S_PURPLE, 10);
slow(obj21);
dd+=360/45;
}

task slow(o){
loop(15){wait(4);
ObjMove_SetSpeed(o,ObjMove_GetSpeed(o)-0.1);

}
PlaySE(ki);
let anna=rand(0,5);
loop(90){wait(1);
ObjMove_SetSpeed(o,ObjMove_GetSpeed(o)+0.02);
ObjMove_SetAngle(o,ObjMove_GetAngle(o)-anna);

}
loop(90){wait(1);
ObjMove_SetAngle(o,ObjMove_GetAngle(o)-anna/3);

}

}



}



task step1234{

PlaySE(tana);
loop(45){
let obj21=CreateShotA1(ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy), 1.5, dd+dd2, DS_STAR_S_PURPLE, 10);
//let obj211=CreateShotA1(ObjMove_GetX(objEnemy)-50*cos(sc),ObjMove_GetY(objEnemy)-50*sin(sc), 1, dd+dd2, DS_STAR_S_PURPLE, 10);
slow(obj21);
dd+=360/45;
}

task slow(o){
loop(15){wait(4);
ObjMove_SetSpeed(o,ObjMove_GetSpeed(o)-0.1);

}
PlaySE(ki);
let anna=rand(0,5);
loop(90){wait(1);
ObjMove_SetSpeed(o,ObjMove_GetSpeed(o)+0.02);
ObjMove_SetAngle(o,ObjMove_GetAngle(o)-anna);

}
loop(90){wait(1);
ObjMove_SetAngle(o,ObjMove_GetAngle(o)-anna/3);

}

}

dd2+=18.56524;

}
///////////




let ggg=0;
task step2{
//129 136
let asd=0;
let gr=129;
loop{PlaySE(ki);

loop(5){
let obj21=CreateShotA1(ObjMove_GetX(objEnemy)+50*cos(ggg),ObjMove_GetY(objEnemy)+50*sin(ggg), 2, dd+dd2, 23, 10);


ggg+=360/5;
dd+=360/5;

}
gr+=1;asd+=19.986756;ggg+=3.564;
//ggg+=24;
if(gr>136){gr=129;}
dd2+=8.758665;
wait(9);

}}

let dd3=0;
let dd23=0;
let ggg2=0;
task step22{
//129 136
let asd=0;
let gr=129;
loop{PlaySE(ki);

loop(5){
let obj21=CreateShotA1(ObjMove_GetX(objEnemy)-90*cos(ggg2),ObjMove_GetY(objEnemy)-90*sin(ggg2), 1.5, dd3-dd23, 21, 10);


ggg2+=360/5;
dd3+=360/5;

}
gr+=1;asd+=19.986756;ggg2+=-3.564;
//ggg+=24;
if(gr>136){gr=129;}
dd23+=8.758665;
wait(9);

}}


let ggg22=0;
let ggg23=0;
let ggg223=0;
let dd233=0;
task step222{
//129 136
let asd=0;
let gr=129;
loop{PlaySE(ki);

loop(5){
let obj21=CreateShotA1(ObjMove_GetX(objEnemy)-130*cos(ggg23),ObjMove_GetY(objEnemy)-130*sin(ggg23), 1.3, dd3-dd233, 17, 10);


ggg23+=360/5;
dd3+=360/5;

}
gr+=1;asd+=19.986756;ggg23+=-3.564;
//ggg+=24;
if(gr>136){gr=129;}
dd233+=13.758665;
wait(6);

}}


let yy=0;
let xx=0;

task step3(x,incx,y,incy,an,loo,graa){
PlaySE(tana);

loop(loo){


let obj21=CreateShotA1(x+xx,y+yy, 1, an, graa, 10);

yy+=incy;
xx+=incx;


slow(obj21);






}
xx=0;
yy=0;



task slow(o){
loop(10){wait(4);
ObjMove_SetSpeed(o,ObjMove_GetSpeed(o)-0.1);

}
PlaySE(ki);
let anna=rand(0,5);
let varq=round(rand(1,2));

if(varq==1){
loop(90){wait(1);
ObjMove_SetSpeed(o,ObjMove_GetSpeed(o)+0.01);


}

}

if(varq==2){
loop(90){wait(1);
ObjMove_SetSpeed(o,ObjMove_GetSpeed(o)-0.01);


}

}

}


}





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

SetPlayerClip(0, 16, 380, 444);
SetStgFrame(32, 16, 416, 464, 20, 80);

yield;
CloseScript(GetOwnScriptID);}
