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


#include"./lib/SHOT_REPLACE/shot_replace.dnh"
#include"./Youmuinclude.txt"
let color2 = 1;
let color = 0;
let objEnemy;
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, 50, 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); 
	
	
	ObjMove_SetDestAtFrame(objEnemy, GetCenterX, 120, 60);

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



task delayedstart{
magiccircle(objEnemy, 0.7, true);
ObjMove_SetDestAtFrame(objEnemy, GetCenterX, 120, 60);
wait(60);
ObjEnemyBossScene_StartSpell(objScene);
ObjEnemyBossScene_SetSpellTimer(objScene, 60*55);
PlaySE(cardcall);
ObjCutin_SetSpellcardS4("Roukanken &quot;Light-Twisting Slash&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);
ObjShot_SetSpellResist(obj2, true);
ObjStLaser_SetSource(obj2, false);
ObjShot_Regist(obj2);
ObjMove_SetPosition(obj2, x-75*cos(ObjStLaser_GetAngle(obj2)), y-75*sin(ObjStLaser_GetAngle(obj2)));
wait2(delay-5);
//if(popped==true){break;}
if(type==1){ObjShot_FadeDelete(obj2); }
if(type==0){ if(popped==true){Obj_Delete(obj2); break;} wait(5); }

if(type==0){
PlaySE(ping);
}
ObjLaser_SetRenderWidth(obj2, width/2);
ObjLaser_SetIntersectionWidth(obj2, width/2-7);
wait2(delay*2);
ObjShot_FadeDelete(obj2);




function wait2(f){ loop(f){ if(popped==true){ ObjShot_FadeDelete(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(4){ 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(4){ 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 randtilt = 0;
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{

wait(120);
if(popped==true){break;}
StartSlow(TARGET_ALL, 30);
SetCommonData("petals", true);
PlaySE(timeslow);
//PlaySE(charge2);
ObjAnim_SetAttackA2(objEnemy, 60);
TCharge01(objEnemy, 3, 60, 65, 105, 225);
ascent(i in -4..5){
CreateLaser1(ObjMove_GetX(objEnemy)+(i*8), 0, 90, PURPLE60, 600, 35, 60, 0);
}

wait(60);
if(popped==true){break;}
PlaySE(slash);
StopSlow(TARGET_ALL);

ascent(i in 0..12){
if(popped==true){break;}
CreateLaser1(ObjMove_GetX(objEnemy)+(i*40)+50, 0, 90, WHITE12, 600, 30, 50, 1);
CreateLaser1(ObjMove_GetX(objEnemy)-(i*40)-50, 0, 90, WHITE12, 600, 30, 50, 1);
	ascent(p in -1..16){
	if(popped==true){break;}
		randtilt = rand(-4, 4);
			loop(2){
			if(GetDistance(GetPlayerX, GetPlayerY, ObjMove_GetX(objEnemy)+(i*40)+50, 0+(p*43.5)+7*sin(i*(360/6)))>=40){
		CreateDNHShotA2(ObjMove_GetX(objEnemy)+(i*40)+50, 0+(p*43.5)+7*sin(i*(360/6)), 0, 0+randtilt+angle2, 0.004+rand(-0.0001, 0.0001), 1.5, YELLOW21, 35);
		}
		angle2+=360/2;
			}
			randtilt = rand(-4, 4);
			loop(2){
			if(GetDistance(GetPlayerX, GetPlayerY, ObjMove_GetX(objEnemy)-(i*40)-50, 0+(p*43.5)+7*sin(i*(360/6)))>=40){
		CreateDNHShotA2(ObjMove_GetX(objEnemy)-(i*40)-50, 0+(p*43.5)+7*sin(i*(360/6)), 0, 0+randtilt+angle2, 0.004+rand(-0.0001, 0.0001), 1.5, YELLOW21, 35);
		}
		angle2+=360/2;
			}
					
		}

}

SetCommonData("petals", false);
wait(30);
			if(popped==true){break;}
			wait(180);
			if(popped==true){break;}
ChangeToHorizontal;
ObjMove_SetDestAtFrame(objEnemy, 20, ObjMove_GetY(GetPlayerObjectID), 90);
wait(120);
if(popped==true){break;}
StartSlow(TARGET_ALL, 30);
SetCommonData("petals", true);
PlaySE(timeslow);
ObjAnim_SetAttackA2(objEnemy, 60);
TCharge01(objEnemy, 3, 60, 65, 105, 225);
ascent(i in -4..5){
CreateLaser1(0, ObjMove_GetY(objEnemy)+(i*8), 0, PURPLE60, 600, 35, 60, 0);
}

wait(60);
if(popped==true){break;}
PlaySE(slash);
StopSlow(TARGET_ALL);

ascent(i in 0..12){
if(popped==true){break;}
CreateLaser1(0, ObjMove_GetY(objEnemy)+(i*40)+50, 0, WHITE12, 600, 30, 50, 1);
CreateLaser1(0, ObjMove_GetY(objEnemy)-(i*40)-50, 0, WHITE12, 600, 30, 50, 1);
	ascent(p in -1..16){
	if(popped==true){break;}
		randtilt = rand(-4, 4);
			loop(2){
			if(GetDistance(GetPlayerX, GetPlayerY, 0+(p*43.5)+7*sin(i*(360/6)), ObjMove_GetY(objEnemy)+(i*40)+50)>=40){
			CreateDNHShotA2(0+(p*43.5)+7*sin(i*(360/6)), ObjMove_GetY(objEnemy)+(i*40)+50, 0, 90+randtilt+angle2, 0.004+rand(-0.0001, 0.0001), 1.5, ORANGE21, 35);
		}
		angle2+=360/2;
			}
			randtilt = rand(-4, 4);
			loop(2){
			if(GetDistance(GetPlayerX, GetPlayerY, 0+(p*43.5)+7*sin(i*(360/6)), ObjMove_GetY(objEnemy)-(i*40)-50)>=40){
		CreateDNHShotA2(0+(p*43.5)+7*sin(i*(360/6)), ObjMove_GetY(objEnemy)-(i*40)-50, 0, 90+randtilt+angle2, 0.004+rand(-0.0001, 0.0001), 1.5, ORANGE21, 35);
		}
		angle2+=360/2;
			}
					
		}
		
}

SetCommonData("petals", false);
wait(30);
			if(popped==true){break;}
			wait(180);
			if(popped==true){break;}
ChangeToVertical;
ObjMove_SetDestAtFrame(objEnemy, ObjMove_GetX(GetPlayerObjectID), 90, 90);
}
}



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