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


#include"./lib/SHOT_REPLACE/shot_replace.dnh"
#include"./Youmuinclude.txt"
let color2 = 1;
let color = 0;
let size = 0;
let youmucutin2 = GetCurrentScriptDirectory~"sprites/youmughost.png";
let angle5 = 0;
let objEnemy;
let phase = 1;
let blah = false;
let objEnemy2;
let duration = 0;
let p = 0;
let stopstuff = false;
let angle = 0;
let angle2 = 0;
let type = 0;
let animframe = 0;
let angle4 = 0;
let frame = 0;
let objlasers = [];
let radius = 0;
let GetSpeedX = 0;
let angle3 = 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(boom);
	LoadSound(shot);
	LoadSound(shot2);
	LoadSound(shot3);
	LoadSound(shot4);
	LoadSound(slash);
	LoadSound(timeslow);
	LoadSound(charge2);
	LoadSound(ping);
	LoadSound(weird);
	LoadSound(cardcall);
	objEnemy = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objEnemy);
	objEnemy2 = ObjEnemy_Create(OBJ_ENEMY);
	ObjEnemy_Regist(objEnemy2);
	Invuln(420, 15, 0);
	//BottomEnemyMarker(objEnemy, objEnemy);
	let Youmu = GetCurrentScriptDirectory~"sprites/Youmu.png";
	ObjPrim_SetTexture(objEnemy, Youmu); 
	ObjPrim_SetTexture(objEnemy2, Youmu);
	ObjSprite2D_SetSourceRect(objEnemy, 0, 0, 128, 128);
	ObjSprite2D_SetSourceRect(objEnemy2, 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); 
	
	ascent(x in 0..3){ObjAnim_AddFrameA1(objEnemy2, ANIM_IDLE, 0, 128*x, 128, 128*x+128);}
	ascent(x in 0..2){ObjAnim_AddFrameA1(objEnemy2, ANIM_IDLE, 128, 128*x, 256, 128*x+128);}
	ascent(x in 0..2){ObjAnim_AddFrameA1(objEnemy2, ANIM_MOVE_LEFT, 256, 128*x, 256+128, 128*x+128);}
	ObjAnim_AddFrameA1(objEnemy2, ANIM_MOVEEND_LEFT, 0, 0, 128, 128);
	ascent(x in 2..4){ObjAnim_AddFrameA1(objEnemy2, ANIM_MOVE_RIGHT, 256, 128*x, 256+128, 128*x+128);}
	ObjAnim_AddFrameA1(objEnemy2, ANIM_MOVEEND_RIGHT, 0, 0, 128, 128);
	ascent(x in 0..4){ObjAnim_AddFrameA1(objEnemy2, ANIM_ATTACK, 128*4, 128*x, 128*5, 128*x+128);}
	ascent(x in 2..4){ObjAnim_AddFrameA1(objEnemy2, ANIM_ATTACKEND, 128*5, 128*x, 128*6, 128*x+128);}
	loop(4){ ObjAnim_AddFrameA1(objEnemy2, ANIM_ATTACKEND, 128*5, 128*7, 128*6, 128*7+128); }
	descent(x in 2..4){ ObjAnim_AddFrameA1(objEnemy2, ANIM_ATTACKEND, 128*5, 128*x, 128*6, 128*x+128);}
	descent(x in 0..3){ObjAnim_AddFrameA1(objEnemy2, ANIM_ATTACKEND, 128*4, 128*x, 128*5, 128*x+128);}
	ObjAnim_SetSpeedA1(objEnemy2, ANIM_IDLE, 12);
	ObjAnim_SetSpeedA1(objEnemy2, ANIM_MOVE_LEFT, 6);
	ObjAnim_SetSpeedA1(objEnemy2, ANIM_MOVE_RIGHT, 6);
	ObjAnim_SetSpeedA1(objEnemy2, ANIM_ATTACK, 10);
	ObjAnim_SetLoopPointA1(objEnemy2, ANIM_MOVE_RIGHT, 1);
	ObjAnim_SetLoopPointA1(objEnemy2, ANIM_MOVE_LEFT, 1);
	ObjAnim_SetLoopPointA1(objEnemy2, ANIM_ATTACK, 3);
	ObjAnim_StartAnimationA2(objEnemy2, 0, 0);
	ObjSprite2D_SetDestCenter(objEnemy2); 
	ObjRender_SetAlpha(objEnemy2, 150);
	
	

	ObjEnemy_SetLife(objEnemy2, 1000);
	ObjEnemy_SetDamageRate(objEnemy2, 25, 25);
	Obj_SetVisible(objEnemy2, false);
	delayedstart;
	//attack2;
	SetShotAutoDeleteClip(150, 150, 150, 13);
	
	
}



