
#ScriptVersion[3]
#Title["YoumuN2_H"]
#Text["Bullets"]


#include"./lib/SHOT_REPLACE/shot_replace.dnh"
#include"./Youmuinclude.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(53);
	}
}

@Initialize{
	//Resource Loading
	shotinit;
	LoadSound(shot);
	LoadSound(shot3);
	LoadSound(charge2);
	LoadSound(slash);
	LoadSound(ping);
	objEnemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objEnemy);
	Invuln(180, 65, 75);

	let Youmu = GetCurrentScriptDirectory~"sprites/Youmu.png";
	ObjPrim_SetTexture(objEnemy, Youmu); 
	ObjSprite2D_SetSourceRect(objEnemy, 0, 0, 128, 128);
	ascent(x in 0..3){ObjAnim_AddFrameA1(objEnemy, ANIM_IDLE, 0, 128*x, 128, 128*x+128);}
	ascent(x in 0..2){ObjAnim_AddFrameA1(objEnemy, ANIM_IDLE, 128, 128*x, 256, 128*x+128);}
	ascent(x in 0..2){ObjAnim_AddFrameA1(objEnemy, ANIM_MOVE_LEFT, 256, 128*x, 256+128, 128*x+128);}
	ObjAnim_AddFrameA1(objEnemy, ANIM_MOVEEND_LEFT, 0, 0, 128, 128);
	ascent(x in 2..4){ObjAnim_AddFrameA1(objEnemy, ANIM_MOVE_RIGHT, 256, 128*x, 256+128, 128*x+128);}
	ObjAnim_AddFrameA1(objEnemy, ANIM_MOVEEND_RIGHT, 0, 0, 128, 128);
	ascent(x in 0..4){ObjAnim_AddFrameA1(objEnemy, ANIM_ATTACK, 128*4, 128*x, 128*5, 128*x+128);}
	ascent(x in 2..4){ObjAnim_AddFrameA1(objEnemy, ANIM_ATTACKEND, 128*5, 128*x, 128*6, 128*x+128);}
	loop(1){ ObjAnim_AddFrameA1(objEnemy, ANIM_ATTACKEND, 128*5, 128*7, 128*6, 128*7+128); }
	descent(x in 2..4){ ObjAnim_AddFrameA1(objEnemy, ANIM_ATTACKEND, 128*5, 128*x, 128*6, 128*x+128);}
	descent(x in 0..3){ObjAnim_AddFrameA1(objEnemy, ANIM_ATTACKEND, 128*4, 128*x, 128*5, 128*x+128);}
	ObjAnim_SetSpeedA1(objEnemy, ANIM_IDLE, 12);
	ObjAnim_SetSpeedA1(objEnemy, ANIM_MOVE_LEFT, 6);
	ObjAnim_SetSpeedA1(objEnemy, ANIM_MOVE_RIGHT, 6);
	ObjAnim_SetSpeedA1(objEnemy, ANIM_ATTACK, 9);
	ObjAnim_SetLoopPointA1(objEnemy, ANIM_MOVE_RIGHT, 1);
	ObjAnim_SetLoopPointA1(objEnemy, ANIM_MOVE_LEFT, 1);
	ObjAnim_SetLoopPointA1(objEnemy, ANIM_ATTACK, 3);
	ObjAnim_StartAnimationA2(objEnemy, 0, 0);
	ObjSprite2D_SetDestCenter(objEnemy); 
		//BottomEnemyMarker(objEnemy, objEnemy);
	
	ObjMove_SetDestAtFrame(objEnemy, GetCenterX, 120, 60);
	
	attack1;
	SetShotAutoDeleteClip(70, 70, 70, 10);
	magiccircle(objEnemy, 0.7, true);
	
}




@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, 23);//当たり判定(自機弾用)登録
	ObjEnemy_SetIntersectionCircleToPlayer(objEnemy, GetEnemyX, GetEnemyY, 17);//当たり判定(体当たり用)登録

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




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

