#TouhouDanmakufu
#Title[Fat Fairy]
#Text[It's fat~]
#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 pointnumber = 0;
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 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+10){ return true; }
else { return false;  }
}

function ShootShape(spawnX, spawnY, v, angle, num, bside, graphic, delay) {
		ascent(i in 0..num) {
			let sx = spawnX+cos(angle+i*360/num); let sy = spawnY+sin(angle+i*360/num); let sxN = spawnX+cos(angle+(i+1)*360/num); let syN = spawnY+sin(angle+(i+1)*360/num);
			CreateShot01(spawnX, spawnY, v*(((sx-spawnX)^2+(sy-spawnY)^2)^0.5), atan2(sy-spawnY,sx-spawnX), graphic, delay);
			ascent(j in 0..bside) {
				let toAngle = atan2(syN-sy,sxN-sx); let toDist = (((sxN-sx)^2+(syN-sy)^2)^0.5); let sx2 = sx+toDist/bside*j*cos(toAngle); let sy2 = sy+toDist/bside*j*sin(toAngle);
				CreateShot01(spawnX, spawnY, v*(((sx2-spawnX)^2+(sy2-spawnY)^2)^0.5), atan2(sy2-spawnY,sx2-spawnX), graphic, delay);
			}
		}
	}


	@Initialize{
	//SetLife(100000);
	if(GetArgument==0){
	attack1;
	}
	if(GetArgument==1){
	attack1B;
	}
	if(GetArgument==2){
	attack1C;
	}
	if(GetArgument==3){
	attack2A;
	}
	if(GetArgument==4){
	attack2B;
	}
	if(GetArgument==5){
	attack2C;
	}

	pointnumber = 3;
	LoadSE(shot3);
	LoadSE(shot);
	LoadSE(boom);
	SetInvincibility(120);
	LoadGraphic(fairy);
	shotinit;
	Initialize_Fairy(6);
	SetMovePosition03(GetX, GetY+100, 7, 2);
	SetLife(100);
	}

task attack2A{
SetDamageRate(50, 5);
wait(90);
loop(10){
PlaySE(shot);
ShootShape(GetX, GetY, 2, angle+45, 4, 12, BLUE50, 10);
angle+=360/4/4;
wait(45);
}
wait(30);
SetSpeed(2);
}


task attack2B{
SetDamageRate(50, 5);
wait(90);
loop(10){
PlaySE(shot);
ShootShape(GetX, GetY, 2, angle, 4, 10, BLUE51, 10);
angle+=360/4/3;
wait(45);
}
wait(30);
SetSpeed(2);
}


task attack2C{
SetDamageRate(8, 5);
wait(90);
Concentration01(60);
wait(90);
loop(25){
PlaySE(shot);
ShootShape(GetX, GetY, 2.25, angle, 5, 12, RED52, 10);
angle+=360/4/5;
wait(20);
}
wait(30);
SetSpeed(2);
}
task attack1B{
SetLife(200);
wait(60);
PlaySE(shot3);
loop(4){
CreateShot01(GetX, GetY, 3, 90+angle, GREEN03, 10);
angle+=360/4;
}
ascent(i in 0..30){
loop(4){
CreateShot01(GetX, GetY, 2.9-(i/15)-rand(-0.1, 0.1), 90+angle+rand(-i, i), GREEN01, 10);
angle+=360/4;
}
}
wait(30);

PlaySE(shot3);
loop(4){
CreateShot01(GetX, GetY, 3, 45+angle, BLUE03, 10);
angle+=360/4;
}
ascent(i in 0..30){
loop(4){
CreateShot01(GetX, GetY, 2.9-(i/15)-rand(-0.1, 0.1), 45+angle+rand(-i, i), BLUE01, 10);
angle+=360/4;
}
}
wait(30);
if(GetX>GetCenterX){
SetAngle(180);
}

if(GetX<=GetCenterX){
SetAngle(0);
}
loop{
SetSpeed(speed);
speed+=0.02;
wait(1);
}
}


