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


#include"./lib/SHOT_REPLACE/shot_replace.dnh"
#include"./Youmuinclude.txt"
let color2 = 1;
let color = 0;
let objEnemy;
let one = 1;
let duration = 0;
let stopstuff = false;
let angle = 0;
let angle2 = 0;
let type = 0;
let animframe = 0;
let frame = 0;
let objlasers = [];
let GetSpeedX = 0;
let variable = 0;
let n = 0;
@Event{
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
	SetScriptResult(1000);
	}
	case(EV_REQUEST_TIMER){
	SetScriptResult(999);
	}
	case(EV_REQUEST_SPELL_SCORE){
	SetScriptResult(10000000);
	}
	case(EV_GAIN_SPELL)
	{
	AddScore(ObjEnemyBossScene_GetInfo(objScene, INFO_SPELL_SCORE));	
	}
}

@Initialize{
	//Resource Loading
	shotinit;
	LoadSound(shot);
	LoadSound(shot2);
	LoadSound(shot3);
	LoadSound(timeslow);
	LoadSound(shot4);
	LoadSound(slash);
	LoadSound(charge2);
	LoadSound(ping);
	LoadSound(cardcall);
	objEnemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objEnemy);
	Invuln(360, 25, 25);
	//BottomEnemyMarker(objEnemy, objEnemy);
	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(4){ 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, 10);
	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); 
	
	
	

	
	delayedstart;
	//attack2;
	SetShotAutoDeleteClip(30, 100, 30, 10);
	
	
}



task delayedstart{
magiccircle(objEnemy, 0.7, true);
ObjMove_SetDestAtFrame(objEnemy, GetCenterX, 120, 60);
wait(60);

ObjEnemyBossScene_StartSpell(objScene);
ObjEnemyBossScene_SetSpellTimer(objScene, 60*46);

PlaySE(cardcall);
ObjCutin_SetSpellcardS4("Insight &quot;Components of Danmaku&quot;", youmucutin, YABUSAME, 32, 178, 170);
ObjCutin_LaunchS3(BYAKUREN, youmucutin, "Normal");
wait(60);
attack1;
}


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

		
if(stopstuff==true && popped==false){
DestroyBoss;
}	
	
	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));
}

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);
ObjLaser_SetLength(obj2, length);
ObjLaser_SetRenderWidth(obj2, width);
ObjLaser_SetIntersectionWidth(obj2, 20);
ObjShot_SetSpellResist(obj2, true);
ObjStLaser_SetSource(obj2, false);
ObjLaser_SetInvalidLength(obj2, 10, 10);
ObjShot_Regist(obj2);
ObjMove_SetPosition(obj2, x-75*cos(ObjStLaser_GetAngle(obj2)), y-75*sin(ObjStLaser_GetAngle(obj2)));

objlasers = objlasers ~ [obj2];

Wait2(delay);
PlaySE(slash);
ObjLaser_SetRenderWidth(obj2, width/2);
ObjLaser_SetIntersectionWidth(obj2, width/2-5);
Wait2(delay);
objlasers = [];
ObjShot_FadeDelete(obj2);