task delayedstart{
magiccircle(objEnemy, 0.7, true);
ObjMove_SetDestAtFrame(objEnemy, GetCenterX, 120, 105);
ObjMove_SetDestAtFrame(objEnemy2, GetCenterX, 180, 105);
wait(110);

TCharge01(objEnemy, 2+size, 60, 255, 0, 0);
PlaySE(charge2);
wait(10);
size+=1/7;
TCharge01(objEnemy, 2+size, 60, 255, 0, 255);
PlaySE(charge2);
wait(10);
size+=1/7;
TCharge01(objEnemy, 2+size, 60, 0, 255, 255);
PlaySE(charge2);
wait(10);
size+=1/7;
TCharge01(objEnemy, 2+size, 60, 0, 255, 0);
PlaySE(charge2);
wait(10);
size+=1/7;
TCharge01(objEnemy, 2+size, 60, 0, 191, 255);
PlaySE(charge2);
wait(10);
size+=1/7;
TCharge01(objEnemy, 2+size, 60, 0, 0, 255);
PlaySE(charge2);
wait(10);
size+=1/7;
TCharge01(objEnemy, 2+size, 60, 160, 32, 240);
PlaySE(charge2);
wait(10);
size+=1/7;

wait(15);

ObjEnemyBossScene_StartSpell(objScene);
ObjEnemyBossScene_SetSpellTimer(objScene, 75*65);

PlaySE(cardcall);
blah = true;
ObjCutin_SetSpellcardS4("Harmony &quot;Cleansing of the Heart&quot;", youmucutin, YABUSAME, 255, 51, 51);
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;
}	
	ObjEnemy_AddLife(objEnemy, GetCommonData("life", 0));
	GetEnemyX = ObjMove_GetX(objEnemy);
	GetEnemyY = ObjMove_GetY(objEnemy);
	ObjEnemy_SetIntersectionCircleToShot(objEnemy, GetEnemyX, GetEnemyY, 23);
	if(blah==true){
	ObjEnemy_SetIntersectionCircleToPlayer(objEnemy, GetEnemyX, GetEnemyY, 17);
	}
	if(phase==2){
	ObjEnemy_SetIntersectionCircleToShot(objEnemy, ObjMove_GetX(objEnemy2), ObjMove_GetY(objEnemy2), 23);
	}
	//ObjEnemy_SetIntersectionCircleToPlayer(objEnemy, ObjMove_GetX(objEnemy2), ObjMove_GetY(objEnemy2), 17);

	frame++;
	yield;
	GetSpeedX = ObjMove_GetSpeed(objEnemy)*cos(ObjMove_GetAngle(objEnemy));
}


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{
let one = 1;
let wp = 1;
angle = 90+360/6/2;
wait(150);
p = 0;
loop{

if(ObjEnemy_GetInfo(objEnemy, INFO_LIFE)<=500 || ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID, INFO_TIMER)<=45){ Invuln(10000, 0, 0); attack2; attack3;  break; }
if(popped==true){break;}
StartSlow(TARGET_ALL, 30);
SetCommonData("petals", true);
PlaySE(timeslow);
ObjAnim_SetAttackA2(objEnemy, 60);
loop(60){
yield;
if(ObjEnemy_GetInfo(objEnemy, INFO_LIFE)<=500 || ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID, INFO_TIMER)<=45){ Invuln(10000, 0, 0); }
}