task DestroyBoss{
popped=true;
loop(10){ yield; }
Obj_Delete(objEnemy);
loop(40){ yield; }
		CloseScript(GetOwnScriptID());
		return;
}

task ChangeToVertical{
animframe = 0;
	ascent(x in 2..4){ ObjAnim_ReplaceFrameA2(objEnemy, ANIM_ATTACKEND, animframe, 128*5, 128*x, 128*6, 128*x+128, 0, 0); animframe++;}
	loop(1){ ObjAnim_ReplaceFrameA2(objEnemy, ANIM_ATTACKEND, animframe, 128*5, 128*7, 128*6, 128*7+128, 0, 0); animframe++;}
	descent(x in 2..4){ ObjAnim_ReplaceFrameA2(objEnemy, ANIM_ATTACKEND, animframe, 128*5, 128*x, 128*6, 128*x+128, 0, 0); animframe++;}
	descent(x in 0..3){ObjAnim_ReplaceFrameA2(objEnemy, ANIM_ATTACKEND, animframe, 128*4, 128*x, 128*5, 128*x+128, 0, 0); animframe++;}
	}
task ChangeToHorizontal{
animframe = 0;
	ascent(x in 0..2){ ObjAnim_ReplaceFrameA2(objEnemy, ANIM_ATTACKEND, animframe, 128*5, 128*x, 128*6, 128*x+128, 0, 0); animframe++;}
	loop(1){ ObjAnim_ReplaceFrameA2(objEnemy, ANIM_ATTACKEND, animframe, 128*5, 128*1, 128*6, 128*1+128, 0, 0); animframe++;}
	descent(x in 0..2){ ObjAnim_ReplaceFrameA2(objEnemy, ANIM_ATTACKEND, animframe, 128*5, 128*x, 128*6, 128*x+128, 0, 0); animframe++;}
	descent(x in 0..3){ObjAnim_ReplaceFrameA2(objEnemy, ANIM_ATTACKEND, animframe, 128*4, 128*x, 128*5, 128*x+128, 0, 0); animframe++;}
	}

task attack1{
wait(120);
let positionx = 0;
let positiony = 0;
let color = 0;
let angle = 0;
let angle2 = 0;
let type = 1;
let dir = 0;
let yvar = 0;
let increment = 1;
let positionx2 = 0;
let positiony2 = 0;
let xoffset = 0;
let yoffset = 0;
loop{
ChangeToHorizontal;
ObjAnim_SetAttackA2(objEnemy, 60);
PlaySE(charge2);
TCharge01(objEnemy, 3, 60, 0, 0, 128);
wait(60);
	if(popped==true){break;}
	PlaySE(slash);
	//ScreenShake(10, 5);
CreateLaser1(GetClipMinX-50, GetClipMinY+60, rand(-4, 4), BLUE12, 500, 40, 50, -1);	
wait(30);
if(popped==true){break;}
ObjAnim_SetAttackA2(objEnemy, 60);
PlaySE(charge2);
TCharge01(objEnemy, 3, 60, 178, 34, 34);
wait(60);
	if(popped==true){break;}
	PlaySE(slash);
	//ScreenShake(10, 5);
CreateLaser1(GetClipMaxX+50, GetClipMinY+60, rand(180-4, 180+4), RED12, 500, 40, 50, 0);	
wait(120);
if(popped==true){break;}
ChangeToVertical;
ObjAnim_SetAttackA2(objEnemy, 75);
if(popped==true){break;}
PlaySE(charge2);
TCharge01(objEnemy, 3, 75, 160, 30, 240);
wait(75);
if(popped==true){break;}
positionx = ObjMove_GetX(objEnemy);
positiony = GetClipMinY-70;
PlaySE(slash);
//ScreenShake(10, 5);
CreateLaser1(positionx, positiony, atan2(GetPlayerY-positiony, GetPlayerX-positionx), PURPLE12, 800, 60, 75, 1);  
wait(105);
if(popped==true){break;}
ExMoveNon;
wait(75);
if(popped==true){break;}
}
}