task attack1C{
SetInvincibility(240);
SetLife(2500);
pointnumber = 5;
wait(75);
PlaySE(shot3);
loop(4){
CreateShot01(GetX, GetY, 3, 90+angle, RED03, 10);
angle+=360/4;
}
ascent(i in 0..35){
loop(4){
CreateShot01(GetX, GetY, 2.9-(i/15)-rand(-0.1, 0.1), 90+angle+rand(-i, i), RED01, 10);
angle+=360/4;
}
}
wait(15);
angle+=360/4/3;
PlaySE(shot3);
loop(4){
CreateShot01(GetX, GetY, 3, 90+angle, BLUE03, 10);
angle+=360/4;
}
ascent(i in 0..35){
loop(4){
CreateShot01(GetX, GetY, 2.9-(i/15)-rand(-0.1, 0.1), 90+angle+rand(-i, i), BLUE01, 10);
angle+=360/4;
}
}
wait(15);
angle+=360/4/3;
PlaySE(shot3);
loop(4){
CreateShot01(GetX, GetY, 3, 90+angle, GREEN03, 10);
angle+=360/4;
}
ascent(i in 0..35){
loop(4){
CreateShot01(GetX, GetY, 2.9-(i/15)-rand(-0.1, 0.1), 90+angle+rand(-i, i), GREEN01, 10);
angle+=360/4;
}
}
wait(15);
angle+=360/4/3;
PlaySE(shot3);
loop(4){
CreateShot01(GetX, GetY, 3, 90+angle, YELLOW03, 10);
angle+=360/4;
}
ascent(i in 0..35){
loop(4){
CreateShot01(GetX, GetY, 2.9-(i/15)-rand(-0.1, 0.1), 90+angle+rand(-i, i), YELLOW01, 10);
angle+=360/4;
}
}wait(15);
angle+=360/4/3;
PlaySE(shot3);
loop(4){
CreateShot01(GetX, GetY, 3, 90+angle, PURPLE03, 10);
angle+=360/4;
}
ascent(i in 0..35){
loop(4){
CreateShot01(GetX, GetY, 2.9-(i/15)-rand(-0.1, 0.1), 90+angle+rand(-i, i), PURPLE01, 10);
angle+=360/4;
}
}
wait(15);
angle+=360/4/3;
PlaySE(shot3);
loop(4){
CreateShot01(GetX, GetY, 3, 90+angle, ORANGE03, 10);
angle+=360/4;
}
ascent(i in 0..35){
loop(4){
CreateShot01(GetX, GetY, 2.9-(i/15)-rand(-0.1, 0.1), 90+angle+rand(-i, i), ORANGE01, 10);
angle+=360/4;
}
}
wait(120);
angle+=360/4/3;
if(GetX>GetCenterX){
SetAngle(180);
}

if(GetX<=GetCenterX){
SetAngle(0);
}
loop{
SetSpeed(speed);
speed+=0.02;
wait(1);
}
}


task attack1{
wait(75);
PlaySE(shot3);
loop(4){
CreateShot01(GetX, GetY, 3, GetAngleToPlayer+angle, RED03, 10);
angle+=360/4;
}
ascent(i in 0..30){
loop(4){
CreateShot01(GetX, GetY, 2.9-(i/15)-rand(-0.1, 0.1), GetAngleToPlayer+angle+rand(-i, i), RED01, 10);
angle+=360/4;
}
}
wait(50);
if(GetX>GetCenterX){
SetAngle(180);
}

if(GetX<GetCenterX){
SetAngle(0);
}
loop{
SetSpeed(speed);
speed+=0.02;
wait(1);
}
}





	@MainLoop{
	
	SetCollisionA(GetX, GetY, 14);
	SetCollisionB(GetX, GetY, 2);
	yield;

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


 @DrawLoop {

DrawFairy(fairy);

}





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

}