function Wait2(f){ loop(f){ if(popped==true){ Obj_Delete(obj2); } yield;  } }

}


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(8){ 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(8){ 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 objlasers = [];
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{
color2++;
attack2;
wait(120);
if(popped==true){break;}
StartSlow(TARGET_ALL, 30);
SetCommonData("petals", true);
PlaySE(timeslow);
ObjAnim_SetAttackA2(objEnemy, 60);

//PlaySE(slash);

	loop(14){
		ascent(i in 0..2){
			CreateLaser1(GetEnemyX+60*cos(angle), GetEnemyY+60*sin(angle), atan2(GetEnemyY-(GetEnemyY+60*sin(angle)), GetEnemyX-(GetEnemyX+60*cos(angle)))+90+(i*180), BLUE12, 650, 40, 60, type);
			type++;
			}
			angle+=360/14;
			}
			wait(20);
			PlaySE(charge2);
			TCharge01(objEnemy, 3, 40, 65, 105, 225);
			wait(40);
			StopSlow(TARGET_ALL);
			SetCommonData("petals", false);
			wait(180);
			if(popped==true){break;}
			angle = atan2(ObjMove_GetY(GetPlayerObjectID)-GetEnemyY, ObjMove_GetX(GetPlayerObjectID)-GetEnemyX);
			ExMoveNon;
			wait(120);
			one*=-1;
			if(popped==true){break;}
			

}
}

task attack2{
let angle3 = rand(0, 360);
let a = 0;

PlaySE(charge2);
TCharge01(objEnemy, 3, 60, 178, 34, 34);
loop(35){
if(a%2==0){
//PlaySE(shot2);
}
if(popped==true){break;}
a++;
	loop(5){
CreateSpecialDNHShotA2(GetEnemyX+30*cos(angle3), GetEnemyY+40*sin(angle3), 0, angle3, 0.06, 6.5, [RED02, YELLOW02][color2%2], 10);
angle3+=360/5;
	}
	angle3+=19.45765398765*one;
wait(6);
}
}
task CreateSpecialDNHShotA2 ( let x, let y, let v, let angle, let vAcc, let vF, let graphic, let delay ) {
	if(graphic==RED02){ color = 0; } if(graphic==YELLOW02){ color = 1; }
	let obj = CreateShotA2(x, y, 0, angle, 0, 0, graphic, 0);
	Obj_SetValue(obj, VALUE_SHOT_TYPE, Obj_GetType(obj));
	CreateDelayCloud(obj, v, angle, vAcc, vF, graphic, delay);
	ObjRender_SetAlpha(obj, 0);
	ObjShot_SetSpellResist(obj, true);
	while(!Obj_IsDeleted(obj)){
	ascent(j in 0..length(objlasers)){
		if(IsIntersected_Obj_Obj(obj, objlasers[j])==true){ 
		if(GetDistance(GetEnemyX, GetEnemyY, ObjMove_GetX(obj), ObjMove_GetY(obj))<=90){
			loop(3){ CreateDNHShotA2(ObjMove_GetX(obj), ObjMove_GetY(obj), 0, angle2+angle, 0.02, 1.35, [PURPLE05, GREEN05][color%2], round(GetDistance(GetEnemyX, GetEnemyY, ObjMove_GetX(obj), ObjMove_GetY(obj))/2));
					 CreateDNHShotA2(ObjMove_GetX(obj), ObjMove_GetY(obj), 0, angle2+angle+(360/3/2), 0.02, 0.95, [PURPLE05, GREEN05][color%2], round(GetDistance(GetEnemyX, GetEnemyY, ObjMove_GetX(obj), ObjMove_GetY(obj))/2));angle2+=360/3; }Obj_Delete(obj); }
			else{ loop(3){ CreateDNHShotA2(ObjMove_GetX(obj), ObjMove_GetY(obj), 0, angle2+angle, 0.02, 1.35, [RED01, YELLOW01][color%2], 50); 
						   CreateDNHShotA2(ObjMove_GetX(obj), ObjMove_GetY(obj), 0, angle2+angle+(360/3/2), 0.02, 1.6, [RED01, YELLOW01][color%2], 20);angle2+=360/3; }Obj_Delete(obj); }
			}
		}
	
	Wait2(1);
	}
	
	
	
function Wait2(f){ loop(f){ if(popped==true){ ObjShot_FadeDelete(obj); } yield;  } }	
}

task DestroyBoss{
SetCommonData("petals", false);
popped=true;
StopSlow(TARGET_ALL);
loop(10){ yield; }
Obj_Delete(objEnemy);
loop(40){ yield; }
		CloseScript(GetOwnScriptID());
		return;
}