task CreateLaser1(x, y, angle, graphic, length, width, delay, type){
let obj = ObjShot_Create(OBJ_STRAIGHT_LASER);
let angle2 = rand(0, 360);
let bulletgraphic = 0;
let one = 1;
let waitincrement = 0;
ObjMove_SetPosition(obj, x, y);
ObjStLaser_SetAngle(obj, angle);
ObjShot_SetGraphic(obj, graphic);
ObjShot_SetDelay(obj, delay);
ObjLaser_SetLength(obj, length);
ObjLaser_SetRenderWidth(obj, width);
ObjLaser_SetIntersectionWidth(obj, 20);
ObjShot_SetSpellResist(obj, true);
ObjStLaser_SetSource(obj, false);
if(type==0){ one=-1.45;}
ObjShot_Regist(obj);
wait2(delay);
PlaySE(ping);
ObjLaser_SetRenderWidth(obj, width/2);
ObjLaser_SetIntersectionWidth(obj, width/2-5);
if(type==-1){ bulletgraphic = BLUE12; }
if(type==0){ bulletgraphic = RED12;}
if(type == 1){ bulletgraphic = PURPLE12; }
if(type<=0){
ascent(i in 0..36){
	loop(4){
		
	CreateDNHShotA2(ObjMove_GetX(obj)+(i*14)*cos(angle), ObjMove_GetY(obj)+(i*14)*sin(angle), 0, angle2+(i*17.575*one), 0.04, 2.72, bulletgraphic, 10);
	CreateDNHShotA2(ObjMove_GetX(obj)+(i*14)*cos(angle), ObjMove_GetY(obj)+(i*14)*sin(angle), 0, angle2+(i*17.575*one), 0.04, 2.67, bulletgraphic, 10);
	CreateDNHShotA2(ObjMove_GetX(obj)+((i*14)-7)*cos(angle), ObjMove_GetY(obj)+((i*14)-7)*sin(angle), 0, angle2+(i*17.575*one)+45, 0.04, 1.73525, bulletgraphic, 10);
	CreateDNHShotA2(ObjMove_GetX(obj)+((i*14)-7)*cos(angle), ObjMove_GetY(obj)+((i*14)-7)*sin(angle), 0, angle2+(i*17.575*one)+45, 0.04, 1.71, bulletgraphic, 10);
	
	angle2+=360/4;
	}
	waitincrement++;
	if(waitincrement%2==0){
		if(popped==false){
	wait(1);
	}
	
	}
	
	}
wait2(delay-18);
	}
if(type==1){
	
ascent(i in 0..22){
	loop(3){
	
		ascent(p in -1..2){
	CreateDNHShotA2(ObjMove_GetX(obj)+((i*33.9090909091)+(p*7))*cos(angle), ObjMove_GetY(obj)+((i*33.9090909091)+(p*7))*sin(angle), 0, angle2+(i*27.4090909091), 0.0375, 2.25, bulletgraphic, 10);
	CreateDNHShotA2(ObjMove_GetX(obj)+((((i*33.9090909091)-13.5))+(p*7))*cos(angle), ObjMove_GetY(obj)+((((i*33.9090909091)-13.5))+(p*7))*sin(angle), 0, angle2+(i*27.4090909091), 0.0325, 1.25, bulletgraphic, 10);
		}
	angle2+=360/3;
	}
	waitincrement++;
	if(waitincrement%2==0){
	if(popped==false){
	wait(1);
	}
	
	}
	
	}
wait2(delay-13);
	}
ObjShot_FadeDelete(obj);


function wait2(f){ loop(f){ if(popped==true){ ObjShot_FadeDelete(obj); } yield;} }
}