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

script_enemy_main {
#include_function ".\Sakuyainclude.txt";
let a = 0;
let argument = 0;
let color = 0;
	@Initialize{
	InitializeAction;
	LoadMusic(bgm);
	PlayMusic(bgm);
	DeleteSE("se\seEnemyExplode01.wav");
	LoadSE(shot3);
	LoadSE(time1);
	LoadSE(teleport);
	LoadGraphic(imageFile);
	LoadSE(time2);
	LoadSE(wtf);
	shotinit;
	LoadSE(charge);
	SetAction(ACT_MOVE, 180);
	LoadSE(shot);
	LoadSE(charge2);
	LoadSE(laser);
	LoadSE(familiarspawn);
	LoadGraphic(imglifebar); 
	SetLife(6000);
	SetX(GetCenterX+rand(-40, 40));
	SetY(GetClipMinY-40);
	LoadSE(shot2);
	SetTimer(40);
	SetInvincibility(270);
	SetDamageRate(210, 55);
	SetMovePosition02(GetCenterX, GetClipMinY + 120, 180);
	LoadGraphic(SP);
	LoadGraphic(MC);
	attack1;
	MagicCircle(false);
	SetShotAutoDeleteClip(30, 50, 30, 10);
	SetEnemyMarker(true);
	SetCommonData("lastattack", false);
	}

task attack1 {
	wait(210);
	loop{
	Concentration01(60);
	SetAction(ACT_SHOT_A, 90);
	PlaySE(charge2);
	wait(60);
	loop(4){
	CreateEnemyFromScript("familiar", GetX, GetY, 0, 0, argument);
	argument++;
	}
	argument = 0;
	wait(60);
	PlaySE(charge2);
	Concentration01(30);
	wait(60);
	color = rand_int(0, 10);
	loop(3){
	
	SetAction(ACT_MOVE, 180);
	SetMovePositionRandom01(rand(75, 95), rand(12, 15), rand(0.5, 0.6), GetClipMinX+65, GetClipMinY+70, GetClipMaxX-65, GetClipMinY+150);
	loop(18){
		loop(18){
		CreateShotA(1, GetX+30*cos(angle), GetY+30*sin(angle), 10);
		SetShotDataA(1, 0, 0.1, angle, 0, 0, 0, [GREEN32, PURPLE32, WHITE32][color%3]);
		SetShotDataA(1, 60, NULL, NULL, 0, 0.03, 3.5, NULL);
		if(a%6!=0){
		FireShot(1);
		}
		angle+=360/18;
		}
		a++;
		if(a%6==0){
		angle+=360/18/2;
		color++;
		}
		wait(10);
		
	}
	wait(10);
	}
wait(120);
}
}



}

script_enemy familiar {
	let anim = 0;
	let one = 1;
	let vanished = false;
	let graphic = 0;
	let img = GetCurrentScriptDirectory~"sprites\familiar.png";
	let ang = 0;
	let www = 0;
	let a = 0;
	let shot2 = GetCurrentScriptDirectory~"sfx\shot2.wav";
	let shot = GetCurrentScriptDirectory~"sfx\shot.wav";
	#include_function ".\lib\SHOT_REPLACE\shot_replace.dnh"
	let frame=0;
	let angle=0;
	let frame2 = 0;
	@Initialize{
	
	SetSpeed(0.2);
	if(GetArgument==0){
	SetAngle(-35);
	}
	if(GetArgument==1){
	SetAngle(35);
	}
	if(GetArgument==2){
	SetAngle(180-35);
	}
	if(GetArgument==3){
	SetAngle(180+35);
	}
	LoadGraphic(img);
	
	if(GetArgument==0){
	graphic = BLUE31;
	}
	if(GetArgument==1){
	graphic = GREEN31;
	}
	if(GetArgument==2){
	graphic = YELLOW31;
	}
	if(GetArgument==3){
	graphic = RED31;
	}
	Attack;
	SetDamageRate(100, 100);
	SetLife(250);
	LoadSE(shot2);
	LoadSE(shot);
	
}

task Attack{
if(GetArgument==3){
		wait(10);
		}
if(GetArgument==1){
one = 1;
angle = 0;
}
if(GetArgument==1){
wait(60);
}
if(GetArgument==2){
one = -1;
angle = 45;
wait(90);
}
	loop{
		
		if(GetArgument==0||GetArgument==3){
		loop(4){
		ascent(i in -2..1){
			CreateShot01(GetX, GetY, 3.25+(a/1250), angle+(i*0.9), graphic, 10);
			}
			angle+=360/4;
			}
		if(GetArgument==0){
		angle+=16.45967382;
		}
		if(GetArgument==3){
		angle-=16.45967382;
		}
			wait(15);
		}
		if(GetArgument==1||GetArgument==2){
		
			loop(16){
				ascent(i in 0..3){
				CreateShot01(GetX, GetY, 2.0+(i*0.075), angle, graphic, 10);
				}
				angle+=360/16;
				}
				
		angle+=15*one+rand(-2, 2);
		wait(60);
		}


}
}
	@MainLoop{
	
a++;
if(a>=780){
VanishEnemy;
}
	
	yield;
	
	
	 
}
	@DrawLoop
	{
	anim+=7;
	SetRenderState(ALPHA);
	SetTexture(img);
	SetGraphicScale(1, 1);
	SetAlpha(255);
	SetGraphicRect(0, 0, 64, 64);
	SetGraphicAngle(0, 0, anim);
	DrawGraphic(GetX, GetY);
}

	
	function wait(w){ loop(w){ yield;}}
	@Finalize{
	PlaySE(GetCurrentScriptDirectory~"sfx\explode.wav");
	}

}



