//#TouhouDanmakufu
#ScriptVersion[3]
#Title["AliceN1_H"]
#Text["Bullets"]


#include"./../lib/SHOT_REPLACE/shot_replace.dnh"
#include"./../includes/BossIncludes.txt"

let objEnemy;
let duration = 0;
let stopstuff = false;
let angle = 0;
let angle2 = 0;
let animframe = 0;
let frame = 0;
let GetSpeedX = 0;
let variable = 0;
let n = 0;
@Event{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
	SetScriptResult(3000);
	}
	case(EV_REQUEST_TIMER){
	SetScriptResult(24);
	}
}


@Initialize{
	//Resource Loading
	shotinit;
	
	objEnemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objEnemy);
	Invuln(60, 120, 75);
	SetCommonData("alive", true);
	let Reimu = GetCurrentScriptDirectory~"sprites/cirno.png";
	ObjPrim_SetTexture(objEnemy, Reimu); 
	ObjSprite2D_SetSourceRect(objEnemy, 0, 0, 128, 128);
	ascent(x in 0..3){
	ObjAnim_AddFrameA2(objEnemy, ANIM_IDLE, 0, 0+x*128, 128, 128+x*128, 0, 0);
	}
	ascent(x in 0..2){
	ObjAnim_AddFrameA2(objEnemy, ANIM_IDLE, 128, 0+x*128, 256, 128+x*128, 0, 0);
	}
	ascent(x in 0..2){ObjAnim_AddFrameA2(objEnemy, ANIM_MOVE_LEFT, 256, 128*x, 256+128, 128*x+128, 1, 0);}
	
	
	ascent(x in 2..4){ObjAnim_AddFrameA2(objEnemy, ANIM_MOVE_RIGHT, 256, 128*x, 256+128, 128*x+128, 0, 0);}
	
	ObjAnim_AddFrameA2(objEnemy, ANIM_MOVEEND_RIGHT, 256, 128*2, 128*3, 128*2+128, 0, 0);
	ObjAnim_AddFrameA2(objEnemy, ANIM_MOVEEND_RIGHT, 0, 0, 128, 128, 0, 0);
	ObjAnim_AddFrameA2(objEnemy, ANIM_MOVEEND_LEFT, 256, 0, 128*3, 128, 0, 0);
	ObjAnim_AddFrameA2(objEnemy, ANIM_MOVEEND_LEFT, 0, 0, 128, 128, 0, 0);
	
	ascent(x in 0..3){ ObjAnim_AddFrameA2(objEnemy, ANIM_ATTACK, 128*6, 128*x, 128*7, 128*x+128, 0, 0);}
	ascent(x in 0..3){ ObjAnim_AddFrameA2(objEnemy, ANIM_ATTACK, 128*7, 128*x, 128*8, 128*x+128, 0, 0);}
	
	

	ObjAnim_AddFrameA2(objEnemy, ANIM_ATTACKEND, 128*6, 128, 128*7, 128*2, 0, 0);
	ObjAnim_AddFrameA2(objEnemy, ANIM_ATTACKEND, 128*7, 128*3, 128*8, 128*4, 0, 0);
	
	ObjAnim_SetSpeedA1(objEnemy, ANIM_IDLE, 12);
	ObjAnim_SetSpeedA1(objEnemy, ANIM_MOVE_LEFT, 8);
	ObjAnim_SetSpeedA1(objEnemy, ANIM_MOVE_RIGHT, 8);
	ObjAnim_SetSpeedA1(objEnemy, ANIM_ATTACK, 8);
	ObjAnim_SetLoopPointA1(objEnemy, ANIM_MOVE_RIGHT, 1);
	ObjAnim_SetLoopPointA1(objEnemy, ANIM_MOVE_LEFT, 1);
	ObjAnim_SetLoopPointA1(objEnemy, ANIM_ATTACK, 1);
	ObjAnim_StartAnimationA2(objEnemy, 0, 0);
		ObjSprite2D_SetDestCenter(objEnemy);  
	//BottomEnemyMarker(objEnemy, objEnemy);
	//ObjMove_SetDestAtFrame(objEnemy, GetCenterX, GetClipMinY+120, 90);
	
	attack1;
	SetShotAutoDeleteClip(60, 60, 60, 20);
	
}

@MainLoop{
	
	
	if(ObjEnemy_GetInfo(objEnemy, INFO_LIFE) <=0 && stopstuff==false){stopstuff=true;}

	GetEnemyX = ObjMove_GetX(objEnemy);
	GetEnemyY = ObjMove_GetY(objEnemy);
	ObjEnemy_SetIntersectionCircleToShot(objEnemy, GetEnemyX, GetEnemyY, 25);//当たり判定(自機弾用)登録
	ObjEnemy_SetIntersectionCircleToPlayer(objEnemy, GetEnemyX, GetEnemyY, 17);//当たり判定(体当たり用)登録

	frame++;
	yield;
	GetSpeedX = ObjMove_GetSpeed(objEnemy)*cos(ObjMove_GetAngle(objEnemy));
	SetCommonData("sakuyax", ObjMove_GetX(objEnemy));
	SetCommonData("sakuyay", ObjMove_GetY(objEnemy));




if(stopstuff==true && popped==false){
DestroyBoss;
}	
	
}

task DestroyBoss{

popped=true;
SetCommonData("alive", false);
loop(10){ yield; }
Obj_Delete(objEnemy);
loop(20){ yield; }
		CloseScript(GetOwnScriptID());
		return;
}




task thin{
ascent(i in 0..7){
ObjRender_SetScaleXYZ(objEnemy, 1-(i/7), 1+(i/7), 1);
yield;
}
descent(i in 0..7){
ObjRender_SetScaleXYZ(objEnemy, 1-(i/7), 1+(i/7), 1);
yield;
}
}

task attack1{	
//wait(75);
let one = -1;

let angle2 = 0;
let color = 0;
let angle3 = 0;
let randnum = 7;
if(popped==true){return;}
wait(45);
if(popped==true){return;}

loop{
//ObjAnim_SetAttackA2(objEnemy, 164);

ascent(i in 0..20){
if(i%5==0){
ExMove(GetClipMinY+120, 12, rand(20, 30));
if(i==10){
ExMove(GetClipMinY+180, 12, rand(20, 30));
}
}
PlaySoundEffect("shot", 80, GetEnemyX);
	if(i%2==0){
loop(10){
	ascent(p in -1..2){
	CreateDNHShotA1(GetEnemyX, GetEnemyY, 3-(i/18)-(absolute(p)/13), angle+(p*0.5), BLUE23, 10);
	}
	angle+=360/10;
	}
}
else{
loop(10){
	ascent(p in -1..2){
	CreateDNHShotA1(GetEnemyX, GetEnemyY, 2.4-(i/24)+(absolute(p)/15), angle+(p*0.5), BLUE23, 10);
	}
	angle+=360/10;
	}
	}
	angle+=25*one;
wait(10);
if(popped==true){ return; }
}
one*=-1;
wait(30);
if(popped==true){ return; }

}
}
