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

//デフォルト弾画像をロード
#include"./Default_ShotConst.txt"
#include"./effect.txt"
#include"./Default_Effect.txt"
let dam=0;

let cut = GetCurrentScriptDirectory ~ "KeCut.png" ;
let cir = GetCurrentScriptDirectory ~ "circle.png" ;
let bg = GetCurrentScriptDirectory ~ "sp2.png" ;
let bg2 = GetCurrentScriptDirectory ~ "bg2.png" ;
let cha = GetCurrentScriptDirectory ~ "./Sounds/se_ch00.wav" ;
let tana = GetCurrentScriptDirectory ~ "./Sounds/se_tan01.wav" ;
let bgam = GetCurrentScriptDirectory ~ "./Sounds/st.mp3" ;
let ki = GetCurrentScriptDirectory ~ "./Sounds/se_kira00.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
{
move;
//SetStgFrame(0, 0, SCREEN_WIDTH, 500, 0,80);
	//自機オブジェクト取得
	objPlayer = GetPlayerObjectID();
LoadSound(cha);
LoadSound(tana);
LoadSound(boo);
LoadSound(bgam);
LoadSound(ki);
	//敵オブジェクトを生成し登録
	objEnemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objEnemy);
	ObjMove_SetDestAtWeight(objEnemy, -120, -120, 10,12);
animate;
	//敵画像の設定
	end;
	//座標(cx, 120)へ60フレームかけて移動する
	let cx = GetStgFrameWidth() / 2;//STGシーンの中心x座標を取得
	StarEffect(objEnemy,11232);
}
let t=0;
let ff=0;
let ff2=0;

let gg=0;
let gg2=0;
let tt=0;
task bullet2{
PlaySE(boo);
loop(16){
let obj3=CreateShotA1(ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), 2, (atan2(GetPlayerY - ObjMove_GetY(objEnemy), GetPlayerX - ObjMove_GetX(objEnemy)))+gg, DS_LIGHT_BLUE, 10);
let obj33=CreateShotA1(ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), 1, ((atan2(GetPlayerY - ObjMove_GetY(objEnemy), GetPlayerX - ObjMove_GetX(objEnemy)))+gg)+120, DS_LIGHT_BLUE, 10);
		ine(obj3,0.01/7,60,-2);
		ine(obj33,0.01/7,60,2);
gg+=360/16;
}
task ine(obb,fa,g,sw){
loop(g){
ObjRender_SetScaleXYZ(obb,tt,tt,0);
ObjMove_SetAngle(obb,ObjMove_GetAngle(obb)+sw);
tt+=fa;
wait(3);
}}tt=0;

}


task bullet{dam=1;
af3=1;t=0;
loop(10){PlaySE(tana);
loop(15){

		let obj=CreateShotA1(ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), 3, ff+ff2, DS_STAR_S_BLUE, 10);
		
		let obj2=CreateShotA1(ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), 2.1, ff-ff2, DS_STAR_S_BLUE, 10);
	

		
		angg;
		task angg{
		loop(21){ObjMove_SetSpeed(obj,ObjMove_GetSpeed(obj)-0.1);wait(3);}
		PlaySE(ki);
		loop(80){ObjMove_SetSpeed(obj,ObjMove_GetSpeed(obj)+0.05);ObjMove_SetAngle(obj,ObjMove_GetAngle(obj)+1.5);wait(3);}
		}
		angg2;
		task angg2{
		loop(30){ObjMove_SetSpeed(obj2,ObjMove_GetSpeed(obj2)-0.1);wait(3);}
		PlaySE(ki);
		loop(80){ObjMove_SetSpeed(obj2,ObjMove_GetSpeed(obj2)+0.05);ObjMove_SetAngle(obj2,ObjMove_GetAngle(obj2)-1.5);wait(3);}
		}
		
ff+=360/15;
}ff2+=17.67;
wait(10);
}
af3=0;
}


///////////
let h=0;

let asd=0;
let asd2=0;

task back{


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;}}


}




task animate{back;
wait(60);
////PlayBGM(bgam,0,379);
ObjMove_SetDestAtWeight(objEnemy, 192, 120, 10,3);
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){




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 ){

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);}

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


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

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);}

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




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









}


}





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

Obj_Delete(objEnemy);
DeleteShotAll(TYPE_ALL,TYPE_ITEM);


CloseScript(GetOwnScriptID);}


@Event
{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE)
	{
		//敵ライフを要求された
		SetScriptResult(1800);//ライフを500に設定
	}
	case(EV_REQUEST_TIMER)
	{
		//敵ライフを要求された
		SetScriptResult(30);//ライフを500に設定
	}
	case(EV_REQUEST_SPELL_SCORE)
	{
		//敵ライフを要求された
		SetScriptResult(15000);//ライフを500に設定
	}
}

let ang=0;
let ang2=0;

task kk{
loop{
yield;
if(dam==0){ObjEnemy_SetDamageRate(objEnemy,0,0);}
	if(dam==1){ObjEnemy_SetDamageRate(objEnemy,50,10);}
}
}

task move{kk;
SetPlayerLife(42);

wait(300);
StarConcentration(objEnemy,90);
PlaySE(cha);
wait(120);
bullet;dam=1;
wait(310);t=0;
loop{

bullet;
wait(120);bullet2;
wait(190);
t=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);


	

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

}

