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

script_enemy_main {
#include_function ".\Sakuyainclude.txt";
let a = 0;
let argument = 0;
let playx = 0;
let angle2 = 0;
let delay = 0;
let angle3 = 0;
let playy = 0;
let color = 0;
	@Initialize{
	InitializeAction;
	LoadMusic(bgm);
	PlayMusic(bgm);
	LoadSE(shot3);
	LoadSE(time1);
	LoadSE(teleport);
	LoadGraphic(imageFile);
	LoadSE(time2);
	LoadSE(wtf);
	shotinit;
	LoadSE(charge);
	SetAction(ACT_MOVE, 55);
	LoadSE(shot);
	LoadSE(charge2);
	LoadSE(laser);
	LoadSE(familiarspawn);
	LoadGraphic(imglifebar); 
	SetLife(6000);
	LoadSE(shot2);
	SetTimer(45);
	SetInvincibility(180);
	SetDamageRate(212.5, 55);
	SetMovePosition02(GetCenterX, GetClipMinY + 100, 75);
	LoadGraphic(SP);
	LoadGraphic(MC);
	attack1;
	CreateItem(ITEM_1UP, GetX, GetY);
	MagicCircle(false);
	SetShotAutoDeleteClip(10, 20, 10, 10);
	SetEnemyMarker(true);
	SetCommonData("lastattack", false);
	}

task attack1 {
	wait(90);
	Concentration01(55);
	PlaySE(charge2);
	wait(55);
	SetAction(ACT_SHOT_A, 60);
	wait(5);
	loop(6){
	CreateEnemyFromScript("familiar", GetX, GetY, 0, 0, angle);
	angle+=360/6;
	}
	wait(180);
	Concentration01(60);
	PlaySE(charge2);
	wait(60);
	
	SetAction(ACT_SHOT_B, 1200000);
	loop{
	wait(15);

	playx = GetPlayerX;
	playy = GetPlayerY;
	angle = atan2(playy-GetY, playx-GetX);
		ascent(p in 0..12){
			ascent(i in -1-p..p+2){
					loop(5){
				CreateShot01(GetX, GetY, 2.5+(p/3.25), angle+(i*1.25), RED31, 10);
					angle+=360/5;
					}
				}
			wait(8);
		}
wait(45);

}
}



}

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{
	
	LoadGraphic(img);
	
	Attack;
	Attack2;
	SetDamageRate(100, 100);
	SetLife(250);
	LoadSE(shot2);
	LoadSE(shot);
	
}

task Attack{
angle = GetArgument;
loop{
SetMovePosition02(GetEnemyX+240*cos(angle), GetEnemyY+35*sin(angle)-45, 30);
angle+=1;
wait(1);
}
}

task Attack2{
wait(90);
loop{
	CreateShot01(GetX+rand(-3, 3), GetY+rand(-1, 1), rand(3.75, 4.35), rand(84, 96), PURPLE32, 10);
	wait(8);
	}
}
	@MainLoop{
	

	yield;
	
	
	 
}
	@DrawLoop
	{
	anim+=7;
	SetRenderState(ALPHA);
	SetTexture(img);
	SetGraphicScale(0.6, 0.6);
	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");
	}

}



