#TouhouDanmakufu
#Title[Plain Fairy]
#Text[Its plainer]
#Player[FREE]
#ScriptVersion[2]
#BGM[.\mu\bgm.mp3]


script_enemy_main {

	#include_function ".\lib\SHOT_REPLACE\shot_replace.dnh"
	#include_function ".\DATA\lib_anime_fairy.txt"
let randnum = rand(0, 359);
let pointnumber = 3;
let fairy = GetCurrentScriptDirectory~"sprites\Sprite.png";
let border = GetCurrentScriptDirectory~"sfx\border.wav";
let orb = GetCurrentScriptDirectory~"sfx\orb.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 time1 = GetCurrentScriptDirectory~"sfx\time1.wav";
let time2 = GetCurrentScriptDirectory~"sfx\time2.wav";
let warp = GetCurrentScriptDirectory~"sfx\warp.wav";
let caution = GetCurrentScriptDirectory~"sfx\caution.wav";
let shot3 = GetCurrentScriptDirectory~"sfx\shot3.wav";
let familiarspawn = GetCurrentScriptDirectory~"sfx\Shadow.wav";
let laser = GetCurrentScriptDirectory~"sfx\laser.wav";
let boom = GetCurrentScriptDirectory~"sfx\boom.wav";
let bloop = 0;
let angle = 0;
let angle2 = 0;
let angle3 = 0;
let angle4 = 0;
let angle5 = 0;
let angle6 = 0;
let radius = 0;
let count = 0;
let speed = 0;




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


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


function WithinPlayingField {
if(GetX>GetClipMinX-10 && GetX<GetClipMaxX+10 && GetY>GetClipMinY-50 && GetY<GetClipMaxY+30){ return true; }
else { return false;  }
}




	@Initialize{
	
	LoadSE(shot3);
	LoadSE(shot4);
	LoadSE(boom);
	SetInvincibility(30);
	LoadGraphic(fairy);
	shotinit;
	Initialize_Fairy(4);
	if(GetArgument==-1||GetArgument==1){
	attack1;
	}
	
	if(GetArgument==2){
	attack2;
	}
	if(GetArgument==3){
	attack3;
	}
	SetLife(60);
	}

	
task attack1{
SetSpeed(2);
SetAngle(90+(45*GetArgument));
loop{
PlaySE(shot3);
loop(2){
CreateShot12(GetX, GetY, rand(-0.5, 0.5), rand(-2, -4), 0, 0.03, 100, 3, RED04, 10);
}
wait(10);
count+=0.3;
}
}

task attack2{
SetDamageRate(1, 1);
 SetAngle(-90);
 SetSpeed(1);
wait(rand_int(0, 10));
 loop{
PlaySE(shot4);
loop(2){
	CreateShotA(1, GetX, GetY, 20);
	SetShotDataA(1, 0, 0.65+0.3*sin(bloop), angle, 0, 0, 1, BLUE01);
	SetShotDataA(1, 120, NULL, angle, 0, -0.05, 0, BLUE01);
	FireShot(1);
	angle+=360/2;
	}
wait(10);
bloop+=7;
}
}

task attack3{
SetDamageRate(4, 3);
SetMovePosition03(GetX, GetY+75, 10, 3);
wait(60);
PlaySE(charge);
Concentration01(60);
wait(60);
loop(75){
	PlaySE(shot3);
	loop(3){
		ascent(i in 0..7){
		CreateShot01(GetX, GetY, 0.5+(i/3), angle+(i*1.5), BLUE12, 10);
		}
		ascent(i in 0..6){
		CreateShot01(GetX, GetY, 0.85+(i/2), angle2-(i*3), RED12, 10);
		}
		angle2+=360/3;
		angle+=360/3;
		}
	angle+=12;
	angle2-=13;
	wait(10);
	}
wait(30);
SetMovePosition02(GetClipMaxX+100, GetY, 90);
}
		


	@MainLoop{
	
	SetCollisionA(GetX, GetY, 10);
	SetCollisionB(GetX, GetY, 4);
	yield;

	if(WithinPlayingField==false){ VanishEnemy; }
	}


 @DrawLoop {

DrawFairy(fairy);

}





@Finalize{
if(GetArgument==3){ CreateItem(ITEM_BOMB, GetX, GetY); }
if(!BeVanished){ PlaySE(boom); loop(pointnumber){ CreateItem(ITEM_SCORE, GetX+rand(-35, 35), GetY+rand(-5, 5)); }} }
}

}