#TouhouDanmakufu
#Title[YuyukoS3_H]
#Text[YuyukoS3_H]
#Player[FREE]
#ScriptVersion[2]
#BGM[.\mu\bgm.mp3]

script_enemy_main{
	
	let moo = 0;
	
	#include_function ".\Youmuinclude.txt"


	@Initialize {
	shotinit;
	LoadSE(time1);
	LoadGraphic(imageFile);
	
	LoadSE(time2);
	LoadSE(charge);
	LoadSE(familiarspawn);
	InitializeAction;
	SetLife(1500);
	LoadSE(ping);
	LoadSE(shot);
	DelayedStart;
	LoadSE(shot2);
	LoadSE(die);
	SetX(GetCommonDataDefault("YoumuX", GetX));
	SetY(GetCommonDataDefault("YoumuY", GetY));
	//CreateEnemyFromScript("Youmu", GetCommonDataDefault("YoumuX", GetX), GetCommonDataDefault("YoumuY", GetY), 0, 0, 0);
	SetTimer(99);
	SetEnemyMarker(true);
	SetInvincibility(36000);
	SetDamageRate(30, 25);
	SetMovePosition02(GetCenterX, GetClipMinY + 120, 60);
	SetAction(ACT_MOVE, 60);
	SetShotAutoDeleteClip(70, 70, 70, 70);
	LoadGraphic(SP);
	LoadGraphic(MC);
	LoadGraphic(CBG1);
	LoadGraphic(CBG2);
	LoadSE(shot4);
	LoadSE(ping);
	LoadSE(die);
	MagicCircle(false);
	LoadGraphic(CutY);
	SetAction(ACT_MOVE, 60);
	SetCommonData("lastattack", true);
	SetDurableSpellCard;
	SetEffectForZeroLife(60, 100, 2);
	SetCommonData("survival", true);
	
	}

	task DelayedStart {
	wait(90);
	SetAction(ACT_SPELL, 90);
	SetScore(4000000);
	PlaySE(GetCurrentScriptDirectory~"cardcall.wav");
	cutin("Half Ghost "\""Double Pain"\", CutY, 0, 0, 256, 512);
	SetTimer(63);
	wait(150);
	Concentration01(120);
	PlaySE(charge);
	SetAction(ACT_CHARGE, 120);
	wait(120);
	PlaySE(ping);
	CreateEnemyFromScript("Youmu2", GetCommonDataDefault("YoumuX", GetX), GetCommonDataDefault("YoumuY", GetY), 0, 0, 0);
	CreateEnemyFromScript("MasterYoumu", GetCommonDataDefault("YoumuX", GetX), GetCommonDataDefault("YoumuY", GetY), 0, 0, 0);
	SetMovePosition02(GetCenterX-30, GetY, 30);
	SetAction(ACT_MOVE, 30);
	alpha = 150;
	wait(90);
	loop{
	PlaySE(shot);
	ascent(i in 0..4+moo){
	CreateShot01(GetX+10, GetY-10, 3-(i/4), atan2(GetPlayerY-(GetY-10), GetPlayerX-(GetX+10)), 137, 20);
	} 
	wait(10);
	PlaySE(shot);
	ascent(i in 0..4+moo){
	CreateShot01(GetX-10, GetY-10, 3-(i/4), atan2(GetPlayerY-(GetY-10), GetPlayerX-(GetX-10)), 142, 20);
	}
	wait(30);
	ExMove;
	wait(90-(moo*10));
	if(GetTimer<50){
	moo=1;
	}
	if(GetTimer<40){
	moo=2;
	if(GetTimer<20){
	moo=4;
	}
	}
	

}
}


@BackGround{
SetTexture(CBG2);
SetRenderState(ALPHA);
SetGraphicAngle(0, 0, 0);
SetColor(255, 255, 255);
SetGraphicScale(1, 1);
SetGraphicRect(0, 0-(anim2*4), 512, 512-(anim2*4));
SetAlpha(255);
DrawGraphic(GetCenterX, GetCenterY);
SetTexture(CBG1);
SetRenderState(ALPHA);
SetGraphicAngle(0, 0, 0);
SetGraphicScale(1, 1);
SetGraphicRect(0, 0, 512, 512);
SetAlpha(150);
DrawGraphic(GetCenterX, GetCenterY);

SetGraphicScale(1, 1);
anim2 += 1.5;
acc1 = 6;
}
}





script_enemy MasterYoumu{
	
	let moo = 0;
	let madeclones = false;
	#include_function ".\Youmuinclude.txt"


	@Initialize {
	InitializeAction;
	SetAction(ACT_MOVE, 120);
	SetMovePosition02(GetCenterX, GetClipMinY + 120, 60);
	LoadSE(shot);
	LoadSE(shot2);
	LoadSE(familiarspawn);
	LoadSE(slash);
	LoadSE(ping);
	LoadSE(shot3);
	LoadGraphic(imageFile);
	LoadGraphic(Cut);
	SetLife(150000);
	SetInvincibility(240000);
	SetDamageRateEx(100, 25, 90, 10);
	attack1;
	MagicCircle(true);
	alpha = 200;
	
	}

	task attack1 {
	SetMovePosition02(GetX, GetY+40, 30);
	SetAction(ACT_MOVE, 30);
	wait(30);
	loop{
	if(madeclones==false && GetTimer==42){
	madeclones=true;
	Concentration01(120);
	PlaySE(charge);
	wait(120);
	CreateEnemyFromScript("Youmu3", GetX, GetY, 0, 0, 0);
	PlaySE(ping);
	SetMovePosition02(GetCenterX, GetCenterY, 120);
	SetAction(ACT_MOVE, 120);
	alphareduct;
	break;
	}
yield;
}
task alphareduct{
loop{
if(alpha>0){ alpha--; }
wait(1);
}
}


}
}





script_enemy Youmu3{
	let ta = 0;
	let caution = GetCurrentScriptDirectory~"sfx\caution.wav";
	let moo = 0;
	let seplayed = false;
	let x = 0;
	let y = 0;
	#include_function ".\Youmuinclude.txt"
	let playx = 0;
	let playy = 0;
	let mooble = 0;
	@Initialize {
	InitializeAction;
	SetAction(ACT_MOVE, 120);
	SetMovePosition02(GetCenterX, GetClipMinY + 120, 60);
	LoadSE(shot);
	LoadSE(shot2);
	LoadSE(familiarspawn);
	LoadSE(slash);
	LoadSE(caution);
	LoadSE(ping);
	LoadSE(shot3);
	LoadGraphic(imageFile);
	LoadGraphic(Cut);
	SetLife(150000);
	SetInvincibility(240000);
	SetDamageRateEx(100, 25, 90, 10);
	attack1;
	MagicCircle(true);
	alpha=150;
	}

	task attack1 {
	SetMovePosition02(GetX+50, GetY, 60);
	SetAction(ACT_MOVE, 60);
	wait(180);
	loop{
	playx = GetPlayerX;
	playy = GetPlayerY;
	if(GetTimer<=1){
	break;
	}
	GetLineBorderPoint(GetX, GetY, playx, playy);
	SetAction(ACT_CHARGE, 90);
	if(GetTimer<=24){
	SetAction(ACT_CHARGE, 150);
	}
	PlaySE(charge);
	Concentration01(90);
	if(GetTimer>24){
	Slow(1);
	MotionBlur(ALL, 60, 120);
	}
	if(GetTimer<=24){
	MotionBlur(ALL, 120, 160);
	}
	wait(60);
	if(GetTimer<24){
	wait(60);
	}
	Slow(0);
	PlaySE(slash);
	CreateBurstingLaser(GetX+60*cos(ta-180), GetY+60*sin(-ta), ta, GetDistance(GetX, GetY, x, y)+60, ta+90);
	SetMovePosition02(x, y, 5);
	SetAction(ACT_SLASH_H, 60);
	
	wait(75);
	if(GetTimer>30){
	wait(30);
	}
	if(GetTimer>15){
	wait(60);
	}
	if(GetTimer>5){
	wait(15);
	}
	if(GetTimer<=1){
	break;
	}
	if(GetTimer<=24 && seplayed == false){
	PlaySE(caution);
	wait(60);
	PlaySE(caution);
	seplayed = true;
	}
	}
	} 



function GetLineBorderPoint(px, py, tx, ty){

	ta = atan2(ty-py, tx-px);

	if( ta>= atan2(GetClipMinY - py, GetClipMinX - px) && ta<=  atan2(GetClipMinY - py, GetClipMaxX - px)){
		x = px - (GetClipMinY-py)*tan(ta+90);
		y = GetClipMinY+20;
		return [px - (GetClipMinY-py)*tan(ta+90), GetClipMinY];
		
	}
	if( ta>= atan2(GetClipMinY - py, GetClipMaxX - px) && ta<=  atan2(GetClipMaxY - py, GetClipMaxX - px)){
		x = GetClipMaxX-20;
		y = py + (GetClipMaxX-px)*tan(ta);
		return [GetClipMaxX, py + (GetClipMaxX-px)*tan(ta)];
		
	}
	if( ta>= atan2(GetClipMaxY - py, GetClipMaxX - px) && ta<=  atan2(GetClipMaxY - py, GetClipMinX - px)){
		x = px - (GetClipMaxY-py)*tan(ta-90);
		y = GetClipMaxY-20;
		return [px - (GetClipMaxY-py)*tan(ta-90), GetClipMaxY];
	}
	if( ta> atan2(GetClipMaxY - py, GetClipMinX - px) || ta<  atan2(GetClipMinY - py, GetClipMinX - px)){
		x = GetClipMinX+20;
		y = py + (GetClipMinX-px)*tan(ta+180);
		return [GetClipMinX, py + (GetClipMinX-px)*tan(ta+180)];
	}
}

task CreateBurstingLaser(x, y, ang, length, bulletang){
let obj = Obj_Create(OBJ_LASER);
		let angle = ang;
		let count = 0;
		let width = 15;
		let radius = rand(-40, -10);
		Obj_SetPosition(obj,x, y);
		ObjLaser_SetLength(obj,length);
		ObjLaser_SetWidth(obj,180);
		Obj_SetAngle(obj,ang);
		ObjShot_SetGraphic(obj,PURPLE12);
		ObjShot_SetDelay(obj,0);
		Obj_SetAlpha(obj, 255);
		ObjLaser_SetSource(obj, false);
		
		while(!Obj_BeDeleted(obj)) {
		ObjLaser_SetWidth(obj,width);
		count++;
		
	
		if(count>300){
		width-=1;
		if(width<15){
		Obj_SetCollisionToPlayer(obj, false);
		}
		if(width<=0){
		Obj_Delete(obj);
		}
		}
		yield;
		}
	}




	
}
}



