
#ScriptVersion[3]
#Title["YoumuN3_N"]
#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(55);
	}
}

@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(6){ 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(20){ 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(6){ 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 exp1 = 4;
let exp2 = 6;
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{
ChangeToVertical;
ObjAnim_SetAttackA2(objEnemy, 60);
PlaySE(charge2);
TCharge01(objEnemy, 3, 50, 255, 215, 0);
wait(50);
	if(popped==true){break;}
		ascent(i in 0..12){
		PlaySE(shot);
			loop(25){
				CreateDNHShotA1(ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), 3.65-(i/3.75), angle, YELLOW33, 10);
				angle+=360/25;
			}
				angle+=37.5+(i^exp1)-rand(-2, 2);
				wait(7);
				if(popped==true){break;}
			}
				ObjAnim_SetAttackA2(objEnemy, 60);
				PlaySE(charge2);
				TCharge01(objEnemy, 3, 50, 34, 139, 34);
				wait(50);
				if(popped==true){break;}
				ascent(i in 0..12){
				PlaySE(shot);
			loop(25){
				CreateDNHShotA1(ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), 3.65-(i/3.75), angle, GREEN33, 10);
				angle+=360/25;
			}
				angle+=17.5-(i^exp2)+rand(-2, 2);
				wait(7);
				if(popped==true){break;}
			}
				ObjAnim_SetAttackA2(objEnemy, 60);
				PlaySE(charge2);
				TCharge01(objEnemy, 3, 60, 25, 25, 112);
				wait(60);
				if(popped==true){break;}
				ascent(p in -2..3){
			CreateLaser1(ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), atan2(ObjMove_GetY(objEnemy)-ObjMove_GetY(GetPlayerObjectID), ObjMove_GetX(objEnemy)-ObjMove_GetX(GetPlayerObjectID))-180+(p*22), BLUE12, 600, 100, 20, 1);
			}
			loop(12){
				PlaySE(shot);
				ascent(i in 0..5){
					ascent(p in -2..3){
					
				CreateDNHShotA1(ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), 5-(i*1.05), atan2(ObjMove_GetY(objEnemy)-ObjMove_GetY(GetPlayerObjectID), ObjMove_GetX(objEnemy)-ObjMove_GetX(GetPlayerObjectID))-180+(p*22), BLUE33, 10);
					}
				}
				wait(7);
				if(popped==true){break;}
			}
				wait(35);
				if(popped==true){break;}
				ExMoveNon;
				angle = rand(0, 360);
				wait(60);
				if(popped==true){break;}
				exp1 = rand(3, 5);
				exp2 = rand(5, 7);


}
}

task CreateLaser1(x, y, angle, graphic, length, width, delay, type){
let obj2 = ObjShot_Create(OBJ_STRAIGHT_LASER);
let angle2 = rand(0, 360);
let bulletgraphic = 0;
let one = 1;
let index = 0;
let waitincrement = 0;
ObjMove_SetPosition(obj2, x, y);
ObjStLaser_SetAngle(obj2, angle);
ObjShot_SetGraphic(obj2, graphic);
ObjShot_SetDelay(obj2, delay*20);
ObjLaser_SetLength(obj2, length);
ObjLaser_SetRenderWidth(obj2, width);
ObjShot_SetSpellResist(obj2, true);
ObjStLaser_SetSource(obj2, false);
ObjShot_Regist(obj2);
wait(delay-5);
if(type==0){ wait(5); }
if(type==1){ObjShot_FadeDelete(obj2); }
if(type==0){
PlaySE(ping);
}
ObjLaser_SetRenderWidth(obj2, width/2);
ObjLaser_SetIntersectionWidth(obj2, width/2-3);
wait(delay*2);
ObjShot_FadeDelete(obj2);
}