angle = angletoplayer(objEnemy)+((360/6/2)*p);
if(popped==true){ break; }
StopSlow(TARGET_ALL);
SetCommonData("petals", false);
PlaySE(slash);
if(ObjEnemy_GetInfo(objEnemy, INFO_LIFE)<=500 || ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID, INFO_TIMER)<=45){ Invuln(10000, 0, 0); attack2; attack3;  break; }
loop(6){
CreateLaser1(ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), angle, WHITE60, 500, 30, 45, 1);
angle+=360/6;
}
loop(40){
if(ObjEnemy_GetInfo(objEnemy, INFO_LIFE)<=500 || ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID, INFO_TIMER)<=45){ Invuln(10000, 0, 0); attack2; attack3;  break; }
PlaySE(shot);
	loop(6){
		loop(2){
		let obj3 = CreateDNHShotA3(ObjMove_GetX(objEnemy)+radius*cos(angle), ObjMove_GetY(objEnemy)+radius*sin(angle),  2, angle+angle2+angle3+angle4, 0, 2, [RED21, ORANGE21, YELLOW21, GREEN21, BLUE21, AQUA21, PURPLE21][color%6], 10);
		ObjMove_AddPatternA2(obj3, 0, NO_CHANGE, NO_CHANGE, 0, 360/(60)*one, 2);
	ObjMove_AddPatternA2(obj3, 70, 1.65, NO_CHANGE, 0, 0, 0);
		ObjMove_AddPatternA2(obj3, 90, 1.75, NO_CHANGE, 0.001, 0, 4);
		angle2+=360/2;
		}
		color++;
		angle+=360/6;
		angle3+=round(rand(20, 340));
		}
		angle4+=rand(0, 360);
		radius+=10.25;
wait(2);
if(ObjEnemy_GetInfo(objEnemy, INFO_LIFE)<=500 || ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID, INFO_TIMER)<=40){ Invuln(10000, 0, 0); break; }
}
if(ObjEnemy_GetInfo(objEnemy, INFO_LIFE)<=500 || ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID, INFO_TIMER)<=40){ Invuln(10000, 0, 0); attack2; attack3;  break; }
radius = 0;
color = round(rand(0, 6));
loop(95){
yield;
if(ObjEnemy_GetInfo(objEnemy, INFO_LIFE)<=500){ Invuln(10000, 0, 0); }
}
p=1-p;


}
}

task attack3{

let one = 1;
let p2 = 0;
let color2 = 0;
let radius2 = 0;
let angle5 = 0;
let angle22 = 0;
let angle32 = 0;
let angle42 = 0;
wait(150);

PlaySE(cardcall);
ObjCutin_SetSpellcardS4("Harmony &quot;Cleansing of the Soul&quot; ", youmucutin2, AYA, 135, 206, 250);
Obj_SetVisible(objEnemy2, true);
phase = 2;
magiccircle(objEnemy2, 0.7, true);
PlaySE(weird);
wait(60);
ObjMove_SetDestAtFrame(objEnemy2, (GetStgFrameWidth/2)+70, 120, 60);
wait(120);
loop{
if(popped==true){break;}
StartSlow(TARGET_ALL, 30);
SetCommonData("petals", true);
PlaySE(timeslow);
ObjAnim_SetAttackA2(objEnemy2, 60);
wait(60);
angle5 = angletoplayer(objEnemy2)+((360/6/2)*p2);
if(popped==true){ break; }
PlaySE(slash);
loop(6){
CreateLaser1(ObjMove_GetX(objEnemy2), ObjMove_GetY(objEnemy2), angle5, WHITE60, 500, 30, 45, 1);
angle5+=360/6;
}
loop(42){
PlaySE(shot);
	loop(6){
		loop(1){
		let obj3 = CreateDNHShotA3(ObjMove_GetX(objEnemy2)+radius*cos(angle5), ObjMove_GetY(objEnemy2)+radius*sin(angle5),  1.9, angle5+angle22+angle32+angle42, 0, 2, [RED21, ORANGE21, YELLOW21, GREEN21, BLUE21, AQUA21, PURPLE21][color2%6], 10);
		ObjMove_AddPatternA2(obj3, 0, NO_CHANGE, NO_CHANGE, 0, 360/(60)*one, 1.9);
	ObjMove_AddPatternA2(obj3, 70, 1.65, NO_CHANGE, 0, 0, 0);
		ObjMove_AddPatternA2(obj3, 90, 1.75, NO_CHANGE, 0.001, 0, 4);
		angle22+=360/1;
		}
		color2++;
		angle5+=360/6;
		angle32+=round(rand(20, 340));
		}
		angle42+=rand(0, 360);
		radius2+=10.0;
wait(2);
if(popped==true){ break; }
}
if(popped==true){ break; }
radius2 = 0;
color2 = round(rand(0, 7));
wait(75);
p2=1-p2;
}
}

