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

script_enemy_main {
	let variable = 0;
	let xpos = 0;
	let undulate = 0;
	let color = 0;
	let one = 1;
	#include_function ".\Yukainclude.txt";
	let i = 0;
	let onee = 1;
	let anim3 = 0;
	let plax = 0;
	let firsttime=true;
	let blah = 0;
	@Initialize{
	shotinit;
	LoadSE(capture);
	LoadSE(time1);
	LoadGraphic(imageFile);
	LoadSE(time2);
	LoadSE(charge);
	LoadSE(familiarspawn);
	InitializeAction;
	SetLife(1500);
	LoadSE(ping);
	LoadSE(shot);
	LoadSE(spark);
	DelayedStart;
	LoadSE(die);
	LoadGraphic(familiar);
	LoadSE(shot2);
	LoadSE(die);
	SetTimer(99);
	SetEnemyMarker(true);
	SetInvincibility(300);
	SetDamageRate(47.5, 25);
	SetMovePosition02(GetCenterX-60, GetClipMinY + 120, 60);
	SetAction(ACT_MOVE, 60);
	SetShotAutoDeleteClip(40, 50, 40, 50);
	LoadGraphic(SP);
	LoadGraphic(MC);
	LoadGraphic(CBG1);
	LoadGraphic(CBG2);
	LoadSE(shot4);
	LoadSE(die);
	LoadGraphic(Cut);
	SetAction(ACT_MOVE, 60);
	MagicCircle(false);
	}

task DelayedStart {

	CreateEnemyFromScript("clone", GetX, GetY, 0, 0, 0);
wait(60);
SetScore(275000);
PlaySE(GetCurrentScriptDirectory~"cardcall.wav");
cutin("Linnaea Borealis "\""Double Spark"\", Cut, 0, 0, 256, 512);
SetAction(ACT_SPELL, 90);
attack1;
//attack2;
SpellBG;
SetTimer(70);
}

	let backRED = 255;
	let backGREEN = 255;
	let backBLUE = 255;


task CreateTargetCircle2(x, y, duration, arg){
		let obj = Obj_Create(OBJ_EFFECT);
		let anglee = 0;
  		ObjEffect_SetTexture(obj, familiar);
  		ObjEffect_SetLayer(obj, 5);
		Obj_SetAlpha(obj, 15);
  		ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
  		ObjEffect_CreateVertex(obj, 4);
		ObjEffect_InitializeRect(familiar, 5);
		ObjEffect_SetXYRect(obj, -64, -64, 64, 64); 
		ObjEffect_SetUVRect(obj, 64, 0, 128, 64);
		ObjEffect_SetRenderState(obj, ALPHA);
		Obj_SetPosition(obj, x, y);
		
		while(!Obj_BeDeleted(obj)) {
			if(arg==1){
		Obj_SetPosition(obj, GetPlayerX, GetPlayerY);
			}
		ObjEffect_SetAngle(obj,0,0,anglee*2);
		ObjEffect_SetScale(obj,2-(anglee/45),2-(anglee/45));
		anglee+=1;
		if(anglee>=duration) { Obj_Delete(obj); }
		yield;
		}

}


task CreateShotAngular(x, y, v, angle, graphic, delay, angvel) {
		let obj = Obj_Create(OBJ_SHOT);
		let angle2 = 0;
		let time = 0;
		let radius = 0;
		Obj_SetPosition(obj, x, y);
		Obj_SetAngle(obj, angle);
		Obj_SetSpeed(obj, 0);
		Obj_SetCollisionToObject(obj, true);
		ObjShot_SetDelay(obj, delay);
		ObjShot_SetGraphic(obj, graphic);
		while(!Obj_BeDeleted(obj)){
		Obj_SetPosition(obj, x+radius*cos(angle+angle2), y+radius*sin(angle+angle2));
		radius+=v;
		angle2+=angvel;
		yield;
		}	
}		
	


task CreateLaser(angle, graphic, delay){
let obj = Obj_Create(OBJ_LASER);
		let width = 150;
		let count = 0;
		let length = 0;
		Obj_SetPosition(obj,GetX-40*cos(angle),GetY-40*sin(angle));
		ObjLaser_SetLength(obj,150);
		ObjLaser_SetWidth(obj,width);
		Obj_SetAngle(obj,angle);
		ObjShot_SetGraphic(obj,graphic);
		ObjShot_SetDelay(obj,delay);
		ObjLaser_SetSource(obj, false);
		while(!Obj_BeDeleted(obj)) {
		if(length<550){ length+=20; }
		ObjLaser_SetLength(obj,length);
		if(count==delay){
		PlaySE(ping);
		//PlaySE(spark);
		}
		if(count>=240){
		width-=150/40;
		}
		if(width<=7.5){
		Obj_SetCollisionToPlayer(obj, false);
		}
		
		if(count>=280){
		Obj_Delete(obj);
		}
		ObjLaser_SetWidth(obj,width);
		
		count++;
		
		yield;
		}
	}


task attack1{
wait(120);
loop{
	if(firsttime!=true){
PlaySE(teleport);
SetAction(ACT_TURN, 180);
loop(60){
alpha-=4;
wait(1);
}
alpha = 0;
SetX(GetClipMinX+120);
SetY(GetClipMinY+120);
PlaySE(teleport);
SetAction(ACT_TURN, 180);
loop(85){
alpha+=3;
wait(1);
}
}
firsttime=false;
PlaySE(charge);
Concentration01(60);
SetAction(ACT_SHOT_B, 300);
wait(10);
CreateLaser(90, BLUE51, 90);
wait(60);
loop(10){
PlaySE(shot);
	loop(6){
		ascent(i in 0..7){
			PC98(GetX, GetY, 1-0.45454545454+(i/2.2), angle+((i*3)*one), BLUE12, 10+(i*2), 3.5);
			}
		angle+=360/6;
		}
one=one*-1;
angle+=360/6/5;
wait(23);
}
PlaySE(teleport);
SetAction(ACT_TURN, 180);
loop(60){
alpha-=4;
wait(1);
}
alpha = 0;
SetX(GetClipMinX+80);
SetY(GetClipMinY+120);
PlaySE(teleport);
SetAction(ACT_TURN, 180);
loop(85){
alpha+=3;
wait(1);
}
PlaySE(charge);
Concentration01(60);
SetAction(ACT_SHOT_B, 300);
wait(10);
CreateTargetCircle2(GetPlayerX, GetPlayerY, 90, 0);
CreateLaser(GetAngleToPlayer, BLUE51, 90);
wait(30);
angle = 0;
loop(6){
	ascent(i in 0..10){
			loop(8){
			PC98(GetX, GetY, 0.5+(i/2), GetAngleToPlayer+angle, BLUE11, 10, 3);
			angle+=360/8;
			}
		wait(1);
		}

wait(30);
}
wait(20);
}
}


	task SpellBG {
		let w = 60;
		wait(w);
		loop(w){
			backGREEN-=255/w;
			backBLUE-=255/w;
			wait(1);
		}
		loop{
			loop(w){
				backGREEN+=128/w;
				wait(1);
			}
			loop(w){
				backGREEN+=127/w;
				wait(1);
			}
			loop(w){
				backRED-=255/w;
				wait(1);
			}
			loop(w){
				backBLUE+=255/w;
				wait(1);
			}
			loop(w){
				backGREEN-=255/w;
				wait(1);
			}
			loop(w){
				backRED+=255/w;
				wait(1);
			}
			loop(w){
				backBLUE-=255/w;
				wait(1);
			}
		}
	}




@BackGround{
SetTexture(CBG1);
SetRenderState(ALPHA);
SetGraphicAngle(0, 0, 0);
SetGraphicScale(1, 1);
SetColor(backRED/3, backGREEN/3, backBLUE/3);
SetGraphicRect(19, 0+(anim2*5), 474, 455+(anim2*5));
SetAlpha(255);
DrawGraphic(GetCenterX, GetCenterY);
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(60);
DrawGraphic(GetCenterX, GetCenterY);
SetColor(255, 255, 255);
i+=1; i%=360;
anim2 += 0.75;
acc1 = 6;


}




	
}



script_enemy clone {
let imageFile = GetCurrentScriptDirectory~"sprites\yuka.png";
let f = true;
let variation = 1;
let last = false;
let scale = 1;
let variable = 1;
let familiar = GetCurrentScriptDirectory~"sprites\familiar.png";
let hurtbox = true;
let futo = GetCurrentScriptDirectory~"sprites\futo.png";
let warp = GetCurrentScriptDirectory~"sfx\warp.wav";
let frame = -60;
let one =-1;
let shooting = false;
let frame2 = -60;
let capture = GetCurrentScriptDirectory~"sfx\capture.wav";
let die = GetCurrentScriptDirectory~"sfx\se_enep01.wav";
let frame3 = -60;
let border = GetCurrentScriptDirectory~"sfx\border.wav";
let orb = GetCurrentScriptDirectory~"sfx\orb.wav";
let shot3 = GetCurrentScriptDirectory~"sfx\shot3.wav";
let shot4 = GetCurrentScriptDirectory~"sfx\shot4.wav";
let shot2 = GetCurrentScriptDirectory~"sfx\shot2.wav";
let shot = GetCurrentScriptDirectory~"sfx\shot.wav";
let charge = GetCurrentScriptDirectory~"sfx\Charge.wav";
let wtf = GetCurrentScriptDirectory~"sfx\kira00.wav";
let b = 0;
let timer = GetTimer;
let alpha = 255;
let time1 = GetCurrentScriptDirectory~"sfx\time1.wav";
let time2 = GetCurrentScriptDirectory~"sfx\time2.wav";
let teleport = GetCurrentScriptDirectory~"sfx\teleport.wav";
let caution = GetCurrentScriptDirectory~"sfx\caution.wav";
let acc1 = 0;
let ping = GetCurrentScriptDirectory~"sfx\ping.wav";
let laser2 = GetCurrentScriptDirectory~"sfx\laser2.wav";
let acc2 = 0;
let acc3 = 0;
let acc5 = 0;
let radiusx = 0;
let radiusy = 0;
let angle2 = 0;
let angle3 = 0;
let ang = 0;
let anim1 = 0;
let c = 0;
let angle = 0;
let anim2 = 0;
let firsttime = true;
let clone = true;
let anim3 = 0;
let radius = 0;
let angle = 0;
let CBG1 = GetCurrentScriptDirectory~"sprites\CBG1.png";
let CBG2 = GetCurrentScriptDirectory~"sprites\CBG2.png";
let ang = 0;
let shot3 = GetCurrentScriptDirectory~"sfx\shot3.wav";
let objbullets = [];
let objgrowers = [];
let variation = 0;
let imglifebar = GetCurrentScriptDirectory~"lifebar_thWW.png";
let familiarspawn = GetCurrentScriptDirectory~"sfx\Shadow.wav";
let bgm = GetCurrentScriptDirectory~"mu\bgm.mp3";
let SP = GetCurrentScriptDirectory~"sprites\futo.png";
let laser = GetCurrentScriptDirectory~"sfx\laser.wav";
let MC = GetCurrentScriptDirectory~"sprites\NMC.png";
	#include_function ".\lib\SHOT_REPLACE\shot_replace.dnh"
	#include_function ".\cutin.dnh"
	#include_function ".\DATA\lib_anime_Yuka.dnh"



function wait(w){ loop(w){ yield;} }

task PC98(x, y, v, ang, graphic, delay, space){
	CreateShot01(x+cos(ang+90)*space, y+sin(ang+90)*3.5, v, ang, graphic, delay);
	CreateShot01(x-cos(ang+90)*space, y-sin(ang+90)*3.5, v, ang, graphic, delay);
	}


sub ExMove { ExMove_(GetClipMinY+120, 10, rand(15, 30)); }
function ExMove_(height, ud, length) {
	SetAction(ACT_MOVE, 180);
	if(GetPlayerX < GetX) {
		if(GetX - length <= GetClipMinX) {
			SetMovePosition03(GetX + length+20, rand(height+4 - ud, height + ud), 20, 2);
		} else {
			SetMovePosition03(GetX - length-20, rand(height - ud, height + ud), 20, 2);
		}
	} else {
		if(GetX + length >= GetClipMaxX) {
			SetMovePosition03(GetX - length-20, rand(height - ud, height + ud), 20, 2);
		} else {
			SetMovePosition03(GetX + length+20, rand(height - ud, height + ud), 20, 2);
		}
	}
}

sub ExMoveLower { ExMoveL_(GetClipMinY+150, 10, rand(15, 30)); }
function ExMoveL_(height, ud, length) {
	SetAction(ACT_MOVE, 180);
	if(GetPlayerX < GetX) {
		if(GetX - length <= GetClipMinX) {
			SetMovePosition03(GetX + length+20, rand(height+4 - ud, height + ud), 20, 2);
		} else {
			SetMovePosition03(GetX - length-20, rand(height - ud, height + ud), 20, 2);
		}
	} else {
		if(GetX + length >= GetClipMaxX) {
			SetMovePosition03(GetX - length-20, rand(height - ud, height + ud), 20, 2);
		} else {
			SetMovePosition03(GetX + length+20, rand(height - ud, height + ud), 20, 2);
		}
	}
}

sub ExMove2 { ExMove_2(GetClipMinY+120, 0, rand(80, 115)); }
function ExMove_2(height, ud, length) {
	SetAction(ACT_MOVE, 180);
	if(GetPlayerX < GetX) {
		if(GetX - length <= GetClipMinX) {
			SetMovePosition03(GetX + length, rand(height+4 - ud, height + ud), 6, 0.85);
		} else {
			SetMovePosition03(GetX - length, rand(height - ud, height + ud), 6, 0.85);
		}
	} else {
		if(GetX + length >= GetClipMaxX) {
			SetMovePosition03(GetX - length, rand(height - ud, height + ud), 6, 0.85);
		} else {
			SetMovePosition03(GetX + length, rand(height - ud, height + ud), 6, 0.85);
		}
	}
}


function GetDistance(x1,y1,x2,y2){
return(((x2-x1)^2+(y2-y1)^2)^(1/2))
} 

	@Initialize{
	SetX(GetCommonDataDefault("clonex", GetEnemyX));
	SetY(GetCommonDataDefault("cloney", GetEnemyY));
	shotinit;
	LoadSE(time1);
	LoadGraphic(imageFile);
	LoadSE(time2);
	LoadSE(charge);
	LoadSE(familiarspawn);
	InitializeAction;
	SetLife(15000000);
	LoadSE(ping);
	LoadSE(shot);
	LoadSE(laser2);
	LoadSE(shot2);
	LoadSE(die);
	SetTimer(99);
	SetEnemyMarker(false);
	SetInvincibility(240);
	SetDamageRateEx(47.5, 25, 100, 50);
	SetAction(ACT_MOVE, 120);
	SetShotAutoDeleteClip(30, 30, 30, 30);
	LoadGraphic(SP);
	LoadGraphic(MC);
	LoadGraphic(CBG1);
	LoadGraphic(CBG2);
	LoadSE(shot4);
	LoadSE(die);
	//LoadGraphic(Cut);
	SetAction(ACT_MOVE, 60);
	attack1;
	
	}


task CreateLaser(angle, graphic, delay){
let obj = Obj_Create(OBJ_LASER);
		let width = 150;
		let count = 0;
		let length = 0;
		Obj_SetPosition(obj,GetX-40*cos(angle),GetY-40*sin(angle));
		ObjLaser_SetLength(obj,150);
		ObjLaser_SetWidth(obj,width);
		Obj_SetAngle(obj,angle);
		ObjShot_SetGraphic(obj,graphic);
		ObjShot_SetDelay(obj,delay);
		ObjLaser_SetSource(obj, false);
		while(!Obj_BeDeleted(obj)) {
		if(length<550){ length+=20; }
		ObjLaser_SetLength(obj,length);
		if(count==delay){
		PlaySE(ping);
		}
		if(count>=240){
		width-=150/40;
		}
		if(width<=7.5){
		Obj_SetCollisionToPlayer(obj, false);
		}
		
		if(count>=280){
		Obj_Delete(obj);
		}
		ObjLaser_SetWidth(obj,width);
		
		count++;
		
		yield;
		}
	}



@MainLoop{
	if(alpha<0){ alpha = 0; }
	if(GetTimer!=timer && (GetTimer < 10 && GetTimer>3)){
		if(clone!=true){
		PlaySE(time1);
			}
			}

	if(GetTimer!=timer && GetTimer < 4){
		if(clone!=true){
		PlaySE(time2);
			}

	
			}
	timer = GetTimer;
	
	
	if(alpha<50){
	SetEnemyMarker(false);
	}
	
	if(hurtbox==true){
	if(alpha==255){ 
			SetCollisionB(GetX, GetY, 14.5); }
	
	if(alpha>50){ SetEnemyMarker(true); SetCollisionA(GetX, GetY, 32); }
	}
	yield;


	
	}


task attack1 {

SetMovePosition02(GetCenterX+60, GetClipMinY+120, 60);
wait(60);
SetAction(ACT_SPELL, 90);
wait(120);
loop{
if(firsttime!=true){
SetAction(ACT_TURN, 180);
loop(60){
alpha-=4;
wait(1);
}
alpha = 0;
SetX(GetClipMaxX-120);
SetY(GetClipMinY+120);
PlaySE(teleport);
SetAction(ACT_TURN, 180);
loop(85){
alpha+=3;
wait(1);
}
}
firsttime=false;
PlaySE(charge);
Concentration01(60);
SetAction(ACT_SHOT_B, 300);
wait(10);
CreateLaser(90, BLUE51, 90);
wait(60);
loop(10){
PlaySE(shot);
	loop(6){
		ascent(i in 0..7){
			PC98(GetX, GetY, 1-0.45454545454+(i/2.2), angle+((i*3)*one), BLUE12, 10+(i*2), 3.5);
			}
		angle+=360/6;
		}
one=one*-1;
angle-=360/6/5;
wait(23);
}
SetAction(ACT_TURN, 180);
loop(60){
alpha-=4;
wait(1);
}
alpha = 0;
SetX(GetClipMaxX-80);
SetY(GetClipMinY+120);
PlaySE(teleport);
SetAction(ACT_TURN, 180);
loop(85){
alpha+=3;
wait(1);
}

PlaySE(charge);
Concentration01(60);
SetAction(ACT_SHOT_B, 300);
wait(10);
CreateLaser(atan2(GetPlayerY-GetY, GetPlayerX-GetX), BLUE51, 90);
wait(30);
loop(6){
angle = 0;
	ascent(i in 0..10){
			loop(8){
			PC98(GetX, GetY, 0.5+(i/2), atan2(GetPlayerY-GetY, GetPlayerX-GetX)+angle, BLUE11, 10, 3);
			angle+=360/8;
			}
		wait(1);
		}

wait(30);
}
wait(20);
}
}




 @DrawLoop {
SetAlpha(alpha);
SetGraphicScale(scale, scale);
DrawBoss(imageFile);
}


@Finalize {
SetShotColor(255, 255, 255);
//PlaySE(die);

}
}