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

script_enemy_main {

	#include_function ".\Yuyukoinclude.txt";
	let i = 0;
	let dx = 0;
	let onee = 1;
	let anim3 = 0;
	let color = 0;
	let x = 0;
let y = 0;
let c = 0;
let argument=0;
let one = 1;
let life1 = false;
let life2 = false;
let wide = 1;
let angle2 = 0;
let attack3 = false;
	@Initialize{
	shotinit;
	LoadSE(time1);
	LoadGraphic(imageFile);
	LoadGraphic(imageFile2);
	LoadSE(time2);
	LoadSE(charge);
	LoadSE(familiarspawn);
	InitializeAction;
	SetLife(1500);
	LoadSE(ping);
	LoadSE(shot);
	DelayedStart;
	LoadSE(shot2);
	LoadSE(die);
	LoadSE(wisps);
	LoadSE(wispspawner);
	SetTimer(99);
	SetEnemyMarker(true);
	SetInvincibility(600);
	SetDamageRate(20, 25);
	SetMovePosition02(GetCenterX, GetClipMinY + 120, 30);
	SetAction(ACT_MOVE, 60);
	SetShotAutoDeleteClip(30, 30, 30, 40);
	LoadGraphic(SP);
	LoadGraphic(MC);
	LoadGraphic(CBG1);
	LoadGraphic(CBG2);
	LoadSE(shot4);
	LoadSE(ping);
	LoadSE(dream);
	LoadSE(die);
	LoadSE(ylaser);
	LoadSE(glaser);
	LoadGraphic(Cut);
	SetAction(ACT_MOVE, 60);
	SetCommonData("lastattack", true);
	LifeCheck;
	SetEffectForZeroLife(60, 100, 2);
	}

task LifeCheck {
loop{
if(GetEnemyLife<=1000 && life1 == false){
DeleteEnemyShotToItem(ALL);
life1 = true;
SetCommonData("rings", false);
SetDamageRate(10, 25);
}

if(GetEnemyLife<=500 && life2 == false){
DeleteEnemyShotToItem(ALL);
SetCommonData("reduce", 1);
SetDamageRate(8, 25);
life2 = true;
attack3 = true;
c = 2;
}
wait(1);
}
}


task DelayedStart {
let i = 0;
let radius = 30;
angle = 180;
wait(60);
Concentration01(120);
PlaySE(charge);
wait(90);

loop(20){
ascent(i in 0..6){
CreateShotA(1, GetX, GetY, 10);
SetShotDataA(1, 0, 1, angle, 0, 0, 1, RED03);
SetShotDataA(1, 60, 2+(i/2), angle, 0, 0, 1, RED03);
FireShot(1);
}
angle+=360/20;
}
wait(60);
SetScore(1500000);
PlaySE(GetCurrentScriptDirectory~"cardcall.wav");
cutin("Cherry Blossoms "\""Feast of Regrets"\", Cut, 0, 0, 256, 512);
SetAction(ACT_SPELL, 90);

attack1;
//Shiny;
SetTimer(120);
wait(90);
fan;
}



task attack1 {
loop(6){

CreateEnemyFromScript("Fan", GetX, GetY, 0, 0, argument);
argument++;
wait(30);
}
wait(420);
loop{
if(life1==false && life2 == false){
loop(20){
ascent(i in 0..6){
CreateShotA(1, GetX, GetY, 10);
SetShotDataA(1, 0, 1, angle, 0, 0, 1, RED03);
SetShotDataA(1, 60, 2+(i/2), angle, 0, 0, 1, RED03);
FireShot(1);
}
angle+=360/20;
}
wait(60);
PlaySE(ping);
wait(380);
}
if(life1 == true){
angle = -30;
loop(15){
PlaySE(shot);
	ascent(i in 0..8+c){
		CreateShot01(GetX, GetY, 2, angle+(i*12), AQUA51, 10);
		}
angle+=10.5;
wait(8);
}
wait(30);
angle = 210;
loop(15){
PlaySE(shot);
	ascent(i in 0..8+c){
		CreateShot01(GetX, GetY, 2, angle-(i*12), YELLOW51, 10);
		}
angle-=10.5;
wait(8);
}
if(attack3 == true){
angle = 0;
PlaySE(shot3);
loop(20){
ascent(i in 0..6){
CreateShotA(1, GetX, GetY, 10);
SetShotDataA(1, 0, 1, GetAngleToPlayer+angle, 0, 0, 1, PURPLE03);
SetShotDataA(1, 60, 1+(i/3), NULL, 0, 0, 1, PURPLE03);
FireShot(1);
}
angle+=360/20;
}
wait(60);
PlaySE(ping);
}
}
wait(30);

}

}


@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 Fan{
	let randx = 0;
	let randy = 0;
	let angle = 0;
	let angle2 = 0;
	let bloop = 120;
	#include_function ".\lib\SHOT_REPLACE\shot_replace.dnh";
	let pingle = GetCurrentScriptDirectory~"sfx\pingle.wav";
	let shot4 = GetCurrentScriptDirectory~"sfx\shot4.wav";
	
	@Initialize {
	shotinit;
	SetLife(1500000000);
	SetInvincibility(120);
	SetDamageRateEx(35, 25, 70, 10);
	attack1;
	LoadSE(pingle);
	LoadSE(shot4);
	}



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

	task attack1{
	wait(120);
	loop{
	if(GetCommonDataDefault("rings", true)==true){
	PlaySE(pingle);
	angle = 0;
	loop(12){
	
	CreateShotDerp(GetX+randx, GetY+randy, 1.5, angle, RED12, 20);
	angle+=360/12;
	}
	}
	randx = rand(-20, 20);
	randy = rand(-10, 10);
	wait(300);
	if(GetEnemyLife<1000 && bloop == 120){
	attack2;
	bloop=0;
	}


	}
	}

	task attack2{
	loop{
		loop(2-GetCommonDataDefault("reduce", 0)){
			loop(2){
			CreateShot01(GetX+randx, GetY+randy, rand(0.75, 1.25), 90+angle2, PURPLE12, 10);
			angle2+=360/2;
			} 
			randx = rand(-100, 100);
			randy = rand(-20, 20);
			}
		wait(30);
		}
	}
	
	
	

	@MainLoop {
	yield;
	SetCollisionA(GetX, GetY, 50);
	if(GetArgument==0){ SetX(GetEnemyX+150); SetY(GetEnemyY); }
	if(GetArgument==1){ SetX(GetEnemyX-150); SetY(GetEnemyY); }
	if(GetArgument==2){ SetX(GetEnemyX-100); SetY(GetEnemyY-50); }
	if(GetArgument==3){ SetX(GetEnemyX+100); SetY(GetEnemyY-50); }
	if(GetArgument==4){ SetX(GetEnemyX-50); SetY(GetEnemyY-20); }
	if(GetArgument==5){ SetX(GetEnemyX+50); SetY(GetEnemyY-20); }
	}

	
 task CreateShotDerp(x, y, v, ang, graphic, delay) {
		let obj_id = Obj_Create(OBJ_SHOT); 
 		let  counter = 0;
		let pangle = 0;
		let change = false;
		let diff = 0;
		Obj_SetPosition(obj_id, x, y);
		ObjShot_SetGraphic(obj_id, graphic);
		Obj_SetSpeed(obj_id, v); 
		Obj_SetAngle(obj_id, ang); 
		ObjShot_SetDelay(obj_id, delay);
		while(!Obj_BeDeleted(obj_id)) {
		if(change==false){
		Obj_SetSpeed(obj_id, v);
		}
		
		if(v<=0){
		pangle = atan2(GetPlayerY-Obj_GetY(obj_id), GetPlayerX-Obj_GetX(obj_id));
		diff = Obj_GetAngle(obj_id)-pangle;
		loop(36){
		Obj_SetAngle(obj_id, Obj_GetAngle(obj_id)-(diff/36));
		wait(1);
		}
		wait(10);
		Obj_SetSpeed(obj_id, 1);
		change=true;
		v=100000;
		}
			
		if(v>0){
		v-=0.02;
		}	

		

			yield;
			}
	}

	@DrawLoop{
	
	}
	@Finalize{
	}


}