task attack2{
let one = 1;
DeleteShotAll(TYPE_SHOT, TYPE_FADE);
radius = 0;
p = 0;
wait(90);
TCharge01(objEnemy, 2+size, 60, 160, 32, 240);
PlaySE(charge2);
wait(60);
wait(60);
ObjMove_SetDestAtFrame(objEnemy, (GetStgFrameWidth/2)-70, 120, 60);
wait(120);

Invuln(30, 15, 0);
loop{

if(popped==true){break;}
StartSlow(TARGET_ALL, 30);
SetCommonData("petals", true);
PlaySE(timeslow);
ObjAnim_SetAttackA2(objEnemy, 60);
wait(60);
angle = angletoplayer(objEnemy)+((360/6/2)*p);
if(popped==true){ break; }
StopSlow(TARGET_ALL);
SetCommonData("petals", false);
PlaySE(slash);
loop(6){
CreateLaser1(ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), angle, WHITE60, 500, 30, 45, 1);
angle+=360/6;
}
loop(42){
PlaySE(shot);
	loop(6){
		loop(1){
		let obj3 = CreateDNHShotA3(ObjMove_GetX(objEnemy)+radius*cos(angle), ObjMove_GetY(objEnemy)+radius*sin(angle),  1.9, angle+angle2+angle3+angle4, 0, 2, [RED21, ORANGE21, YELLOW21, GREEN21, BLUE21, AQUA21, PURPLE21][color%6], 10);
		ObjMove_AddPatternA2(obj3, 0, NO_CHANGE, NO_CHANGE, 0, 360/(60)*one, 1.9);
	ObjMove_AddPatternA2(obj3, 70, 1.65, NO_CHANGE, 0, 0, 0);
		ObjMove_AddPatternA2(obj3, 90, 1.75, NO_CHANGE, 0.001, 0, 4);
		angle2+=360/1;
		}
		color++;
		angle+=360/6;
		angle3+=round(rand(20, 340));
		}
		angle4+=rand(0, 360);
		radius+=10.0;
wait(2);
if(popped==true){ break; }
}
if(popped==true){ break; }
radius = 0;
color = round(rand(0, 7));
wait(75);
p=1-p;


}
}



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

task DestroyBoss{
SetCommonData("petals", false);
popped=true;
StopSlow(TARGET_ALL);
Obj_Delete(objEnemy2);
PlaySE(boom);
StartSlow(TARGET_ALL, 30);
//ObjMove_SetDestAtWeight(objEnemy, ObjMove_GetX(objEnemy)+120, ObjMove_GetY(objEnemy)+rand(-20, 20), 20, 1);
loop(15){ TExpan(ObjMove_GetX(objEnemy)+rand(-35, 35), ObjMove_GetY(objEnemy)+rand(-25, 25), 8, 25, 224, 255, 255, 100); wait(5); }
PlaySE(boom);
TExpan(ObjMove_GetX(objEnemy), ObjMove_GetY(objEnemy), 55, 120, 224, 255, 255, 255);
Obj_Delete(objEnemy);
loop(60){ yield; }
		CloseScript(GetOwnScriptID());
		StopSlow(TARGET_ALL);
		return;
}