script_enemy Youmu2{
	
	let moo = 0;
	let time = 0;
	#include_function ".\Youmuinclude.txt"


	@Initialize {
	InitializeAction;
	SetAction(ACT_MOVE, 120);
	SetMovePosition02(GetCenterX, GetClipMinY + 120, 60);
	LoadSE(shot);
	LoadSE(shot2);
	LoadSE(familiarspawn);
	LoadSE(slash);
	LoadSE(shot3);
	LoadGraphic(imageFile);
	LoadGraphic(Cut);
	SetLife(150000);
	SetInvincibility(240);
	SetDamageRateEx(100, 25, 120, 10);
	attack1;
	alpha = 150;
	}

	task attack1 {
	SetMovePosition02(GetCenterX+30, GetY, 30);
	SetAction(ACT_MOVE, 30);
	wait(90);
	loop{
	if(GetTimer<=1){
	break;
	}
	SetMovePosition02(GetClipMaxX-30, GetClipMaxY-30, 90-(time/2));
	SetAction(ACT_MOVE, 90-(time/2));
	wait(120-(time/2));
	SetAction(ACT_CHARGE, 120-(time/2));
	//PlaySE(charge);
	Concentration01(120-(time/2));
	wait(120-(time/2));
	PlaySE(slash);
	CreateBurstingLaser(GetClipMaxX+10, GetClipMaxY-30, 180, GetDistance(GetClipMaxX+10, GetClipMaxY, GetClipMinX-10, GetClipMaxY), -90, moo);
	SetMovePosition02(GetClipMinX+30, GetY, 2);
	SetAction(ACT_SLASH_H, 122);
	if(GetTimer<=1){
	break;
	}
	wait(182-(time*1.05));
	SetMovePosition02(GetClipMinX+30, GetClipMinY+30, 90-(time/2));
	SetAction(ACT_MOVE, 90-(time/2));
	wait(120-(time/2));
	if(GetTimer<=1){
	break;
	}
	SetAction(ACT_CHARGE, 120-(time/2));
	//PlaySE(charge);
	Concentration01(120-(time/2));
	wait(120-(time/2));
	PlaySE(slash);
	CreateBurstingLaser(GetClipMinX-10, GetClipMinY+30, 0, GetDistance(GetClipMaxX+10, GetClipMaxY, GetClipMinX-10, GetClipMaxY), 90, moo);
	SetMovePosition02(GetClipMaxX-30, GetY, 2);
	SetAction(ACT_SLASH_H, 122);
	wait(182-(time*1.05));
	moo+=0.05;
	}
	
	

}





task CreateBurstingLaser(x, y, ang, length, bulletang, moo){
let obj = Obj_Create(OBJ_LASER);
		let angle = ang;
		let count = 0;
		let width = 15;
		let ti = 0;
		if(GetTimer<35){ ti = 1; }
		if(GetTimer<35){ ti = 2; }
		if(GetTimer<15){ ti = 3; }
		let radius = rand(-20, 20);
		Obj_SetPosition(obj,x, y);
		ObjLaser_SetLength(obj,length);
		ObjLaser_SetWidth(obj,180);
		Obj_SetAngle(obj,ang);
		ObjShot_SetGraphic(obj,BLUE12);
		ObjShot_SetDelay(obj,0);
		Obj_SetAlpha(obj, 255);
		ObjLaser_SetSource(obj, false);
		
		while(!Obj_BeDeleted(obj)) {
		ObjLaser_SetWidth(obj,width);
		count++;
		if(count==60){
		PlaySE(shot3);
		loop(20){
		ascent(i in 0..6+ti){
		CreateShot01(Obj_GetX(obj)+radius*cos(Obj_GetAngle(obj)), Obj_GetY(obj)+radius*sin(Obj_GetAngle(obj)), 0.5+(i/6), bulletang+(i*moo), GREEN21, 20);
		}
		radius+=ObjLaser_GetLength(obj)/9;
		}
		}
	
		if(count>150){
		if(width<14){
		Obj_SetCollisionToPlayer(obj, false);
		}
		width-=1;
		if(width<=0){
		Obj_Delete(obj);
		}
		}
		yield;
		}
	}




	
}




